Deploying to gh-pages from @ harttle/liquidjs@70fdb7af48 🚀

This commit is contained in:
harttle
2021-09-30 16:55:43 +00:00
parent cec0814a9b
commit 9a2a2bfd55
515 changed files with 11719 additions and 9833 deletions
+8 -8
View File
@@ -36,8 +36,8 @@
<link rel="stylesheet" href="../css/navy.css">
<link rel="alternate" href="../atom.xml" title="LiquidJS">
</head>
<link rel="alternate" href="../atom.xml" title="LiquidJS" type="application/atom+xml">
<meta name="generator" content="Hexo 5.4.0"></head>
<body>
<div id="container">
@@ -63,7 +63,7 @@
</select>
</div>
<a href="https://github.com/harttle/liquidjs" target="_blank" rel="noopener external nofollow noreferrer" id="github-link-wrap" class="main-nav-link"><i class="icon-github"></i>Github</a>
<a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/harttle/liquidjs" id="github-link-wrap" class="main-nav-link"><i class="icon-github"></i>Github</a>
<a id="mobile-nav-toggle">
<span class="mobile-nav-toggle-bar"></span>
<span class="mobile-nav-toggle-bar"></span>
@@ -87,7 +87,7 @@
<header class="article-header">
<h1 class="article-title" itemprop="name">Caching</h1>
<a href="https://github.com/harttle/liquidjs/edit/master/docs/source/tutorials/caching.md" target="_blank" rel="noopener external nofollow noreferrer" class="article-edit-link" title="Improve this doc"><i class="icon-pencil"></i></a>
<a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/harttle/liquidjs/edit/master/docs/source/tutorials/caching.md" class="article-edit-link" title="Improve this doc"><i class="icon-pencil"></i></a>
</header>
<div class="article-content" itemprop="articleBody">
@@ -95,19 +95,19 @@
<p>LiquidJS provides multiple ways to cache the parsed templates to improve performance.</p>
<h2 id="Programmaticly" class="article-heading"><a href="#Programmaticly" class="headerlink" title="Programmaticly"></a>Programmaticly<a class="article-anchor" href="#Programmaticly" aria-hidden="true"></a></h2><p>The <a href="../api/classes/liquid_.liquid.html#parse">.parse()</a>, <a href="../api/classes/liquid_.liquid.html#parseFile">.parseFile()</a>, <a href="../api/classes/liquid_.liquid.html#parseFileSync">.parseFileSync()</a> APIs are used to parse templates from string or files. The result template can be then rendered multiple times with different context.</p>
<p>Parse from string:</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> tpl = engine.parse(<span class="string">'&#123;&#123;name | capitalize&#125;&#125;'</span>);</span><br><span class="line"></span><br><span class="line">engine.renderSync(tpl, &#123;<span class="attr">name</span>: <span class="string">'alice'</span>&#125;) <span class="comment">// 'Alice'</span></span><br><span class="line">engine.renderSync(tpl, &#123;<span class="attr">name</span>: <span class="string">'bob'</span>&#125;) <span class="comment">// 'Bob'</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> tpl = engine.parse(<span class="string">&#x27;&#123;&#123;name | capitalize&#125;&#125;&#x27;</span>);</span><br><span class="line"></span><br><span class="line">engine.renderSync(tpl, &#123;<span class="attr">name</span>: <span class="string">&#x27;alice&#x27;</span>&#125;) <span class="comment">// &#x27;Alice&#x27;</span></span><br><span class="line">engine.renderSync(tpl, &#123;<span class="attr">name</span>: <span class="string">&#x27;bob&#x27;</span>&#125;) <span class="comment">// &#x27;Bob&#x27;</span></span><br></pre></td></tr></table></figure>
<p>Parse from file:</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> tpl = engine.parseFileSync(<span class="string">'hello'</span>); <span class="comment">// contents of `hello.liquid`: &#123;&#123;name&#125;&#125;</span></span><br><span class="line"></span><br><span class="line">engine.renderSync(tpl, &#123;<span class="attr">name</span>: <span class="string">'alice'</span>&#125;) <span class="comment">// 'Alice'</span></span><br><span class="line">engine.renderSync(tpl, &#123;<span class="attr">name</span>: <span class="string">'bob'</span>&#125;) <span class="comment">// 'Bob'</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> tpl = engine.parseFileSync(<span class="string">&#x27;hello&#x27;</span>); <span class="comment">// contents of `hello.liquid`: &#123;&#123;name&#125;&#125;</span></span><br><span class="line"></span><br><span class="line">engine.renderSync(tpl, &#123;<span class="attr">name</span>: <span class="string">&#x27;alice&#x27;</span>&#125;) <span class="comment">// &#x27;Alice&#x27;</span></span><br><span class="line">engine.renderSync(tpl, &#123;<span class="attr">name</span>: <span class="string">&#x27;bob&#x27;</span>&#125;) <span class="comment">// &#x27;Bob&#x27;</span></span><br></pre></td></tr></table></figure>
<p>The template string/file is parsed only once and renderd multiple times using different context. Templates for different files can be stored into a <code>Map</code> and can be retrieved directly for subsequent renders.</p>
<h2 id="The-cache-Option" class="article-heading"><a href="#The-cache-Option" class="headerlink" title="The cache Option"></a>The <code>cache</code> Option<a class="article-anchor" href="#The-cache-Option" aria-hidden="true"></a></h2><p>The <a href="../api/interfaces/liquid_options_.liquidoptions.html#Optional-cache">cache option</a> can be set to instruct liquidjs to use cached parsed templates each time you call <a href="../api/classes/liquid_.liquid.html#renderFile">renderFile</a> or <a href="../api/classes/liquid_.liquid.html#renderFilesync">renderFileSync</a>.</p>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> &#123; Liquid &#125; = <span class="built_in">require</span>(<span class="string">'liquidjs'</span>);</span><br><span class="line"><span class="keyword">var</span> engine = <span class="keyword">new</span> Liquid(&#123;</span><br><span class="line"> cache: <span class="literal">true</span></span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// liquidjs parses the hello.liquid, then renders it with &#123;name: 'alice'&#125;</span></span><br><span class="line">engine.renderFileSync(<span class="string">'hello'</span>, &#123;<span class="attr">name</span>: <span class="string">'alice'</span>&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">// liquidjs finds the cached template, then renders it with &#123;name: 'bob'&#125;</span></span><br><span class="line">engine.renderFileSync(<span class="string">'hello'</span>, &#123;<span class="attr">name</span>: <span class="string">'bob'</span>&#125;)</span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> &#123; Liquid &#125; = <span class="built_in">require</span>(<span class="string">&#x27;liquidjs&#x27;</span>);</span><br><span class="line"><span class="keyword">var</span> engine = <span class="keyword">new</span> Liquid(&#123;</span><br><span class="line"> <span class="attr">cache</span>: <span class="literal">true</span></span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// liquidjs parses the hello.liquid, then renders it with &#123;name: &#x27;alice&#x27;&#125;</span></span><br><span class="line">engine.renderFileSync(<span class="string">&#x27;hello&#x27;</span>, &#123;<span class="attr">name</span>: <span class="string">&#x27;alice&#x27;</span>&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">// liquidjs finds the cached template, then renders it with &#123;name: &#x27;bob&#x27;&#125;</span></span><br><span class="line">engine.renderFileSync(<span class="string">&#x27;hello&#x27;</span>, &#123;<span class="attr">name</span>: <span class="string">&#x27;bob&#x27;</span>&#125;)</span><br></pre></td></tr></table></figure>
</div>
<footer class="article-footer">
<time class="article-footer-updated" datetime="2021-09-26T12:45:03.359Z" itemprop="dateModified">Last updated: 2021-09-26</time>
<time class="article-footer-updated" datetime="2021-09-30T16:54:19.718Z" itemprop="dateModified">Last updated: 2021-09-30</time>
<a href="use-in-expressjs.html" class="article-footer-prev" title="Use in Express.js"><i class="icon-chevron-left"></i><span>Prev</span></a><a href="register-filters-tags.html" class="article-footer-next" title="Register Filters/Tags"><span>Next</span><i class="icon-chevron-right"></i></a>
</footer>
</div>