Synchronized build

This commit is contained in:
Lektor Bot 2025-01-06 02:46:14 +00:00
parent 2cd38ca510
commit 251c54ba15
65 changed files with 270 additions and 270 deletions

View File

@ -198,7 +198,7 @@ open the artifact for reading or writing. If the build goes well, Lektor
will commit those changes and persist them.</p> will commit those changes and persist them.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span>
<span class="nd">@ctx</span><span class="o">.</span><span class="n">sub_artifact</span><span class="p">(</span><span class="s1">&#39;artifact.txt&#39;</span><span class="p">)</span> <span class="nd">@ctx</span><span class="o">.</span><span class="n">sub_artifact</span><span class="p">(</span><span class="s1">&#39;artifact.txt&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">build_stylesheet</span><span class="p">(</span><span class="n">artifact</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">build_stylesheet</span><span class="p">(</span><span class="n">artifact</span><span class="p">):</span>
<span class="k">with</span> <span class="n">artifact</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="k">with</span> <span class="n">artifact</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Hello World!</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span> <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Hello World!</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
</pre></div> </pre></div>

View File

@ -199,7 +199,7 @@ committed when the entire build process goes through smoothly and the
changes are committed by the builder.</p> changes are committed by the builder.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span>
<span class="nd">@ctx</span><span class="o">.</span><span class="n">sub_artifact</span><span class="p">(</span><span class="s1">&#39;artifact.txt&#39;</span><span class="p">)</span> <span class="nd">@ctx</span><span class="o">.</span><span class="n">sub_artifact</span><span class="p">(</span><span class="s1">&#39;artifact.txt&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">build_stylesheet</span><span class="p">(</span><span class="n">artifact</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">build_stylesheet</span><span class="p">(</span><span class="n">artifact</span><span class="p">):</span>
<span class="k">with</span> <span class="n">artifact</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="k">with</span> <span class="n">artifact</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Hello World!</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span> <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;Hello World!</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
</pre></div> </pre></div>

View File

@ -195,10 +195,10 @@ catch the error and render it into the template with a failure marker. This
can be changed with the <code>fail</code> parameter. This is similar to the behavior of can be changed with the <code>fail</code> parameter. This is similar to the behavior of
the <a href="../../../environment/render-template/" class="ref">render_template</a> method of the the <a href="../../../environment/render-template/" class="ref">render_template</a> method of the
environment.</p> environment.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="k">class</span> <span class="nc">MyBuildProgram</span><span class="p">(</span><span class="n">BuildProgram</span><span class="p">):</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="k">class</span><span class="w"> </span><span class="nc">MyBuildProgram</span><span class="p">(</span><span class="n">BuildProgram</span><span class="p">):</span>
<span class="o">...</span> <span class="o">...</span>
<span class="k">def</span> <span class="nf">build_artifact</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">artifact</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">build_artifact</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">artifact</span><span class="p">):</span>
<span class="n">artifact</span><span class="o">.</span><span class="n">render_template_into</span><span class="p">(</span> <span class="n">artifact</span><span class="o">.</span><span class="n">render_template_into</span><span class="p">(</span>
<span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="p">[</span><span class="s1">&#39;_template&#39;</span><span class="p">],</span> <span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="p">[</span><span class="s1">&#39;_template&#39;</span><span class="p">],</span> <span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="p">)</span>
</pre></div> </pre></div>

View File

@ -196,7 +196,7 @@ that create temporaries. By default the file is moved as this is what's
common with temporaries but this can be changed into a copy with <code>copy=True</code>.</p> common with temporaries but this can be changed into a copy with <code>copy=True</code>.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span>
<span class="nd">@ctx</span><span class="o">.</span><span class="n">sub_artifact</span><span class="p">(</span><span class="s1">&#39;artifact.txt&#39;</span><span class="p">)</span> <span class="nd">@ctx</span><span class="o">.</span><span class="n">sub_artifact</span><span class="p">(</span><span class="s1">&#39;artifact.txt&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">build_stylesheet</span><span class="p">(</span><span class="n">artifact</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">build_stylesheet</span><span class="p">(</span><span class="n">artifact</span><span class="p">):</span>
<span class="n">temporary_file</span> <span class="o">=</span> <span class="n">invoke_external_program</span><span class="p">()</span> <span class="n">temporary_file</span> <span class="o">=</span> <span class="n">invoke_external_program</span><span class="p">()</span>
<span class="n">artifact</span><span class="o">.</span><span class="n">replace_with_file</span><span class="p">(</span><span class="n">temporary_file</span><span class="p">)</span> <span class="n">artifact</span><span class="o">.</span><span class="n">replace_with_file</span><span class="p">(</span><span class="n">temporary_file</span><span class="p">)</span>
</pre></div> </pre></div>

View File

@ -200,7 +200,7 @@ will look at the context to decide on further operations to perform.</p>
<p>The current context can be discovered by calling the <a href="../get-ctx/" class="ref">get_ctx</a> <p>The current context can be discovered by calling the <a href="../get-ctx/" class="ref">get_ctx</a>
function which will return it. If there is no artifact build ongoing then function which will return it. If there is no artifact build ongoing then
the return value will be <code>None</code>.</p> the return value will be <code>None</code>.</p>
<h2 id="basic-example">Basic Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.context</span> <span class="kn">import</span> <span class="n">get_ctx</span> <h2 id="basic-example">Basic Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.context</span><span class="w"> </span><span class="kn">import</span> <span class="n">get_ctx</span>
<span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;The current source is </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">ctx</span><span class="o">.</span><span class="n">source</span><span class="p">)</span> <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;The current source is </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">ctx</span><span class="o">.</span><span class="n">source</span><span class="p">)</span>

View File

@ -197,7 +197,7 @@
<p>To access the current pad from the context, this attribute can be used. It <p>To access the current pad from the context, this attribute can be used. It
refers to the active <a href="../../../db/pad/" class="ref">Pad</a>.</p> refers to the active <a href="../../../db/pad/" class="ref">Pad</a>.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.context</span> <span class="kn">import</span> <span class="n">get_ctx</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.context</span><span class="w"> </span><span class="kn">import</span> <span class="n">get_ctx</span>
<span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span>
<span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="n">ctx</span><span class="o">.</span><span class="n">pad</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">children</span><span class="p">:</span> <span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="n">ctx</span><span class="o">.</span><span class="n">pad</span><span class="o">.</span><span class="n">root</span><span class="o">.</span><span class="n">children</span><span class="p">:</span>

View File

@ -209,13 +209,13 @@ to record this as a dependency.</p>
is possible to depend on things outside of it, but the automatic watch is possible to depend on things outside of it, but the automatic watch
system of the builder will not track files there so they will not show up system of the builder will not track files there so they will not show up
unless a manual build is instructed.</p> unless a manual build is instructed.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">import</span> <span class="nn">os</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">os</span>
<span class="kn">from</span> <span class="nn">lektor.pluginsystem</span> <span class="kn">import</span> <span class="n">Plugin</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">Plugin</span>
<span class="k">class</span> <span class="nc">IncludeFilePlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">IncludeFilePlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">include_file</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">include_file</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
<span class="n">fn</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">root_path</span><span class="p">,</span> <span class="s1">&#39;inc&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span> <span class="n">fn</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">root_path</span><span class="p">,</span> <span class="s1">&#39;inc&#39;</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span>
<span class="n">get_ctx</span><span class="p">()</span><span class="o">.</span><span class="n">record_dependency</span><span class="p">(</span><span class="n">fn</span><span class="p">)</span> <span class="n">get_ctx</span><span class="p">()</span><span class="o">.</span><span class="n">record_dependency</span><span class="p">(</span><span class="n">fn</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">fn</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">fn</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>

View File

@ -198,7 +198,7 @@
<p>This works almost exactly like the <a href="../source/" class="ref">source</a> property but the <p>This works almost exactly like the <a href="../source/" class="ref">source</a> property but the
difference is that it is <code>None</code> if the source object is not a difference is that it is <code>None</code> if the source object is not a
<a href="../../../db/record/" class="ref">Record</a>.</p> <a href="../../../db/record/" class="ref">Record</a>.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.context</span> <span class="kn">import</span> <span class="n">get_ctx</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.context</span><span class="w"> </span><span class="kn">import</span> <span class="n">get_ctx</span>
<span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span>
<span class="nb">print</span> <span class="n">ctx</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">record_label</span> <span class="nb">print</span> <span class="n">ctx</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">record_label</span>

View File

@ -199,7 +199,7 @@
created from <a href="../../../db/obj/" class="ref">Source Objects</a>, it's typically possible created from <a href="../../../db/obj/" class="ref">Source Objects</a>, it's typically possible
to refer back to it. Note that there are situations in which artifacts are to refer back to it. Note that there are situations in which artifacts are
created but no source is available. In this case the value will be <code>None</code>.</p> created but no source is available. In this case the value will be <code>None</code>.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.context</span> <span class="kn">import</span> <span class="n">get_ctx</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.context</span><span class="w"> </span><span class="kn">import</span> <span class="n">get_ctx</span>
<span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span>
<span class="nb">print</span> <span class="n">ctx</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">source_filename</span> <span class="nb">print</span> <span class="n">ctx</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">source_filename</span>

View File

@ -214,16 +214,16 @@ artifact is already considered up to date.</p>
provided it can identify the configuration that the artifact was created provided it can identify the configuration that the artifact was created
from. If the hash changes the artifact will be rebuilt. Such a hash from. If the hash changes the artifact will be rebuilt. Such a hash
can for instance be generated with <a href="../../../utils/get-structure-hash/" class="ref">get_structure_hash</a>.</p> can for instance be generated with <a href="../../../utils/get-structure-hash/" class="ref">get_structure_hash</a>.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">import</span> <span class="nn">os</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">os</span>
<span class="kn">from</span> <span class="nn">lektor.pluginsystem</span> <span class="kn">import</span> <span class="n">Plugin</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">Plugin</span>
<span class="k">class</span> <span class="nc">IncludeFilePlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">IncludeFilePlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">get_css</span><span class="p">(</span><span class="n">artifact_name</span><span class="o">=</span><span class="s1">&#39;/demo.css&#39;</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">get_css</span><span class="p">(</span><span class="n">artifact_name</span><span class="o">=</span><span class="s1">&#39;/demo.css&#39;</span><span class="p">):</span>
<span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span>
<span class="nd">@ctx</span><span class="o">.</span><span class="n">sub_artifact</span><span class="p">(</span><span class="n">artifact_name</span><span class="p">)</span> <span class="nd">@ctx</span><span class="o">.</span><span class="n">sub_artifact</span><span class="p">(</span><span class="n">artifact_name</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">build_stylesheet</span><span class="p">(</span><span class="n">artifact</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">build_stylesheet</span><span class="p">(</span><span class="n">artifact</span><span class="p">):</span>
<span class="k">with</span> <span class="n">artifact</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="k">with</span> <span class="n">artifact</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;body { background: red; }</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span> <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;body { background: red; }</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">artifact_name</span> <span class="k">return</span> <span class="n">artifact_name</span>

View File

@ -175,7 +175,7 @@ if not. This means that if plugins only call that method in places where
they know a build is access it's not necessary to check if the context is they know a build is access it's not necessary to check if the context is
available.</p> available.</p>
<p>For more information: <a href="../context/" class="ref">Context</a>.</p> <p>For more information: <a href="../context/" class="ref">Context</a>.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.context</span> <span class="kn">import</span> <span class="n">get_ctx</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.context</span><span class="w"> </span><span class="kn">import</span> <span class="n">get_ctx</span>
<span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span>
</pre></div> </pre></div>

View File

@ -190,7 +190,7 @@
<p>Optionally a builder can yield further sources that are then picked up by the <p>Optionally a builder can yield further sources that are then picked up by the
builder and processed normally. This is how the recursive build process in builder and processed normally. This is how the recursive build process in
Lektor is implemented for normal records.</p> Lektor is implemented for normal records.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="k">def</span> <span class="nf">iter_child_sources</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">iter_child_sources</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sources</span><span class="o">.</span><span class="n">children</span><span class="p">:</span> <span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sources</span><span class="o">.</span><span class="n">children</span><span class="p">:</span>
<span class="k">yield</span> <span class="n">child</span> <span class="k">yield</span> <span class="n">child</span>
</pre></div> </pre></div>

View File

@ -168,7 +168,7 @@
Python code. Within templates you can also use the <a href="../../templates/globals/bag/" class="ref">bag</a> function which is easier to call.</p> Python code. Within templates you can also use the <a href="../../templates/globals/bag/" class="ref">bag</a> function which is easier to call.</p>
<p>The key is in dotted notation. For more information about this refer <p>The key is in dotted notation. For more information about this refer
to the main <a href="../" class="ref">databags</a> documentation.</p> to the main <a href="../" class="ref">databags</a> documentation.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="k">def</span> <span class="nf">translate</span><span class="p">(</span><span class="n">pad</span><span class="p">,</span> <span class="n">alt</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">translate</span><span class="p">(</span><span class="n">pad</span><span class="p">,</span> <span class="n">alt</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
<span class="k">return</span> <span class="n">pad</span><span class="o">.</span><span class="n">databags</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s1">&#39;i18n.</span><span class="si">%s</span><span class="s1">.</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">alt</span><span class="p">,</span> <span class="n">key</span><span class="p">),</span> <span class="n">key</span><span class="p">)</span> <span class="k">return</span> <span class="n">pad</span><span class="o">.</span><span class="n">databags</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s1">&#39;i18n.</span><span class="si">%s</span><span class="s1">.</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">alt</span><span class="p">,</span> <span class="n">key</span><span class="p">),</span> <span class="n">key</span><span class="p">)</span>
</pre></div> </pre></div>

View File

@ -246,7 +246,7 @@ differs between Python and templates. In templates you have to use the
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span> <span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
<span class="p">&lt;/</span><span class="nt">ul</span><span class="p">&gt;</span> <span class="p">&lt;/</span><span class="nt">ul</span><span class="p">&gt;</span>
</pre></div> </pre></div>
<h2 id="python-example">Python Example</h2><div class="hll"><pre><span></span><span class="k">def</span> <span class="nf">get_hotels</span><span class="p">(</span><span class="n">page</span><span class="p">):</span> <h2 id="python-example">Python Example</h2><div class="hll"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">get_hotels</span><span class="p">(</span><span class="n">page</span><span class="p">):</span>
<span class="k">return</span> <span class="n">page</span><span class="o">.</span><span class="n">children</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span> <span class="k">return</span> <span class="n">page</span><span class="o">.</span><span class="n">children</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span>
<span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s1">&#39;hotel&#39;</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">stars</span> <span class="o">&gt;=</span> <span class="mi">3</span><span class="p">))</span> <span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s1">&#39;hotel&#39;</span><span class="p">)</span> <span class="o">&amp;</span> <span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">stars</span> <span class="o">&gt;=</span> <span class="mi">3</span><span class="p">))</span>
</pre></div> </pre></div>

View File

@ -246,7 +246,7 @@ differs between Python and templates. In templates you have to use the
<span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span> <span class="cp">{%</span> <span class="k">endfor</span> <span class="cp">%}</span>
<span class="p">&lt;/</span><span class="nt">ul</span><span class="p">&gt;</span> <span class="p">&lt;/</span><span class="nt">ul</span><span class="p">&gt;</span>
</pre></div> </pre></div>
<h2 id="python-example">Python Example</h2><div class="hll"><pre><span></span><span class="k">def</span> <span class="nf">get_hotels_or_apartments</span><span class="p">(</span><span class="n">page</span><span class="p">):</span> <h2 id="python-example">Python Example</h2><div class="hll"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">get_hotels_or_apartments</span><span class="p">(</span><span class="n">page</span><span class="p">):</span>
<span class="k">return</span> <span class="n">page</span><span class="o">.</span><span class="n">children</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span> <span class="k">return</span> <span class="n">page</span><span class="o">.</span><span class="n">children</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span>
<span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s1">&#39;hotel&#39;</span><span class="p">)</span> <span class="o">|</span> <span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s1">&#39;apartment&#39;</span><span class="p">))</span> <span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s1">&#39;hotel&#39;</span><span class="p">)</span> <span class="o">|</span> <span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s1">&#39;apartment&#39;</span><span class="p">))</span>
</pre></div> </pre></div>

View File

@ -248,22 +248,22 @@ in the path. The part after the at sign is called the “virtual path”.</p>
the record's path + <code>@source</code>. So if the record was <code>/hello</code> then the the record's path + <code>@source</code>. So if the record was <code>/hello</code> then the
path would be <code>/hello@source</code>. The true base record it belongs to can be path would be <code>/hello@source</code>. The true base record it belongs to can be
referenced from the <a href="record/" class="ref">record</a> property.</p> referenced from the <a href="record/" class="ref">record</a> property.</p>
<div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.sourceobj</span> <span class="kn">import</span> <span class="n">VirtualSourceObject</span> <div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.sourceobj</span><span class="w"> </span><span class="kn">import</span> <span class="n">VirtualSourceObject</span>
<span class="kn">from</span> <span class="nn">lektor.utils</span> <span class="kn">import</span> <span class="n">build_url</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.utils</span><span class="w"> </span><span class="kn">import</span> <span class="n">build_url</span>
<span class="k">class</span> <span class="nc">Source</span><span class="p">(</span><span class="n">VirtualSourceObject</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">Source</span><span class="p">(</span><span class="n">VirtualSourceObject</span><span class="p">):</span>
<span class="nd">@property</span> <span class="nd">@property</span>
<span class="k">def</span> <span class="nf">path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">path</span> <span class="o">+</span> <span class="s1">&#39;@source&#39;</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">path</span> <span class="o">+</span> <span class="s1">&#39;@source&#39;</span>
<span class="nd">@property</span> <span class="nd">@property</span>
<span class="k">def</span> <span class="nf">source_content</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">source_content</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">source_filename</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">source_filename</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="k">return</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">)</span> <span class="k">return</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">)</span>
<span class="nd">@property</span> <span class="nd">@property</span>
<span class="k">def</span> <span class="nf">url_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">url_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="n">build_url</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">url_path</span><span class="p">,</span> <span class="s1">&#39;source.txt&#39;</span><span class="p">])</span> <span class="k">return</span> <span class="n">build_url</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">url_path</span><span class="p">,</span> <span class="s1">&#39;source.txt&#39;</span><span class="p">])</span>
</pre></div> </pre></div>
<p>For more information see <a href="../../environment/add-build-program/" class="ref">add-build-program</a> as well as <p>For more information see <a href="../../environment/add-build-program/" class="ref">add-build-program</a> as well as

View File

@ -232,7 +232,7 @@ how to do this through the <a href="get/" class="ref">get</a> method:</p>
</pre></div> </pre></div>
<h2 id="plugin-usage">Plugin Usage</h2><p>Within plugins it's typically not a good idea to construct a new Pad. <h2 id="plugin-usage">Plugin Usage</h2><p>Within plugins it's typically not a good idea to construct a new Pad.
Instead you can get access to the current pad from the active context:</p> Instead you can get access to the current pad from the active context:</p>
<div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.context</span> <span class="kn">import</span> <span class="n">get_ctx</span> <div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.context</span><span class="w"> </span><span class="kn">import</span> <span class="n">get_ctx</span>
<span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span>
<span class="k">if</span> <span class="n">ctx</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> <span class="k">if</span> <span class="n">ctx</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
@ -244,7 +244,7 @@ instance.</p>
<h2 id="manual-pad-creation">Manual Pad Creation</h2><p>If you want to work with the database from a script, you can create a <h2 id="manual-pad-creation">Manual Pad Creation</h2><p>If you want to work with the database from a script, you can create a
pad from the <a href="../../environment/" class="ref">Environment</a> with the help of pad from the <a href="../../environment/" class="ref">Environment</a> with the help of
the <a href="../../environment/new-pad/" class="ref">new_pad</a> method:</p> the <a href="../../environment/new-pad/" class="ref">new_pad</a> method:</p>
<div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.project</span> <span class="kn">import</span> <span class="n">Project</span> <div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.project</span><span class="w"> </span><span class="kn">import</span> <span class="n">Project</span>
<span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span> <span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span>
<span class="n">env</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">make_env</span><span class="p">()</span> <span class="n">env</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">make_env</span><span class="p">()</span>

View File

@ -202,15 +202,15 @@ method and set the <code>widget</code> property as a very basic requirement.</p>
to match the type name. If you want to name your type <code>mything</code> then it to match the type name. If you want to name your type <code>mything</code> then it
needs to be called <code>MyThingType</code>. Afterwards you can register it with the needs to be called <code>MyThingType</code>. Afterwards you can register it with the
environment in <a href="../../plugins/events/setup-env/" class="ref">setup_env</a>:</p> environment in <a href="../../plugins/events/setup-env/" class="ref">setup_env</a>:</p>
<div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.types.primitives</span> <span class="kn">import</span> <span class="n">SingleInputType</span> <div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.types.primitives</span><span class="w"> </span><span class="kn">import</span> <span class="n">SingleInputType</span>
<span class="k">class</span> <span class="nc">MyThingType</span><span class="p">(</span><span class="n">SingleInputType</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">MyThingType</span><span class="p">(</span><span class="n">SingleInputType</span><span class="p">):</span>
<span class="n">widget</span> <span class="o">=</span> <span class="s1">&#39;singleline-text&#39;</span> <span class="n">widget</span> <span class="o">=</span> <span class="s1">&#39;singleline-text&#39;</span>
<span class="k">def</span> <span class="nf">value_from_raw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">raw</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">value_from_raw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">raw</span><span class="p">):</span>
<span class="k">return</span> <span class="n">raw</span><span class="o">.</span><span class="n">value</span> <span class="k">return</span> <span class="n">raw</span><span class="o">.</span><span class="n">value</span>
<span class="k">def</span> <span class="nf">setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">add_type</span><span class="p">(</span><span class="n">MyThingType</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">add_type</span><span class="p">(</span><span class="n">MyThingType</span><span class="p">)</span>
</pre></div> </pre></div>
<div class="admonition admonition-tip"><p>In the above example, the new type declares a base class of <code>SingleInputType</code>. <div class="admonition admonition-tip"><p>In the above example, the new type declares a base class of <code>SingleInputType</code>.

View File

@ -212,12 +212,12 @@ database layer. This can be any Python type for as long as it makes sense.
It must either return a valid value or a special value that indicates a bad It must either return a valid value or a special value that indicates a bad
value. For more information see the raw value information below and the value. For more information see the raw value information below and the
example provided.</p> example provided.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.types</span> <span class="kn">import</span> <span class="n">Type</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.types</span><span class="w"> </span><span class="kn">import</span> <span class="n">Type</span>
<span class="k">class</span> <span class="nc">LocationType</span><span class="p">(</span><span class="n">Type</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">LocationType</span><span class="p">(</span><span class="n">Type</span><span class="p">):</span>
<span class="n">widget</span> <span class="o">=</span> <span class="s1">&#39;singleline-text&#39;</span> <span class="n">widget</span> <span class="o">=</span> <span class="s1">&#39;singleline-text&#39;</span>
<span class="k">def</span> <span class="nf">value_from_raw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">raw</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">value_from_raw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">raw</span><span class="p">):</span>
<span class="k">if</span> <span class="n">raw</span><span class="o">.</span><span class="n">value</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> <span class="k">if</span> <span class="n">raw</span><span class="o">.</span><span class="n">value</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">return</span> <span class="n">raw</span><span class="o">.</span><span class="n">missing_value</span><span class="p">(</span><span class="s1">&#39;Location was not supplied&#39;</span><span class="p">)</span> <span class="k">return</span> <span class="n">raw</span><span class="o">.</span><span class="n">missing_value</span><span class="p">(</span><span class="s1">&#39;Location was not supplied&#39;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span> <span class="k">try</span><span class="p">:</span>
@ -227,7 +227,7 @@ example provided.</p>
<span class="k">return</span> <span class="n">raw</span><span class="o">.</span><span class="n">bad_value</span><span class="p">(</span><span class="s1">&#39;Location was malformed&#39;</span><span class="p">)</span> <span class="k">return</span> <span class="n">raw</span><span class="o">.</span><span class="n">bad_value</span><span class="p">(</span><span class="s1">&#39;Location was malformed&#39;</span><span class="p">)</span>
<span class="k">return</span> <span class="p">(</span><span class="n">lng</span><span class="p">,</span> <span class="n">lat</span><span class="p">)</span> <span class="k">return</span> <span class="p">(</span><span class="n">lng</span><span class="p">,</span> <span class="n">lat</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">add_type</span><span class="p">(</span><span class="n">LocationType</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">add_type</span><span class="p">(</span><span class="n">LocationType</span><span class="p">)</span>
</pre></div> </pre></div>
<h2 id="raw-value">Raw Value</h2><p>The value passed is a <code>raw</code> value type. It has a few properties and methods:</p> <h2 id="raw-value">Raw Value</h2><p>The value passed is a <code>raw</code> value type. It has a few properties and methods:</p>

View File

@ -210,12 +210,12 @@ but you can select one of the built-in widgets for your own type. Note that
not all widgets will necessarily will work directly with your type as such. not all widgets will necessarily will work directly with your type as such.
For instance the <code>select</code> widget and some others will currently require some For instance the <code>select</code> widget and some others will currently require some
extra values be supplied in the <a href="../to-json/" class="ref">to_json</a> method.</p> extra values be supplied in the <a href="../to-json/" class="ref">to_json</a> method.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.types</span> <span class="kn">import</span> <span class="n">Type</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.types</span><span class="w"> </span><span class="kn">import</span> <span class="n">Type</span>
<span class="k">class</span> <span class="nc">MyThingType</span><span class="p">(</span><span class="n">Type</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">MyThingType</span><span class="p">(</span><span class="n">Type</span><span class="p">):</span>
<span class="n">widget</span> <span class="o">=</span> <span class="s1">&#39;singleline-text&#39;</span> <span class="n">widget</span> <span class="o">=</span> <span class="s1">&#39;singleline-text&#39;</span>
<span class="k">def</span> <span class="nf">value_from_raw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">raw</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">value_from_raw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">raw</span><span class="p">):</span>
<span class="k">return</span> <span class="n">raw</span><span class="o">.</span><span class="n">value</span> <span class="k">return</span> <span class="n">raw</span><span class="o">.</span><span class="n">value</span>
</pre></div> </pre></div>
<h2 id="available-widgets">Available Widgets</h2><p>These widgets are currently available:</p> <h2 id="available-widgets">Available Widgets</h2><p>These widgets are currently available:</p>

View File

@ -196,40 +196,40 @@ custom source objects. This can be used to implement virtual items. This
works in combination with <a href="../generator/" class="ref">generator</a> and works in combination with <a href="../generator/" class="ref">generator</a> and
<a href="../urlresolver/" class="ref">urlresolver</a> and is responsible for generating <a href="../urlresolver/" class="ref">urlresolver</a> and is responsible for generating
artifacts out of source objects.</p> artifacts out of source objects.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.sourceobj</span> <span class="kn">import</span> <span class="n">VirtualSourceObject</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.sourceobj</span><span class="w"> </span><span class="kn">import</span> <span class="n">VirtualSourceObject</span>
<span class="kn">from</span> <span class="nn">lektor.build_programs</span> <span class="kn">import</span> <span class="n">BuildProgram</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.build_programs</span><span class="w"> </span><span class="kn">import</span> <span class="n">BuildProgram</span>
<span class="kn">from</span> <span class="nn">lektor.utils</span> <span class="kn">import</span> <span class="n">build_url</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.utils</span><span class="w"> </span><span class="kn">import</span> <span class="n">build_url</span>
<span class="k">class</span> <span class="nc">Source</span><span class="p">(</span><span class="n">VirtualSourceObject</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">Source</span><span class="p">(</span><span class="n">VirtualSourceObject</span><span class="p">):</span>
<span class="nd">@property</span> <span class="nd">@property</span>
<span class="k">def</span> <span class="nf">path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">path</span> <span class="o">+</span> <span class="s1">&#39;@source&#39;</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">path</span> <span class="o">+</span> <span class="s1">&#39;@source&#39;</span>
<span class="nd">@property</span> <span class="nd">@property</span>
<span class="k">def</span> <span class="nf">source_content</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">source_content</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">source_filename</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">source_filename</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="k">return</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">)</span> <span class="k">return</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">)</span>
<span class="nd">@property</span> <span class="nd">@property</span>
<span class="k">def</span> <span class="nf">url_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">url_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="n">build_url</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">url_path</span><span class="p">,</span> <span class="s1">&#39;source.txt&#39;</span><span class="p">])</span> <span class="k">return</span> <span class="n">build_url</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">url_path</span><span class="p">,</span> <span class="s1">&#39;source.txt&#39;</span><span class="p">])</span>
<span class="k">class</span> <span class="nc">SourceBuildProgram</span><span class="p">(</span><span class="n">BuildProgram</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">SourceBuildProgram</span><span class="p">(</span><span class="n">BuildProgram</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">produce_artifacts</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">produce_artifacts</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">declare_artifact</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">declare_artifact</span><span class="p">(</span>
<span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">url_path</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">url_path</span><span class="p">,</span>
<span class="n">sources</span><span class="o">=</span><span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">iter_source_filenames</span><span class="p">()))</span> <span class="n">sources</span><span class="o">=</span><span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="o">.</span><span class="n">iter_source_filenames</span><span class="p">()))</span>
<span class="k">def</span> <span class="nf">build_artifact</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">artifact</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">build_artifact</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">artifact</span><span class="p">):</span>
<span class="n">artifact</span><span class="o">.</span><span class="n">render_template_into</span><span class="p">(</span><span class="s1">&#39;view_source.html&#39;</span><span class="p">,</span> <span class="n">artifact</span><span class="o">.</span><span class="n">render_template_into</span><span class="p">(</span><span class="s1">&#39;view_source.html&#39;</span><span class="p">,</span>
<span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="p">)</span> <span class="n">this</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="p">)</span>
<span class="n">env</span><span class="o">.</span><span class="n">add_build_program</span><span class="p">(</span><span class="n">Source</span><span class="p">,</span> <span class="n">SourceBuildProgram</span><span class="p">)</span> <span class="n">env</span><span class="o">.</span><span class="n">add_build_program</span><span class="p">(</span><span class="n">Source</span><span class="p">,</span> <span class="n">SourceBuildProgram</span><span class="p">)</span>
<span class="nd">@env</span><span class="o">.</span><span class="n">virtualpathresolver</span><span class="p">(</span><span class="s1">&#39;source&#39;</span><span class="p">)</span> <span class="nd">@env</span><span class="o">.</span><span class="n">virtualpathresolver</span><span class="p">(</span><span class="s1">&#39;source&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">resolve_virtual_path</span><span class="p">(</span><span class="n">record</span><span class="p">,</span> <span class="n">pieces</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">resolve_virtual_path</span><span class="p">(</span><span class="n">record</span><span class="p">,</span> <span class="n">pieces</span><span class="p">):</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">pieces</span><span class="p">:</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">pieces</span><span class="p">:</span>
<span class="k">return</span> <span class="n">Source</span><span class="p">(</span><span class="n">record</span><span class="p">)</span> <span class="k">return</span> <span class="n">Source</span><span class="p">(</span><span class="n">record</span><span class="p">)</span>
</pre></div> </pre></div>

View File

@ -196,9 +196,9 @@
<p>This method can be used to register a new publisher for a given URL scheme <p>This method can be used to register a new publisher for a given URL scheme
with Lektor. This allows plugins to provide custom deployment methods. For with Lektor. This allows plugins to provide custom deployment methods. For
more information on implementing these see <a href="../../publisher/" class="ref">Publisher</a>.</p> more information on implementing these see <a href="../../publisher/" class="ref">Publisher</a>.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.publisher</span> <span class="kn">import</span> <span class="n">Publisher</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.publisher</span><span class="w"> </span><span class="kn">import</span> <span class="n">Publisher</span>
<span class="k">class</span> <span class="nc">MyPublisher</span><span class="p">(</span><span class="n">Publisher</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">MyPublisher</span><span class="p">(</span><span class="n">Publisher</span><span class="p">):</span>
<span class="k">pass</span> <span class="k">pass</span>
<span class="n">env</span><span class="o">.</span><span class="n">add_publisher</span><span class="p">(</span><span class="s1">&#39;my&#39;</span><span class="p">,</span> <span class="n">MyPublisher</span><span class="p">)</span> <span class="n">env</span><span class="o">.</span><span class="n">add_publisher</span><span class="p">(</span><span class="s1">&#39;my&#39;</span><span class="p">,</span> <span class="n">MyPublisher</span><span class="p">)</span>

View File

@ -194,15 +194,15 @@
</ul> </ul>
<p>This registers a new <a href="../../db/type/" class="ref">Field Type</a> with the environment</p> <p>This registers a new <a href="../../db/type/" class="ref">Field Type</a> with the environment</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.types</span> <span class="kn">import</span> <span class="n">Type</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.types</span><span class="w"> </span><span class="kn">import</span> <span class="n">Type</span>
<span class="k">class</span> <span class="nc">MyThingType</span><span class="p">(</span><span class="n">Type</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">MyThingType</span><span class="p">(</span><span class="n">Type</span><span class="p">):</span>
<span class="n">widget</span> <span class="o">=</span> <span class="s1">&#39;singleline-text&#39;</span> <span class="n">widget</span> <span class="o">=</span> <span class="s1">&#39;singleline-text&#39;</span>
<span class="k">def</span> <span class="nf">value_from_raw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">raw</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">value_from_raw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">raw</span><span class="p">):</span>
<span class="k">return</span> <span class="n">raw</span><span class="o">.</span><span class="n">value</span> <span class="k">return</span> <span class="n">raw</span><span class="o">.</span><span class="n">value</span>
<span class="k">def</span> <span class="nf">setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">add_type</span><span class="p">(</span><span class="n">MyThingType</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">add_type</span><span class="p">(</span><span class="n">MyThingType</span><span class="p">)</span>
</pre></div> </pre></div>

View File

@ -198,22 +198,22 @@ the equation.</p>
<p>The registered function is invoked for each source after it was build. As <p>The registered function is invoked for each source after it was build. As
such it's important to only return items if a virtual sub resource actually such it's important to only return items if a virtual sub resource actually
exists for a page.</p> exists for a page.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.sourceobj</span> <span class="kn">import</span> <span class="n">VirtualSourceObject</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.sourceobj</span><span class="w"> </span><span class="kn">import</span> <span class="n">VirtualSourceObject</span>
<span class="kn">from</span> <span class="nn">lektor.db</span> <span class="kn">import</span> <span class="n">Record</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.db</span><span class="w"> </span><span class="kn">import</span> <span class="n">Record</span>
<span class="kn">from</span> <span class="nn">lektor.utils</span> <span class="kn">import</span> <span class="n">build_url</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.utils</span><span class="w"> </span><span class="kn">import</span> <span class="n">build_url</span>
<span class="k">class</span> <span class="nc">Source</span><span class="p">(</span><span class="n">VirtualSourceObject</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">Source</span><span class="p">(</span><span class="n">VirtualSourceObject</span><span class="p">):</span>
<span class="nd">@property</span> <span class="nd">@property</span>
<span class="k">def</span> <span class="nf">path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">path</span> <span class="o">+</span> <span class="s1">&#39;@source&#39;</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">path</span> <span class="o">+</span> <span class="s1">&#39;@source&#39;</span>
<span class="nd">@property</span> <span class="nd">@property</span>
<span class="k">def</span> <span class="nf">url_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">url_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="n">build_url</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">url_path</span><span class="p">,</span> <span class="s1">&#39;source.txt&#39;</span><span class="p">])</span> <span class="k">return</span> <span class="n">build_url</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">url_path</span><span class="p">,</span> <span class="s1">&#39;source.txt&#39;</span><span class="p">])</span>
<span class="nd">@env</span><span class="o">.</span><span class="n">generator</span> <span class="nd">@env</span><span class="o">.</span><span class="n">generator</span>
<span class="k">def</span> <span class="nf">generate_source_file</span><span class="p">(</span><span class="n">node</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">generate_source_file</span><span class="p">(</span><span class="n">node</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">Record</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">node</span><span class="o">.</span><span class="n">is_attachment</span><span class="p">:</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">Record</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">node</span><span class="o">.</span><span class="n">is_attachment</span><span class="p">:</span>
<span class="k">yield</span> <span class="n">Source</span><span class="p">(</span><span class="n">node</span><span class="p">)</span> <span class="k">yield</span> <span class="n">Source</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
</pre></div> </pre></div>

View File

@ -192,7 +192,7 @@ holds state that is immutable after initialization. For instance it
will hold all loaded plugins, the configuration for the Jinja 2 will hold all loaded plugins, the configuration for the Jinja 2
template engine and more.</p> template engine and more.</p>
<p>Plugins have access to the environment at any point by accessing <code>self.env</code>.</p> <p>Plugins have access to the environment at any point by accessing <code>self.env</code>.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.project</span> <span class="kn">import</span> <span class="n">Project</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.project</span><span class="w"> </span><span class="kn">import</span> <span class="n">Project</span>
<span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span> <span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span>
<span class="n">env</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">make_env</span><span class="p">()</span> <span class="n">env</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">make_env</span><span class="p">()</span>

View File

@ -194,13 +194,13 @@
refer to the <a href="https://jinja.palletsprojects.com/en/3.0.x/api/#jinja2.Environment" class="ext">Jinja 2 Documentation</a>.</p> refer to the <a href="https://jinja.palletsprojects.com/en/3.0.x/api/#jinja2.Environment" class="ext">Jinja 2 Documentation</a>.</p>
<p>This is where plugins can inject additional data like custom filters, tests <p>This is where plugins can inject additional data like custom filters, tests
or global functions.</p> or global functions.</p>
<h2 id="plugin-example">Plugin Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.pluginsystem</span> <span class="kn">import</span> <span class="n">Plugin</span> <h2 id="plugin-example">Plugin Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">Plugin</span>
<span class="k">class</span> <span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="o">...</span> <span class="o">...</span>
<span class="k">def</span> <span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">shout_filter</span><span class="p">(</span><span class="n">value</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">shout_filter</span><span class="p">(</span><span class="n">value</span><span class="p">):</span>
<span class="k">return</span> <span class="n">unicode</span><span class="p">(</span><span class="n">value</span><span class="p">)</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">+</span> <span class="s1">&#39;!!!!1111&#39;</span> <span class="k">return</span> <span class="n">unicode</span><span class="p">(</span><span class="n">value</span><span class="p">)</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="o">+</span> <span class="s1">&#39;!!!!1111&#39;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">jinja_env</span><span class="o">.</span><span class="n">filters</span><span class="p">[</span><span class="s1">&#39;shout&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">shout_filter</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">jinja_env</span><span class="o">.</span><span class="n">filters</span><span class="p">[</span><span class="s1">&#39;shout&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">shout_filter</span>
</pre></div> </pre></div>

View File

@ -198,7 +198,7 @@ gives access to the settings in the project file.</p>
<p>These settings are work in progress and if you want to know how to use <p>These settings are work in progress and if you want to know how to use
the config file and what to do with it, you have to consult the source the config file and what to do with it, you have to consult the source
code.</p> code.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.project</span> <span class="kn">import</span> <span class="n">Project</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.project</span><span class="w"> </span><span class="kn">import</span> <span class="n">Project</span>
<span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span> <span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span>
<span class="n">env</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">make_env</span><span class="p">()</span> <span class="n">env</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">make_env</span><span class="p">()</span>

View File

@ -194,7 +194,7 @@
<p>Normally when an environment is constructed plugins are loaded automatically. <p>Normally when an environment is constructed plugins are loaded automatically.
If you disabled this when creating the environment you can still at a later If you disabled this when creating the environment you can still at a later
point load the plugins by invoking this method.</p> point load the plugins by invoking this method.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.project</span> <span class="kn">import</span> <span class="n">Project</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.project</span><span class="w"> </span><span class="kn">import</span> <span class="n">Project</span>
<span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span> <span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span>
<span class="n">env</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">make_env</span><span class="p">(</span><span class="n">load_plugins</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> <span class="n">env</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">make_env</span><span class="p">(</span><span class="n">load_plugins</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

View File

@ -195,7 +195,7 @@
first construct a <a href="../../db/pad/" class="ref">Pad</a>. This method can do that for first construct a <a href="../../db/pad/" class="ref">Pad</a>. This method can do that for
you. For more information about how the pad works, you can refer to the you. For more information about how the pad works, you can refer to the
general documentation of it.</p> general documentation of it.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.project</span> <span class="kn">import</span> <span class="n">Project</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.project</span><span class="w"> </span><span class="kn">import</span> <span class="n">Project</span>
<span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span> <span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span>
<span class="n">env</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">make_env</span><span class="p">()</span> <span class="n">env</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">make_env</span><span class="p">()</span>

View File

@ -207,7 +207,7 @@ be the closest renderable thing. Typically this is a <a href="../../db/record/"
discovered from <code>this</code> and it will default to <code>_primary</code> if no other discovered from <code>this</code> and it will default to <code>_primary</code> if no other
information can be found.</li> information can be found.</li>
</ul> </ul>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.project</span> <span class="kn">import</span> <span class="n">Project</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.project</span><span class="w"> </span><span class="kn">import</span> <span class="n">Project</span>
<span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span> <span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span>
<span class="n">env</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">make_env</span><span class="p">(</span><span class="n">load_plugins</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> <span class="n">env</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">make_env</span><span class="p">(</span><span class="n">load_plugins</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

View File

@ -198,21 +198,21 @@ This works in combination with <a href="../generator/" class="ref">generator</a>
URL matching part of the equation.</p> URL matching part of the equation.</p>
<p>The registered function is invoked with a source object and a list of <p>The registered function is invoked with a source object and a list of
URL path segments.</p> URL path segments.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.sourceobj</span> <span class="kn">import</span> <span class="n">VirtualSourceObject</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.sourceobj</span><span class="w"> </span><span class="kn">import</span> <span class="n">VirtualSourceObject</span>
<span class="kn">from</span> <span class="nn">lektor.utils</span> <span class="kn">import</span> <span class="n">build_url</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.utils</span><span class="w"> </span><span class="kn">import</span> <span class="n">build_url</span>
<span class="k">class</span> <span class="nc">Source</span><span class="p">(</span><span class="n">VirtualSourceObject</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">Source</span><span class="p">(</span><span class="n">VirtualSourceObject</span><span class="p">):</span>
<span class="nd">@property</span> <span class="nd">@property</span>
<span class="k">def</span> <span class="nf">path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">path</span> <span class="o">+</span> <span class="s1">&#39;@source&#39;</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">path</span> <span class="o">+</span> <span class="s1">&#39;@source&#39;</span>
<span class="nd">@property</span> <span class="nd">@property</span>
<span class="k">def</span> <span class="nf">url_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">url_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="n">build_url</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">url_path</span><span class="p">,</span> <span class="s1">&#39;source.txt&#39;</span><span class="p">])</span> <span class="k">return</span> <span class="n">build_url</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">url_path</span><span class="p">,</span> <span class="s1">&#39;source.txt&#39;</span><span class="p">])</span>
<span class="nd">@env</span><span class="o">.</span><span class="n">urlresolver</span> <span class="nd">@env</span><span class="o">.</span><span class="n">urlresolver</span>
<span class="k">def</span> <span class="nf">match_source_file</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">url_path</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">match_source_file</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">url_path</span><span class="p">):</span>
<span class="k">if</span> <span class="n">url_path</span> <span class="o">==</span> <span class="p">[</span><span class="s1">&#39;source.txt&#39;</span><span class="p">]</span> \ <span class="k">if</span> <span class="n">url_path</span> <span class="o">==</span> <span class="p">[</span><span class="s1">&#39;source.txt&#39;</span><span class="p">]</span> \
<span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">Record</span><span class="p">)</span> \ <span class="ow">and</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">Record</span><span class="p">)</span> \
<span class="ow">and</span> <span class="ow">not</span> <span class="n">node</span><span class="o">.</span><span class="n">is_attachment</span><span class="p">:</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">node</span><span class="o">.</span><span class="n">is_attachment</span><span class="p">:</span>

View File

@ -208,30 +208,30 @@ segments). If they would request <code>/my-page@feed/recent</code> then it woul
pass <code>['recent']</code> as path segments.</p> pass <code>['recent']</code> as path segments.</p>
<h2 id="example">Example</h2><p>Here an example that would implement a virtual source for feeds and an <h2 id="example">Example</h2><p>Here an example that would implement a virtual source for feeds and an
associated virtual path resolver:</p> associated virtual path resolver:</p>
<div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.sourceobj</span> <span class="kn">import</span> <span class="n">VirtualSourceObject</span> <div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.sourceobj</span><span class="w"> </span><span class="kn">import</span> <span class="n">VirtualSourceObject</span>
<span class="kn">from</span> <span class="nn">lektor.utils</span> <span class="kn">import</span> <span class="n">build_url</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.utils</span><span class="w"> </span><span class="kn">import</span> <span class="n">build_url</span>
<span class="k">class</span> <span class="nc">Feed</span><span class="p">(</span><span class="n">VirtualSourceObject</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">Feed</span><span class="p">(</span><span class="n">VirtualSourceObject</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record</span><span class="p">,</span> <span class="n">version</span><span class="o">=</span><span class="s1">&#39;default&#39;</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record</span><span class="p">,</span> <span class="n">version</span><span class="o">=</span><span class="s1">&#39;default&#39;</span><span class="p">):</span>
<span class="n">VirtualSourceObject</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record</span><span class="p">)</span> <span class="n">VirtualSourceObject</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">version</span> <span class="o">=</span> <span class="n">version</span> <span class="bp">self</span><span class="o">.</span><span class="n">version</span> <span class="o">=</span> <span class="n">version</span>
<span class="nd">@property</span> <span class="nd">@property</span>
<span class="k">def</span> <span class="nf">path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">@feed</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span> <span class="k">return</span> <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">@feed</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span>
<span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">path</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">path</span><span class="p">,</span>
<span class="s1">&#39;/&#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">version</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">version</span> <span class="o">!=</span> <span class="s1">&#39;default&#39;</span> <span class="k">else</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;/&#39;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">version</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">version</span> <span class="o">!=</span> <span class="s1">&#39;default&#39;</span> <span class="k">else</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
<span class="p">)</span> <span class="p">)</span>
<span class="nd">@property</span> <span class="nd">@property</span>
<span class="k">def</span> <span class="nf">url_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">url_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="n">build_url</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">url_path</span><span class="p">,</span> <span class="s1">&#39;feed.xml&#39;</span><span class="p">])</span> <span class="k">return</span> <span class="n">build_url</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">record</span><span class="o">.</span><span class="n">url_path</span><span class="p">,</span> <span class="s1">&#39;feed.xml&#39;</span><span class="p">])</span>
<span class="k">def</span> <span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="nd">@self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">virtualpathresolver</span><span class="p">(</span><span class="s1">&#39;feed&#39;</span><span class="p">)</span> <span class="nd">@self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">virtualpathresolver</span><span class="p">(</span><span class="s1">&#39;feed&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">resolve_virtual_path</span><span class="p">(</span><span class="n">record</span><span class="p">,</span> <span class="n">pieces</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">resolve_virtual_path</span><span class="p">(</span><span class="n">record</span><span class="p">,</span> <span class="n">pieces</span><span class="p">):</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">pieces</span><span class="p">:</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">pieces</span><span class="p">:</span>
<span class="k">return</span> <span class="n">Feed</span><span class="p">(</span><span class="n">record</span><span class="p">)</span> <span class="k">return</span> <span class="n">Feed</span><span class="p">(</span><span class="n">record</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">pieces</span> <span class="o">==</span> <span class="p">[</span><span class="s1">&#39;recent&#39;</span><span class="p">]:</span> <span class="k">elif</span> <span class="n">pieces</span> <span class="o">==</span> <span class="p">[</span><span class="s1">&#39;recent&#39;</span><span class="p">]:</span>

View File

@ -214,9 +214,9 @@ most useful for preprocessing sources on the file system before the rest of
the build process should pick it up. For instance here a plugin could inject the build process should pick it up. For instance here a plugin could inject
additional files into the asset folder and similar things.</p> additional files into the asset folder and similar things.</p>
<p>As an example, this is what the <a href="../../../../guides/webpack/" class="ref">Webpack Support</a> uses.</p> <p>As an example, this is what the <a href="../../../../guides/webpack/" class="ref">Webpack Support</a> uses.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">import</span> <span class="nn">subprocess</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">subprocess</span>
<span class="k">def</span> <span class="nf">on_before_build_all</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">builder</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">on_before_build_all</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">builder</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="n">root</span> <span class="o">=</span> <span class="n">ospath</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">root_path</span><span class="p">,</span> <span class="s1">&#39;webpack&#39;</span><span class="p">)</span> <span class="n">root</span> <span class="o">=</span> <span class="n">ospath</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">root_path</span><span class="p">,</span> <span class="s1">&#39;webpack&#39;</span><span class="p">)</span>
<span class="n">subprocess</span><span class="o">.</span><span class="n">Popen</span><span class="p">([</span><span class="s1">&#39;webpack&#39;</span><span class="p">],</span> <span class="n">cwd</span><span class="o">=</span><span class="n">root</span><span class="p">)</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">Popen</span><span class="p">([</span><span class="s1">&#39;webpack&#39;</span><span class="p">],</span> <span class="n">cwd</span><span class="o">=</span><span class="n">root</span><span class="p">)</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
</pre></div> </pre></div>

View File

@ -225,7 +225,7 @@ the usefulness is limited.</p>
<div class="admonition admonition-warning"><p>Note that currently both the builder as well as the build state are <div class="admonition admonition-warning"><p>Note that currently both the builder as well as the build state are
undocumented and unsupported! This means that if a plugin chooses to use those undocumented and unsupported! This means that if a plugin chooses to use those
references to do something with it they should consider that they might break references to do something with it they should consider that they might break
in future versions.</p></div><h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="k">def</span> <span class="nf">on_before_build</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="n">prog</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> in future versions.</p></div><h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">on_before_build</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="n">prog</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;building </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">source</span><span class="o">.</span><span class="n">source_filename</span><span class="p">)</span> <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;building </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">source</span><span class="o">.</span><span class="n">source_filename</span><span class="p">)</span>
</pre></div> </pre></div>

View File

@ -211,9 +211,9 @@
<div class="admonition admonition-note"><p>Future versions of Lektor may change its Markdown parser away from <a href="https://github.com/lepture/mistune">Mistune</a>, and the various markdown related event hooks may be completely removed or work differently if that happens.</p></div><p>This event is emitted right after MarkdownConfig is instantiated, in which configuration can be set. This is done before the renderer is made.</p> <div class="admonition admonition-note"><p>Future versions of Lektor may change its Markdown parser away from <a href="https://github.com/lepture/mistune">Mistune</a>, and the various markdown related event hooks may be completely removed or work differently if that happens.</p></div><p>This event is emitted right after MarkdownConfig is instantiated, in which configuration can be set. This is done before the renderer is made.</p>
<h2 id="example">Example</h2><p><a href="https://github.com/lektor/lektor-markdown-header-anchors" class="ext">lektor-markdown-header-anchors</a> uses this to register a renderer mixin:</p> <h2 id="example">Example</h2><p><a href="https://github.com/lektor/lektor-markdown-header-anchors" class="ext">lektor-markdown-header-anchors</a> uses this to register a renderer mixin:</p>
<div class="hll"><pre><span></span><span class="k">def</span> <span class="nf">on_markdown_config</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <div class="hll"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">on_markdown_config</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="k">class</span> <span class="nc">HeaderAnchorMixin</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">HeaderAnchorMixin</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">header</span><span class="p">(</span><span class="n">renderer</span><span class="p">,</span> <span class="n">text</span><span class="p">,</span> <span class="n">level</span><span class="p">,</span> <span class="n">raw</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">header</span><span class="p">(</span><span class="n">renderer</span><span class="p">,</span> <span class="n">text</span><span class="p">,</span> <span class="n">level</span><span class="p">,</span> <span class="n">raw</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_config</span><span class="p">()</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;anchor-type&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s2">&quot;random&quot;</span><span class="p">:</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_config</span><span class="p">()</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;anchor-type&#39;</span><span class="p">)</span> <span class="o">==</span> <span class="s2">&quot;random&quot;</span><span class="p">:</span>
<span class="n">anchor</span> <span class="o">=</span> <span class="n">uuid</span><span class="o">.</span><span class="n">uuid4</span><span class="p">()</span><span class="o">.</span><span class="n">hex</span><span class="p">[:</span><span class="mi">6</span><span class="p">]</span> <span class="n">anchor</span> <span class="o">=</span> <span class="n">uuid</span><span class="o">.</span><span class="n">uuid4</span><span class="p">()</span><span class="o">.</span><span class="n">hex</span><span class="p">[:</span><span class="mi">6</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span> <span class="k">else</span><span class="p">:</span>

View File

@ -211,7 +211,7 @@
<div class="admonition admonition-note"><p>Future versions of Lektor may change its Markdown parser away from <a href="https://github.com/lepture/mistune">Mistune</a>, and the various markdown related event hooks may be completely removed or work differently if that happens.</p></div><p>This event is emitted before the markdown meta information is set. This can be used to add custom meta variables to the markdown object.</p> <div class="admonition admonition-note"><p>Future versions of Lektor may change its Markdown parser away from <a href="https://github.com/lepture/mistune">Mistune</a>, and the various markdown related event hooks may be completely removed or work differently if that happens.</p></div><p>This event is emitted before the markdown meta information is set. This can be used to add custom meta variables to the markdown object.</p>
<h2 id="example">Example</h2><p><a href="https://github.com/lektor/lektor-markdown-header-anchors" class="ext">lektor-markdown-header-anchors</a> uses this to initialize a meta var as an empty list:</p> <h2 id="example">Example</h2><p><a href="https://github.com/lektor/lektor-markdown-header-anchors" class="ext">lektor-markdown-header-anchors</a> uses this to initialize a meta var as an empty list:</p>
<div class="hll"><pre><span></span><span class="k">def</span> <span class="nf">on_markdown_meta_init</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <div class="hll"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">on_markdown_meta_init</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="n">meta</span><span class="p">[</span><span class="s1">&#39;toc&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span> <span class="n">meta</span><span class="p">[</span><span class="s1">&#39;toc&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
</pre></div> </pre></div>

View File

@ -211,7 +211,7 @@
<div class="admonition admonition-note"><p>Future versions of Lektor may change its Markdown parser away from <a href="https://github.com/lepture/mistune">Mistune</a>, and the various markdown related event hooks may be completely removed or work differently if that happens.</p></div><p>This event is emitted after the markdown has been rendered. This can be used to change the markdown object meta information after the fact.</p> <div class="admonition admonition-note"><p>Future versions of Lektor may change its Markdown parser away from <a href="https://github.com/lepture/mistune">Mistune</a>, and the various markdown related event hooks may be completely removed or work differently if that happens.</p></div><p>This event is emitted after the markdown has been rendered. This can be used to change the markdown object meta information after the fact.</p>
<h2 id="example">Example</h2><p><a href="https://github.com/lektor/lektor-markdown-header-anchors" class="ext">lektor-markdown-header-anchors</a> uses this to populate a meta var:</p> <h2 id="example">Example</h2><p><a href="https://github.com/lektor/lektor-markdown-header-anchors" class="ext">lektor-markdown-header-anchors</a> uses this to populate a meta var:</p>
<div class="hll"><pre><span></span><span class="k">def</span> <span class="nf">on_markdown_meta_postprocess</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <div class="hll"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">on_markdown_meta_postprocess</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">meta</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="n">prev_level</span> <span class="o">=</span> <span class="kc">None</span> <span class="n">prev_level</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">toc</span> <span class="o">=</span> <span class="p">[]</span> <span class="n">toc</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">stack</span> <span class="o">=</span> <span class="p">[</span><span class="n">toc</span><span class="p">]</span> <span class="n">stack</span> <span class="o">=</span> <span class="p">[</span><span class="n">toc</span><span class="p">]</span>

View File

@ -223,7 +223,7 @@ unless they are explicitly passed to it.</p>
if the template was indeed loaded from the templates folder. There are many if the template was indeed loaded from the templates folder. There are many
more places where templates are rendered in those cases the value will more places where templates are rendered in those cases the value will
not be provided.</p> not be provided.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="k">def</span> <span class="nf">on_process_template_context</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">on_process_template_context</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="n">context</span><span class="p">[</span><span class="s1">&#39;my_variable&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;my value&#39;</span> <span class="n">context</span><span class="p">[</span><span class="s1">&#39;my_variable&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;my value&#39;</span>
</pre></div> </pre></div>

View File

@ -214,19 +214,19 @@ to spawn their own development tools. For instance it can be used to
start a background process that kicks off webpack or similar tools. There start a background process that kicks off webpack or similar tools. There
is a second event called <a href="../server-stop/" class="ref">server-stop</a> which can be is a second event called <a href="../server-stop/" class="ref">server-stop</a> which can be
used to detect server shutdowns.</p> used to detect server shutdowns.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">import</span> <span class="nn">os</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">os</span>
<span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">Popen</span> <span class="kn">from</span><span class="w"> </span><span class="nn">subprocess</span><span class="w"> </span><span class="kn">import</span> <span class="n">Popen</span>
<span class="k">class</span> <span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="o">...</span> <span class="o">...</span>
<span class="n">webpack</span> <span class="o">=</span> <span class="kc">None</span> <span class="n">webpack</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">def</span> <span class="nf">on_server_spawn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">on_server_spawn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">root_path</span><span class="p">,</span> <span class="s1">&#39;webpack&#39;</span><span class="p">)</span> <span class="n">path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">root_path</span><span class="p">,</span> <span class="s1">&#39;webpack&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">webpack</span> <span class="o">=</span> <span class="n">Popen</span><span class="p">([</span><span class="s1">&#39;webpack&#39;</span><span class="p">,</span> <span class="s1">&#39;--watch&#39;</span><span class="p">],</span> <span class="n">cwd</span><span class="o">=</span><span class="n">path</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">webpack</span> <span class="o">=</span> <span class="n">Popen</span><span class="p">([</span><span class="s1">&#39;webpack&#39;</span><span class="p">,</span> <span class="s1">&#39;--watch&#39;</span><span class="p">],</span> <span class="n">cwd</span><span class="o">=</span><span class="n">path</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">on_server_stop</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">on_server_stop</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">webpack</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">webpack</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">webpack</span><span class="o">.</span><span class="n">kill</span><span class="p">()</span> <span class="bp">self</span><span class="o">.</span><span class="n">webpack</span><span class="o">.</span><span class="n">kill</span><span class="p">()</span>
</pre></div> </pre></div>

View File

@ -213,7 +213,7 @@
with the <a href="../../../environment/" class="ref">environment</a>. This can be used to with the <a href="../../../environment/" class="ref">environment</a>. This can be used to
reconfigure it. For instance this is the perfect place to inject Jinja 2 reconfigure it. For instance this is the perfect place to inject Jinja 2
filters and global variables.</p> filters and global variables.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="k">def</span> <span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">jinja_env</span><span class="o">.</span><span class="n">globals</span><span class="p">[</span><span class="s1">&#39;my_variable&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;my value&#39;</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">jinja_env</span><span class="o">.</span><span class="n">globals</span><span class="p">[</span><span class="s1">&#39;my_variable&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;my value&#39;</span>
</pre></div> </pre></div>

View File

@ -169,7 +169,7 @@
or plugin class. This is particularly useful to retrieve state from a plugin. or plugin class. This is particularly useful to retrieve state from a plugin.
If the <code>env</code> is not given a context needs to be active and the env of the If the <code>env</code> is not given a context needs to be active and the env of the
context is used.</p> context is used.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.pluginsystem</span> <span class="kn">import</span> <span class="n">get_plugin</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">get_plugin</span>
<span class="n">plugin</span> <span class="o">=</span> <span class="n">get_plugin</span><span class="p">(</span><span class="s1">&#39;the-plugin-id&#39;</span><span class="p">)</span> <span class="n">plugin</span> <span class="o">=</span> <span class="n">get_plugin</span><span class="p">(</span><span class="s1">&#39;the-plugin-id&#39;</span><span class="p">)</span>
<span class="n">cfg</span> <span class="o">=</span> <span class="n">plugin</span><span class="o">.</span><span class="n">get_config</span><span class="p">()</span> <span class="n">cfg</span> <span class="o">=</span> <span class="n">plugin</span><span class="o">.</span><span class="n">get_config</span><span class="p">()</span>

View File

@ -191,19 +191,19 @@ plugin in the loaded project. This is by default in <code>configs/&lt;plugin-id
Plugins could override this in theory but it's not recommended. The primary Plugins could override this in theory but it's not recommended. The primary
use of this property is to track dependencies.</p> use of this property is to track dependencies.</p>
<p>For a convenient way to load the config see <a href="../get-config/">get_config</a>.</p> <p>For a convenient way to load the config see <a href="../get-config/">get_config</a>.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.pluginsystem</span> <span class="kn">import</span> <span class="n">Plugin</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">Plugin</span>
<span class="kn">from</span> <span class="nn">lektor.context</span> <span class="kn">import</span> <span class="n">get_ctx</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.context</span><span class="w"> </span><span class="kn">import</span> <span class="n">get_ctx</span>
<span class="k">class</span> <span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="n">color</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_config</span><span class="p">()</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;color&#39;</span><span class="p">)</span> <span class="n">color</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_config</span><span class="p">()</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;color&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">get_css</span><span class="p">(</span><span class="n">artifact_name</span><span class="o">=</span><span class="s1">&#39;/static/demo.css&#39;</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">get_css</span><span class="p">(</span><span class="n">artifact_name</span><span class="o">=</span><span class="s1">&#39;/static/demo.css&#39;</span><span class="p">):</span>
<span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span>
<span class="nd">@ctx</span><span class="o">.</span><span class="n">sub_artifact</span><span class="p">(</span><span class="n">artifact_name</span><span class="p">,</span> <span class="n">sources</span><span class="o">=</span><span class="p">[</span> <span class="nd">@ctx</span><span class="o">.</span><span class="n">sub_artifact</span><span class="p">(</span><span class="n">artifact_name</span><span class="p">,</span> <span class="n">sources</span><span class="o">=</span><span class="p">[</span>
<span class="bp">self</span><span class="o">.</span><span class="n">config_filename</span><span class="p">])</span> <span class="bp">self</span><span class="o">.</span><span class="n">config_filename</span><span class="p">])</span>
<span class="k">def</span> <span class="nf">build_stylesheet</span><span class="p">(</span><span class="n">artifact</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">build_stylesheet</span><span class="p">(</span><span class="n">artifact</span><span class="p">):</span>
<span class="k">with</span> <span class="n">artifact</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="k">with</span> <span class="n">artifact</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;body { background: </span><span class="si">%s</span><span class="s1"> }</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">color</span><span class="p">)</span> <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;body { background: </span><span class="si">%s</span><span class="s1"> }</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">color</span><span class="p">)</span>
<span class="k">return</span> <span class="n">artifact_name</span> <span class="k">return</span> <span class="n">artifact_name</span>

View File

@ -188,10 +188,10 @@
<p>This is a short string with some more explanation of what the plugin does. <p>This is a short string with some more explanation of what the plugin does.
It's shown in the UI to give the user some ideas about its operation.</p> It's shown in the UI to give the user some ideas about its operation.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.pluginsystem</span> <span class="kn">import</span> <span class="n">Plugin</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">Plugin</span>
<span class="k">class</span> <span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;My Plugin&#39;</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;My Plugin&#39;</span>
<span class="n">description</span> <span class="o">=</span> <span class="s1">&#39;This is a small plugin I wrote for testing purposes&#39;</span> <span class="n">description</span> <span class="o">=</span> <span class="s1">&#39;This is a small plugin I wrote for testing purposes&#39;</span>
</pre></div> </pre></div>

View File

@ -189,21 +189,21 @@
<p>This method can be used to emit an event that other plugins can hook. The <p>This method can be used to emit an event that other plugins can hook. The
event name is prefixed with the plugin ID.</p> event name is prefixed with the plugin ID.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.pluginsystem</span> <span class="kn">import</span> <span class="n">Plugin</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">Plugin</span>
<span class="k">class</span> <span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">emit</span><span class="p">(</span><span class="s1">&#39;setup&#39;</span><span class="p">,</span> <span class="n">foo</span><span class="o">=</span><span class="mi">42</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">emit</span><span class="p">(</span><span class="s1">&#39;setup&#39;</span><span class="p">,</span> <span class="n">foo</span><span class="o">=</span><span class="mi">42</span><span class="p">)</span>
</pre></div> </pre></div>
<p>Another plugin can then hook this:</p> <p>Another plugin can then hook this:</p>
<div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.pluginsystem</span> <span class="kn">import</span> <span class="n">Plugin</span> <div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">Plugin</span>
<span class="k">class</span> <span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">on_my_plugin_setup</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">foo</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">on_my_plugin_setup</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">foo</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;got </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">foo</span><span class="p">)</span> <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;got </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="n">foo</span><span class="p">)</span>
</pre></div> </pre></div>
<p>(This assumes the plugin id is set to <code>my-plugin</code> in <code>setup.py</code>)</p> <p>(This assumes the plugin id is set to <code>my-plugin</code> in <code>setup.py</code>)</p>

View File

@ -190,12 +190,12 @@
<p>This loads the config of the plugin as an <a href="https://github.com/mitsuhiko/python-inifile" class="ext">Ini File</a>.</p> <p>This loads the config of the plugin as an <a href="https://github.com/mitsuhiko/python-inifile" class="ext">Ini File</a>.</p>
<p>Dotted paths are used to navigate into sections. So <code>get('foo.bar')</code> would <p>Dotted paths are used to navigate into sections. So <code>get('foo.bar')</code> would
navigate to the <code>bar</code> key in the <code>[foo]</code> section.</p> navigate to the <code>bar</code> key in the <code>[foo]</code> section.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.pluginsystem</span> <span class="kn">import</span> <span class="n">Plugin</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">Plugin</span>
<span class="k">class</span> <span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="n">color</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_config</span><span class="p">()</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;color&#39;</span><span class="p">)</span> <span class="n">color</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_config</span><span class="p">()</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;color&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">jinja_env</span><span class="o">.</span><span class="n">globals</span><span class="p">[</span><span class="s1">&#39;my_color&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">color</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">jinja_env</span><span class="o">.</span><span class="n">globals</span><span class="p">[</span><span class="s1">&#39;my_color&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">color</span>
</pre></div> </pre></div>

View File

@ -188,10 +188,10 @@
<p>This property needs to be set to a human readable name for the plugin. It's <p>This property needs to be set to a human readable name for the plugin. It's
what's shown in the UI to show the UI.</p> what's shown in the UI to show the UI.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.pluginsystem</span> <span class="kn">import</span> <span class="n">Plugin</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">Plugin</span>
<span class="k">class</span> <span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;My Plugin&#39;</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;My Plugin&#39;</span>
</pre></div> </pre></div>

View File

@ -171,7 +171,7 @@
out with the current path (of a given base path) and search upwards until it out with the current path (of a given base path) and search upwards until it
finds a folder with a single project file in and then loads this. If none finds a folder with a single project file in and then loads this. If none
of that leads to a file then <code>None</code> is returned.</p> of that leads to a file then <code>None</code> is returned.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.project</span> <span class="kn">import</span> <span class="n">Project</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.project</span><span class="w"> </span><span class="kn">import</span> <span class="n">Project</span>
<span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span> <span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span>
</pre></div> </pre></div>

View File

@ -170,7 +170,7 @@
<p>This is the most common way to create a project instance. It's a class <p>This is the most common way to create a project instance. It's a class
method that given the path to a project file will load the project. If method that given the path to a project file will load the project. If
the file does not exist then <code>None</code> is returned.</p> the file does not exist then <code>None</code> is returned.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.project</span> <span class="kn">import</span> <span class="n">Project</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.project</span><span class="w"> </span><span class="kn">import</span> <span class="n">Project</span>
<span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="s1">&#39;/path/to/the/project.lektorproject&#39;</span><span class="p">)</span> <span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="s1">&#39;/path/to/the/project.lektorproject&#39;</span><span class="p">)</span>
</pre></div> </pre></div>

View File

@ -172,7 +172,7 @@
preferred way to construct such a thing.</p> preferred way to construct such a thing.</p>
<p>By default plugins will be loaded and initialized but this can be disabled <p>By default plugins will be loaded and initialized but this can be disabled
by passing <code>load_plugins=False</code>.</p> by passing <code>load_plugins=False</code>.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.project</span> <span class="kn">import</span> <span class="n">Project</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.project</span><span class="w"> </span><span class="kn">import</span> <span class="n">Project</span>
<span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span> <span class="n">project</span> <span class="o">=</span> <span class="n">Project</span><span class="o">.</span><span class="n">discover</span><span class="p">()</span>
<span class="n">env</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">make_env</span><span class="p">()</span> <span class="n">env</span> <span class="o">=</span> <span class="n">project</span><span class="o">.</span><span class="n">make_env</span><span class="p">()</span>

View File

@ -174,16 +174,16 @@
<p>This method takes a message and raises an appropriate failure that aborts <p>This method takes a message and raises an appropriate failure that aborts
the publishing process. This is invoked from within the <a href="../publish/" class="ref">publish</a> method to indicate a failure:</p> the publishing process. This is invoked from within the <a href="../publish/" class="ref">publish</a> method to indicate a failure:</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.publisher</span> <span class="kn">import</span> <span class="n">Publisher</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.publisher</span><span class="w"> </span><span class="kn">import</span> <span class="n">Publisher</span>
<span class="k">class</span> <span class="nc">MyPublisher</span><span class="p">(</span><span class="n">Publisher</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">MyPublisher</span><span class="p">(</span><span class="n">Publisher</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">publish</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">target_url</span><span class="p">,</span> <span class="n">credentials</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">publish</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">target_url</span><span class="p">,</span> <span class="n">credentials</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fail</span><span class="p">(</span><span class="s1">&#39;This publisher cannot publish :(&#39;</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">fail</span><span class="p">(</span><span class="s1">&#39;This publisher cannot publish :(&#39;</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">add_publisher</span><span class="p">(</span><span class="s1">&#39;my&#39;</span><span class="p">,</span> <span class="n">MyPublisher</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">add_publisher</span><span class="p">(</span><span class="s1">&#39;my&#39;</span><span class="p">,</span> <span class="n">MyPublisher</span><span class="p">)</span>
</pre></div> </pre></div>

View File

@ -192,14 +192,14 @@ keyword arguments.</li>
the output in the console or in the deploy/publish window in the admin UI.</p> the output in the console or in the deploy/publish window in the admin UI.</p>
<h2 id="example">Example</h2><p>This example implements a simple publisher that just copies all built files <h2 id="example">Example</h2><p>This example implements a simple publisher that just copies all built files
into a new location.</p> into a new location.</p>
<div class="hll"><pre><span></span><span class="kn">import</span> <span class="nn">os</span> <div class="hll"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">os</span>
<span class="kn">import</span> <span class="nn">shutil</span> <span class="kn">import</span><span class="w"> </span><span class="nn">shutil</span>
<span class="kn">from</span> <span class="nn">lektor.publisher</span> <span class="kn">import</span> <span class="n">Publisher</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.publisher</span><span class="w"> </span><span class="kn">import</span> <span class="n">Publisher</span>
<span class="k">class</span> <span class="nc">CopyPublisher</span><span class="p">(</span><span class="n">Publisher</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">CopyPublisher</span><span class="p">(</span><span class="n">Publisher</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">publish</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">target_url</span><span class="p">,</span> <span class="n">credentials</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">publish</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">target_url</span><span class="p">,</span> <span class="n">credentials</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="n">src_path</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_path</span> <span class="n">src_path</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">output_path</span>
<span class="n">dst_path</span> <span class="o">=</span> <span class="n">target_url</span><span class="o">.</span><span class="n">path</span> <span class="n">dst_path</span> <span class="o">=</span> <span class="n">target_url</span><span class="o">.</span><span class="n">path</span>
<span class="n">strip</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">src_path</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span> <span class="n">strip</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">src_path</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>
@ -226,8 +226,8 @@ into a new location.</p>
<span class="k">yield</span> <span class="s1">&#39;Done&#39;</span> <span class="k">yield</span> <span class="s1">&#39;Done&#39;</span>
<span class="k">class</span> <span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">MyPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">add_publisher</span><span class="p">(</span><span class="s1">&#39;copy&#39;</span><span class="p">,</span> <span class="n">CopyPublisher</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">add_publisher</span><span class="p">(</span><span class="s1">&#39;copy&#39;</span><span class="p">,</span> <span class="n">CopyPublisher</span><span class="p">)</span>
</pre></div> </pre></div>
<p>This publisher registers with the <code>copy</code> scheme and could be used like this:</p> <p>This publisher registers with the <code>copy</code> scheme and could be used like this:</p>

View File

@ -182,7 +182,7 @@ of path segments and returns an absolute path. The default behavior is to
guess the trailing slash based on the presence of a dot in the last path guess the trailing slash based on the presence of a dot in the last path
segment. If you want to override the detection you can explicitly pass segment. If you want to override the detection you can explicitly pass
<code>True</code> to enforce a trailing slash or <code>False</code> to avoid it.</p> <code>True</code> to enforce a trailing slash or <code>False</code> to avoid it.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">lektor.utils</span> <span class="kn">import</span> <span class="n">build_url</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.utils</span><span class="w"> </span><span class="kn">import</span> <span class="n">build_url</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">build_url</span><span class="p">([</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="mi">42</span><span class="p">])</span> <span class="gp">&gt;&gt;&gt; </span><span class="n">build_url</span><span class="p">([</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="mi">42</span><span class="p">])</span>
<span class="go">u&#39;/foo/42/&#39;</span> <span class="go">u&#39;/foo/42/&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">build_url</span><span class="p">([</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="mi">23</span><span class="p">])</span> <span class="gp">&gt;&gt;&gt; </span><span class="n">build_url</span><span class="p">([</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="mi">23</span><span class="p">])</span>

View File

@ -177,7 +177,7 @@
<p>Given a Python object (typically a dictionary or tuple) it generates a stable <p>Given a Python object (typically a dictionary or tuple) it generates a stable
MD5 hash from those recursively. This is useful for the <code>config_hash</code> MD5 hash from those recursively. This is useful for the <code>config_hash</code>
parameter with artifacts.</p> parameter with artifacts.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">lektor.utils</span> <span class="kn">import</span> <span class="n">get_structure_hash</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.utils</span><span class="w"> </span><span class="kn">import</span> <span class="n">get_structure_hash</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">get_structure_hash</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span> <span class="gp">&gt;&gt;&gt; </span><span class="n">get_structure_hash</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="go">&#39;fbcf00cb8f6fc7631af7fbff70ca6f87&#39;</span> <span class="go">&#39;fbcf00cb8f6fc7631af7fbff70ca6f87&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">get_structure_hash</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span> <span class="gp">&gt;&gt;&gt; </span><span class="n">get_structure_hash</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">])</span>

View File

@ -179,7 +179,7 @@
<p>Given two Lektor paths this joins them together with the rules that Lektor <p>Given two Lektor paths this joins them together with the rules that Lektor
set up for this. In particular this is important in the presence of set up for this. In particular this is important in the presence of
virtual paths which have their own join semantics.</p> virtual paths which have their own join semantics.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">lektor.utils</span> <span class="kn">import</span> <span class="n">join_path</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.utils</span><span class="w"> </span><span class="kn">import</span> <span class="n">join_path</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">join_path</span><span class="p">(</span><span class="s1">&#39;/blog&#39;</span><span class="p">,</span> <span class="s1">&#39;hello-world&#39;</span><span class="p">)</span> <span class="gp">&gt;&gt;&gt; </span><span class="n">join_path</span><span class="p">(</span><span class="s1">&#39;/blog&#39;</span><span class="p">,</span> <span class="s1">&#39;hello-world&#39;</span><span class="p">)</span>
<span class="go">&#39;/blog/hello-world&#39;</span> <span class="go">&#39;/blog/hello-world&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">join_path</span><span class="p">(</span><span class="s1">&#39;/blog&#39;</span><span class="p">,</span> <span class="s1">&#39;@archive&#39;</span><span class="p">)</span> <span class="gp">&gt;&gt;&gt; </span><span class="n">join_path</span><span class="p">(</span><span class="s1">&#39;/blog&#39;</span><span class="p">,</span> <span class="s1">&#39;@archive&#39;</span><span class="p">)</span>

View File

@ -179,7 +179,7 @@
<p>This function parses a path into the individual components it's made from. <p>This function parses a path into the individual components it's made from.
The path is always assumed to be absolute and made absolute if it's not yet The path is always assumed to be absolute and made absolute if it's not yet
so. The root path is the empty list.</p> so. The root path is the empty list.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">lektor.utils</span> <span class="kn">import</span> <span class="n">parse_path</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.utils</span><span class="w"> </span><span class="kn">import</span> <span class="n">parse_path</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">parse_path</span><span class="p">(</span><span class="s1">&#39;/foo/bar&#39;</span><span class="p">)</span> <span class="gp">&gt;&gt;&gt; </span><span class="n">parse_path</span><span class="p">(</span><span class="s1">&#39;/foo/bar&#39;</span><span class="p">)</span>
<span class="go">[&#39;foo&#39;, &#39;bar&#39;]</span> <span class="go">[&#39;foo&#39;, &#39;bar&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">parse_path</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span> <span class="gp">&gt;&gt;&gt; </span><span class="n">parse_path</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>

View File

@ -182,15 +182,15 @@ width and/or height, and the operation mode.
In the default mode, if width or height are <code>None</code>, they are calculated In the default mode, if width or height are <code>None</code>, they are calculated
from the source image's dimensions so that the image is scaled proportionally.</p> from the source image's dimensions so that the image is scaled proportionally.</p>
<p>Used internally for the implementation of <a href="../../db/record/thumbnail/" class="ref">thumbnail</a>, and exposed as an API for image-processing plugins.</p> <p>Used internally for the implementation of <a href="../../db/record/thumbnail/" class="ref">thumbnail</a>, and exposed as an API for image-processing plugins.</p>
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.build_programs</span> <span class="kn">import</span> <span class="n">AttachmentBuildProgram</span> <h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.build_programs</span><span class="w"> </span><span class="kn">import</span> <span class="n">AttachmentBuildProgram</span>
<span class="kn">from</span> <span class="nn">lektor.context</span> <span class="kn">import</span> <span class="n">get_ctx</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.context</span><span class="w"> </span><span class="kn">import</span> <span class="n">get_ctx</span>
<span class="kn">from</span> <span class="nn">lektor.db</span> <span class="kn">import</span> <span class="n">Image</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.db</span><span class="w"> </span><span class="kn">import</span> <span class="n">Image</span>
<span class="kn">from</span> <span class="nn">lektor.imagetools</span> <span class="kn">import</span> <span class="n">process_image</span><span class="p">,</span> <span class="n">ThumbnailMode</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.imagetools</span><span class="w"> </span><span class="kn">import</span> <span class="n">process_image</span><span class="p">,</span> <span class="n">ThumbnailMode</span>
<span class="kn">from</span> <span class="nn">lektor.pluginsystem</span> <span class="kn">import</span> <span class="n">Plugin</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">Plugin</span>
<span class="k">class</span> <span class="nc">ImageCropBuildProgram</span><span class="p">(</span><span class="n">AttachmentBuildProgram</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">ImageCropBuildProgram</span><span class="p">(</span><span class="n">AttachmentBuildProgram</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">build_artifact</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">artifact</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">build_artifact</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">artifact</span><span class="p">):</span>
<span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span>
<span class="n">width</span><span class="p">,</span> <span class="n">height</span> <span class="o">=</span> <span class="mi">600</span><span class="p">,</span> <span class="mi">400</span> <span class="n">width</span><span class="p">,</span> <span class="n">height</span> <span class="o">=</span> <span class="mi">600</span><span class="p">,</span> <span class="mi">400</span>
<span class="n">source_img</span> <span class="o">=</span> <span class="n">artifact</span><span class="o">.</span><span class="n">source_obj</span><span class="o">.</span><span class="n">attachment_filename</span> <span class="n">source_img</span> <span class="o">=</span> <span class="n">artifact</span><span class="o">.</span><span class="n">source_obj</span><span class="o">.</span><span class="n">attachment_filename</span>
@ -202,8 +202,8 @@ from the source image's dimensions so that the image is scaled proportionally.</
<span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="n">ThumbnailMode</span><span class="o">.</span><span class="n">CROP</span><span class="p">)</span> <span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="n">ThumbnailMode</span><span class="o">.</span><span class="n">CROP</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">ImageCropPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">ImageCropPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">add_build_program</span><span class="p">(</span><span class="n">Image</span><span class="p">,</span> <span class="n">ImageCropBuildProgram</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">add_build_program</span><span class="p">(</span><span class="n">Image</span><span class="p">,</span> <span class="n">ImageCropBuildProgram</span><span class="p">)</span>
</pre></div> </pre></div>

View File

@ -169,7 +169,7 @@ package in the packages folder.</p>
<p>Once that is done, we need to create a <code>setup.py</code> file which tells Lektor <p>Once that is done, we need to create a <code>setup.py</code> file which tells Lektor
what your plugin needs to run. This will already be created for you if what your plugin needs to run. This will already be created for you if
you used the wizard.</p> you used the wizard.</p>
<div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">setuptools</span> <span class="kn">import</span> <span class="n">setup</span> <div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">setuptools</span><span class="w"> </span><span class="kn">import</span> <span class="n">setup</span>
<span class="n">setup</span><span class="p">(</span> <span class="n">setup</span><span class="p">(</span>
<span class="n">name</span><span class="o">=</span><span class="s1">&#39;lektor-hello-world&#39;</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s1">&#39;lektor-hello-world&#39;</span><span class="p">,</span>
@ -213,9 +213,9 @@ example.</li>
<h2 id="creating-the-plugin">Creating The Plugin</h2><p>Now it's time to create our first plugin that does absolutely nothing. We <h2 id="creating-the-plugin">Creating The Plugin</h2><p>Now it's time to create our first plugin that does absolutely nothing. We
create a new file with the name <code>lektor_hello_world.py</code> next to our create a new file with the name <code>lektor_hello_world.py</code> next to our
<code>setup.py</code> and put the following things in:</p> <code>setup.py</code> and put the following things in:</p>
<div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">lektor.pluginsystem</span> <span class="kn">import</span> <span class="n">Plugin</span> <div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">lektor.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">Plugin</span>
<span class="k">class</span> <span class="nc">HelloWorldPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">HelloWorldPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;Hello World&#39;</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;Hello World&#39;</span>
<span class="n">description</span> <span class="o">=</span> <span class="s1">&#39;This is a demo plugin for testing purposes.&#39;</span> <span class="n">description</span> <span class="o">=</span> <span class="s1">&#39;This is a demo plugin for testing purposes.&#39;</span>
</pre></div> </pre></div>
@ -232,7 +232,7 @@ hello-world: Hello World
events that can be hooked but we will only cover a very basic one here, events that can be hooked but we will only cover a very basic one here,
the <code>setup-env</code> event. To respond to it, we need to implement the <code>setup-env</code> event. To respond to it, we need to implement
a function named <code>on_setup_env</code>:</p> a function named <code>on_setup_env</code>:</p>
<div class="hll"><pre><span></span><span class="kn">import</span> <span class="nn">random</span> <div class="hll"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">random</span>
<span class="n">MESSAGES</span> <span class="o">=</span> <span class="p">[</span> <span class="n">MESSAGES</span> <span class="o">=</span> <span class="p">[</span>
<span class="s1">&#39;Reticulating splines&#39;</span><span class="p">,</span> <span class="s1">&#39;Reticulating splines&#39;</span><span class="p">,</span>
@ -240,14 +240,14 @@ a function named <code>on_setup_env</code>:</p>
<span class="s1">&#39;Possessing pawns&#39;</span><span class="p">,</span> <span class="s1">&#39;Possessing pawns&#39;</span><span class="p">,</span>
<span class="p">]</span> <span class="p">]</span>
<span class="k">def</span> <span class="nf">get_random_message</span><span class="p">():</span> <span class="k">def</span><span class="w"> </span><span class="nf">get_random_message</span><span class="p">():</span>
<span class="k">return</span> <span class="n">random</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">MESSAGES</span><span class="p">)</span> <span class="k">return</span> <span class="n">random</span><span class="o">.</span><span class="n">choice</span><span class="p">(</span><span class="n">MESSAGES</span><span class="p">)</span>
<span class="k">class</span> <span class="nc">HelloWorldPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">HelloWorldPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;Hello World&#39;</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;Hello World&#39;</span>
<span class="n">description</span> <span class="o">=</span> <span class="s1">&#39;This is a demo plugin for testing purposes.&#39;</span> <span class="n">description</span> <span class="o">=</span> <span class="s1">&#39;This is a demo plugin for testing purposes.&#39;</span>
<span class="k">def</span> <span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">jinja_env</span><span class="o">.</span><span class="n">globals</span><span class="o">.</span><span class="n">update</span><span class="p">(</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">jinja_env</span><span class="o">.</span><span class="n">globals</span><span class="o">.</span><span class="n">update</span><span class="p">(</span>
<span class="n">get_random_message</span><span class="o">=</span><span class="n">get_random_message</span> <span class="n">get_random_message</span><span class="o">=</span><span class="n">get_random_message</span>
<span class="p">)</span> <span class="p">)</span>

View File

@ -161,19 +161,19 @@ plugins and Lektor itself modify so do not provide a function called
<code>get_script</code> but for instance call it <code>get_my_plugin_script</code>.</li> <code>get_script</code> but for instance call it <code>get_my_plugin_script</code>.</li>
</ul> </ul>
<p>A simple example of a plugin that implements <a href="https://en.gravatar.com/" class="ext">Gravatar</a> support:</p> <p>A simple example of a plugin that implements <a href="https://en.gravatar.com/" class="ext">Gravatar</a> support:</p>
<div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">hashlib</span> <span class="kn">import</span> <span class="n">md5</span> <div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">hashlib</span><span class="w"> </span><span class="kn">import</span> <span class="n">md5</span>
<span class="kn">from</span> <span class="nn">werkzeug.urls</span> <span class="kn">import</span> <span class="n">url_encode</span> <span class="kn">from</span><span class="w"> </span><span class="nn">werkzeug.urls</span><span class="w"> </span><span class="kn">import</span> <span class="n">url_encode</span>
<span class="kn">from</span> <span class="nn">lektor.pluginsystem</span> <span class="kn">import</span> <span class="n">Plugin</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">Plugin</span>
<span class="n">BASE_URL</span> <span class="o">=</span> <span class="s1">&#39;https://secure.gravatar.com/avatar/&#39;</span> <span class="n">BASE_URL</span> <span class="o">=</span> <span class="s1">&#39;https://secure.gravatar.com/avatar/&#39;</span>
<span class="k">def</span> <span class="nf">get_gravatar</span><span class="p">(</span><span class="n">email</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">get_gravatar</span><span class="p">(</span><span class="n">email</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">):</span>
<span class="n">fn</span> <span class="o">=</span> <span class="n">md5</span><span class="p">(</span><span class="n">email</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">))</span><span class="o">.</span><span class="n">hexdigest</span><span class="p">()</span> <span class="n">fn</span> <span class="o">=</span> <span class="n">md5</span><span class="p">(</span><span class="n">email</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">))</span><span class="o">.</span><span class="n">hexdigest</span><span class="p">()</span>
<span class="k">return</span> <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">/</span><span class="si">%s</span><span class="s1">?</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">BASE_URL</span><span class="p">,</span> <span class="n">fn</span><span class="p">,</span> <span class="n">url_encode</span><span class="p">(</span><span class="n">options</span><span class="p">))</span> <span class="k">return</span> <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">/</span><span class="si">%s</span><span class="s1">?</span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">BASE_URL</span><span class="p">,</span> <span class="n">fn</span><span class="p">,</span> <span class="n">url_encode</span><span class="p">(</span><span class="n">options</span><span class="p">))</span>
<span class="k">class</span> <span class="nc">GravatarPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">GravatarPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;Gravatar&#39;</span> <span class="n">name</span> <span class="o">=</span> <span class="s1">&#39;Gravatar&#39;</span>
<span class="k">def</span> <span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">jinja_env</span><span class="o">.</span><span class="n">filters</span><span class="p">[</span><span class="s1">&#39;gravatar&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">get_gravatar</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">jinja_env</span><span class="o">.</span><span class="n">filters</span><span class="p">[</span><span class="s1">&#39;gravatar&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">get_gravatar</span>
</pre></div> </pre></div>
<h2 id="configure-plugins">Configure Plugins</h2><p>Plugins can come with their own config files and it's encouraged that plugins <h2 id="configure-plugins">Configure Plugins</h2><p>Plugins can come with their own config files and it's encouraged that plugins
@ -206,22 +206,22 @@ through the <a href="../../api/build/context/sub-artifact/" class="ref">sub_arti
method which declares a new artifact.</li> method which declares a new artifact.</li>
</ol> </ol>
<p>Here is an example of both ways in one plugin:</p> <p>Here is an example of both ways in one plugin:</p>
<div class="hll"><pre><span></span><span class="kn">import</span> <span class="nn">os</span> <div class="hll"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">os</span>
<span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">json</span> <span class="kn">from</span><span class="w"> </span><span class="nn">flask</span><span class="w"> </span><span class="kn">import</span> <span class="n">json</span>
<span class="kn">from</span> <span class="nn">lektor.pluginsystem</span> <span class="kn">import</span> <span class="n">Plugin</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">Plugin</span>
<span class="k">def</span> <span class="nf">dump_exif</span><span class="p">(</span><span class="n">image</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">dump_exif</span><span class="p">(</span><span class="n">image</span><span class="p">):</span>
<span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span> <span class="n">ctx</span> <span class="o">=</span> <span class="n">get_ctx</span><span class="p">()</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">posixpath</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">image</span><span class="o">.</span><span class="n">path</span><span class="p">,</span> <span class="s1">&#39;-exif.json&#39;</span><span class="p">)</span> <span class="n">path</span> <span class="o">=</span> <span class="n">posixpath</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">image</span><span class="o">.</span><span class="n">path</span><span class="p">,</span> <span class="s1">&#39;-exif.json&#39;</span><span class="p">)</span>
<span class="nd">@ctx</span><span class="o">.</span><span class="n">sub_artifact</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">sources</span><span class="o">=</span><span class="p">[</span><span class="n">image</span><span class="o">.</span><span class="n">source_filename</span><span class="p">])</span> <span class="nd">@ctx</span><span class="o">.</span><span class="n">sub_artifact</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">sources</span><span class="o">=</span><span class="p">[</span><span class="n">image</span><span class="o">.</span><span class="n">source_filename</span><span class="p">])</span>
<span class="k">def</span> <span class="nf">include_file</span><span class="p">(</span><span class="n">artifact</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">include_file</span><span class="p">(</span><span class="n">artifact</span><span class="p">):</span>
<span class="n">ctx</span><span class="o">.</span><span class="n">record_dependency</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)</span> <span class="n">ctx</span><span class="o">.</span><span class="n">record_dependency</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)</span>
<span class="k">with</span> <span class="n">artifact</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;wb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="k">with</span> <span class="n">artifact</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;wb&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">json</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">image</span><span class="o">.</span><span class="n">exif</span><span class="o">.</span><span class="n">to_dict</span><span class="p">(),</span> <span class="n">f</span><span class="p">)</span> <span class="n">json</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">image</span><span class="o">.</span><span class="n">exif</span><span class="o">.</span><span class="n">to_dict</span><span class="p">(),</span> <span class="n">f</span><span class="p">)</span>
<span class="k">return</span> <span class="n">path</span> <span class="k">return</span> <span class="n">path</span>
<span class="k">class</span> <span class="nc">ExifDumpPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">ExifDumpPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">jinja_env</span><span class="o">.</span><span class="n">globals</span><span class="p">[</span><span class="s1">&#39;dump_exif&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dump_exif</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">jinja_env</span><span class="o">.</span><span class="n">globals</span><span class="p">[</span><span class="s1">&#39;dump_exif&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">dump_exif</span>
</pre></div> </pre></div>
<p>This dumps out the EXIF data into a JSON file and returns the artifact name. <p>This dumps out the EXIF data into a JSON file and returns the artifact name.
@ -246,13 +246,13 @@ code here
---- ----
</code></pre> </code></pre>
<p>You can add your "asciidoc" type to Lektor with a plugin:</p> <p>You can add your "asciidoc" type to Lektor with a plugin:</p>
<div class="hll"><pre><span></span><span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">PIPE</span><span class="p">,</span> <span class="n">Popen</span> <div class="hll"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">subprocess</span><span class="w"> </span><span class="kn">import</span> <span class="n">PIPE</span><span class="p">,</span> <span class="n">Popen</span>
<span class="kn">from</span> <span class="nn">lektor.pluginsystem</span> <span class="kn">import</span> <span class="n">Plugin</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">Plugin</span>
<span class="kn">from</span> <span class="nn">lektor.types</span> <span class="kn">import</span> <span class="n">Type</span> <span class="kn">from</span><span class="w"> </span><span class="nn">lektor.types</span><span class="w"> </span><span class="kn">import</span> <span class="n">Type</span>
<span class="k">def</span> <span class="nf">asciidoc_to_html</span><span class="p">(</span><span class="n">text</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">asciidoc_to_html</span><span class="p">(</span><span class="n">text</span><span class="p">):</span>
<span class="c1"># The &quot;-&quot; at the end tells asciidoc to read from stdin.</span> <span class="c1"># The &quot;-&quot; at the end tells asciidoc to read from stdin.</span>
<span class="n">p</span> <span class="o">=</span> <span class="n">Popen</span><span class="p">(</span> <span class="n">p</span> <span class="o">=</span> <span class="n">Popen</span><span class="p">(</span>
<span class="p">[</span><span class="s1">&#39;asciidoc&#39;</span><span class="p">,</span> <span class="s1">&#39;--no-header-footer&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;asciidoc&#39;</span><span class="p">,</span> <span class="s1">&#39;--no-header-footer&#39;</span><span class="p">,</span>
@ -268,26 +268,26 @@ code here
<span class="c1"># Wrapper with an __html__ method prevents</span> <span class="c1"># Wrapper with an __html__ method prevents</span>
<span class="c1"># Lektor from escaping HTML tags.</span> <span class="c1"># Lektor from escaping HTML tags.</span>
<span class="k">class</span> <span class="nc">HTML</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">HTML</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">html</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">html</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">html</span> <span class="o">=</span> <span class="n">html</span> <span class="bp">self</span><span class="o">.</span><span class="n">html</span> <span class="o">=</span> <span class="n">html</span>
<span class="k">def</span> <span class="nf">__html__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">__html__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">html</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">html</span>
<span class="k">class</span> <span class="nc">AsciiDocType</span><span class="p">(</span><span class="n">Type</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">AsciiDocType</span><span class="p">(</span><span class="n">Type</span><span class="p">):</span>
<span class="n">widget</span> <span class="o">=</span> <span class="s1">&#39;multiline-text&#39;</span> <span class="n">widget</span> <span class="o">=</span> <span class="s1">&#39;multiline-text&#39;</span>
<span class="k">def</span> <span class="nf">value_from_raw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">raw</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">value_from_raw</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">raw</span><span class="p">):</span>
<span class="k">return</span> <span class="n">HTML</span><span class="p">(</span><span class="n">asciidoc_to_html</span><span class="p">(</span><span class="n">raw</span><span class="o">.</span><span class="n">value</span> <span class="ow">or</span> <span class="sa">u</span><span class="s1">&#39;&#39;</span><span class="p">))</span> <span class="k">return</span> <span class="n">HTML</span><span class="p">(</span><span class="n">asciidoc_to_html</span><span class="p">(</span><span class="n">raw</span><span class="o">.</span><span class="n">value</span> <span class="ow">or</span> <span class="sa">u</span><span class="s1">&#39;&#39;</span><span class="p">))</span>
<span class="k">class</span> <span class="nc">AsciiDocPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span> <span class="k">class</span><span class="w"> </span><span class="nc">AsciiDocPlugin</span><span class="p">(</span><span class="n">Plugin</span><span class="p">):</span>
<span class="n">name</span> <span class="o">=</span> <span class="sa">u</span><span class="s1">&#39;AsciiDoc&#39;</span> <span class="n">name</span> <span class="o">=</span> <span class="sa">u</span><span class="s1">&#39;AsciiDoc&#39;</span>
<span class="n">description</span> <span class="o">=</span> <span class="sa">u</span><span class="s1">&#39;Adds AsciiDoc field type to Lektor.&#39;</span> <span class="n">description</span> <span class="o">=</span> <span class="sa">u</span><span class="s1">&#39;Adds AsciiDoc field type to Lektor.&#39;</span>
<span class="k">def</span> <span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span> <span class="k">def</span><span class="w"> </span><span class="nf">on_setup_env</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">extra</span><span class="p">):</span>
<span class="c1"># Derives type name &quot;asciidoc&quot; from class name.</span> <span class="c1"># Derives type name &quot;asciidoc&quot; from class name.</span>
<span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">add_type</span><span class="p">(</span><span class="n">AsciiDocType</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">env</span><span class="o">.</span><span class="n">add_type</span><span class="p">(</span><span class="n">AsciiDocType</span><span class="p">)</span>
</pre></div> </pre></div>

View File

@ -152,11 +152,11 @@ some information added about it to your <code>setup.py</code>. At least the key
<code>name</code>, <code>version</code>, <code>author</code>, <code>author_email</code>, <code>url</code> and <code>description</code> need to be <code>name</code>, <code>version</code>, <code>author</code>, <code>author_email</code>, <code>url</code> and <code>description</code> need to be
set. Here is an example of doing this, largely taken from what is given by set. Here is an example of doing this, largely taken from what is given by
the CLI command <code>lektor dev new-plugin</code>:</p> the CLI command <code>lektor dev new-plugin</code>:</p>
<div class="hll"><pre><span></span><span class="kn">import</span> <span class="nn">ast</span> <div class="hll"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">ast</span>
<span class="kn">import</span> <span class="nn">io</span> <span class="kn">import</span><span class="w"> </span><span class="nn">io</span>
<span class="kn">import</span> <span class="nn">re</span> <span class="kn">import</span><span class="w"> </span><span class="nn">re</span>
<span class="kn">from</span> <span class="nn">setuptools</span> <span class="kn">import</span> <span class="n">setup</span><span class="p">,</span> <span class="n">find_packages</span> <span class="kn">from</span><span class="w"> </span><span class="nn">setuptools</span><span class="w"> </span><span class="kn">import</span> <span class="n">setup</span><span class="p">,</span> <span class="n">find_packages</span>
<span class="k">with</span> <span class="n">io</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;README.md&#39;</span><span class="p">,</span> <span class="s1">&#39;rt&#39;</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">&quot;utf8&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span> <span class="k">with</span> <span class="n">io</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">&#39;README.md&#39;</span><span class="p">,</span> <span class="s1">&#39;rt&#39;</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">&quot;utf8&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">readme</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> <span class="n">readme</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>

View File

@ -158,7 +158,7 @@
parametrize themes:</p> parametrize themes:</p>
<div class="hll"><pre><span></span><span class="k">[theme_settings]</span> <div class="hll"><pre><span></span><span class="k">[theme_settings]</span>
<span class="na">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;Lektor&quot;</span> <span class="na">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;Lektor&quot;</span>
<span class="na">github_url</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;https://github.com/lektor&quot;</span> <span class="s">github_url = &quot;https://github.com/lektor&quot;</span>
</pre></div> </pre></div>
<p>And those settings will be accessed in templates through the config env <p>And those settings will be accessed in templates through the config env
variable:</p> variable:</p>

View File

@ -151,7 +151,7 @@ speak multiple languages and allow you to easily create localized websites.</li>
<div class="slideshow-wrapper"> <div class="slideshow-wrapper">
<div class="slideshow"> <div class="slideshow">
<div class="slideshow-inner"> <div class="slideshow-inner">
<div class="carousel slide" data-ride="carousel" data-interval="8500" id="carousel-7778057db8024be6937cebab894bc271"> <div class="carousel slide" data-ride="carousel" data-interval="8500" id="carousel-2a6867753fc643f283ddb2a774ee6ff6">
<div class="carousel-inner" role="listbox"> <div class="carousel-inner" role="listbox">
@ -210,11 +210,11 @@ be completely customized.</p>
</div> </div>
</div> </div>
<a class="left carousel-control" href="#carousel-7778057db8024be6937cebab894bc271" role="button" data-slide="prev"> <a class="left carousel-control" href="#carousel-2a6867753fc643f283ddb2a774ee6ff6" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span> <span class="sr-only">Previous</span>
</a> </a>
<a class="right carousel-control" href="#carousel-7778057db8024be6937cebab894bc271" role="button" data-slide="next"> <a class="right carousel-control" href="#carousel-2a6867753fc643f283ddb2a774ee6ff6" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span> <span class="sr-only">Next</span>
</a> </a>

View File

@ -153,7 +153,7 @@
<span class="na">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">My Blog</span> <span class="na">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">My Blog</span>
<span class="na">source_path</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">/</span> <span class="na">source_path</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">/</span>
<span class="na">url_path</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">/feed.xml</span> <span class="na">url_path</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">/feed.xml</span>
<span class="na">items</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">site.query('/').filter(F.type == 'post')</span> <span class="na">items = site.query('/').filter(F.type =</span><span class="o">=</span><span class="w"> </span><span class="s">'post'</span><span class="err">)</span>
<span class="na">item_model</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">blog-post</span> <span class="na">item_model</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">blog-post</span>
<span class="k">[coffee]</span> <span class="k">[coffee]</span>

View File

@ -188,7 +188,7 @@ determine whether the <code>body</code> field is interpreted as being <code>mark
<span class="k">[fields.body]</span> <span class="k">[fields.body]</span>
<span class="na">label</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">Body</span> <span class="na">label</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">Body</span>
<span class="na">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">polymorphic</span> <span class="na">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">polymorphic</span>
<span class="na">polymorphic_type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">'html' if this.body.lstrip().startswith('&lt;') else 'markdown'</span> <span class="na">polymorphic_type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">'html'</span><span class="w"> </span><span class="s">if this.body.lstrip().startswith('&lt;') else 'markdown'</span>
</pre> </pre>
<p>In this case, the <code>body</code> field will be interpreted as raw HTML if the <p>In this case, the <code>body</code> field will be interpreted as raw HTML if the
content of that field starts with a “<code>&lt;</code>”, otherwise it will be content of that field starts with a “<code>&lt;</code>”, otherwise it will be

View File

@ -202,7 +202,7 @@ tea
<pre lang="ini"><span class="na">items</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">this.parent.children.filter(F.tags.contains(tag))</span> <pre lang="ini"><span class="na">items</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">this.parent.children.filter(F.tags.contains(tag))</span>
</pre> </pre>
<p>You can sort and filter with any expression:</p> <p>You can sort and filter with any expression:</p>
<pre lang="ini"><span class="na">items</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">this.parent.children.filter(F.tags.contains(tag) and F.status == 'published').order_by('-pub_date')</span> <pre lang="ini"><span class="na">items = this.parent.children.filter(F.tags.contains(tag) and F.status =</span><span class="o">=</span><span class="w"> </span><span class="s">'published').order_by('-pub_date'</span><span class="err">)</span>
</pre> </pre>
<p>If the parent page has <a href="https://www.getlektor.com/docs/guides/pagination/" rel="nofollow">a pagination query</a> you may want to use it for tagged pages:</p> <p>If the parent page has <a href="https://www.getlektor.com/docs/guides/pagination/" rel="nofollow">a pagination query</a> you may want to use it for tagged pages:</p>
<pre lang="ini"><span class="na">items</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">this.parent.pagination.items.filter(F.tags.contains(tag))</span> <pre lang="ini"><span class="na">items</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">this.parent.pagination.items.filter(F.tags.contains(tag))</span>

View File

@ -4,80 +4,80 @@ span.linenos { color: inherit; background-color: transparent; padding-left: 5px;
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; } span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.hll .hll { background-color: #ffffcc } .hll .hll { background-color: #ffffcc }
.hll .c { color: #8f5902; font-style: italic } /* Comment */ .hll .c { color: #8F5902; font-style: italic } /* Comment */
.hll .err { color: #a40000; border: 1px solid #ef2929 } /* Error */ .hll .err { color: #A40000; border: 1px solid #EF2929 } /* Error */
.hll .g { color: #000000 } /* Generic */ .hll .g { color: #000 } /* Generic */
.hll .k { color: #204a87; font-weight: bold } /* Keyword */ .hll .k { color: #204A87; font-weight: bold } /* Keyword */
.hll .l { color: #000000 } /* Literal */ .hll .l { color: #000 } /* Literal */
.hll .n { color: #000000 } /* Name */ .hll .n { color: #000 } /* Name */
.hll .o { color: #ce5c00; font-weight: bold } /* Operator */ .hll .o { color: #CE5C00; font-weight: bold } /* Operator */
.hll .x { color: #000000 } /* Other */ .hll .x { color: #000 } /* Other */
.hll .p { color: #000000; font-weight: bold } /* Punctuation */ .hll .p { color: #000; font-weight: bold } /* Punctuation */
.hll .ch { color: #8f5902; font-style: italic } /* Comment.Hashbang */ .hll .ch { color: #8F5902; font-style: italic } /* Comment.Hashbang */
.hll .cm { color: #8f5902; font-style: italic } /* Comment.Multiline */ .hll .cm { color: #8F5902; font-style: italic } /* Comment.Multiline */
.hll .cp { color: #8f5902; font-style: italic } /* Comment.Preproc */ .hll .cp { color: #8F5902; font-style: italic } /* Comment.Preproc */
.hll .cpf { color: #8f5902; font-style: italic } /* Comment.PreprocFile */ .hll .cpf { color: #8F5902; font-style: italic } /* Comment.PreprocFile */
.hll .c1 { color: #8f5902; font-style: italic } /* Comment.Single */ .hll .c1 { color: #8F5902; font-style: italic } /* Comment.Single */
.hll .cs { color: #8f5902; font-style: italic } /* Comment.Special */ .hll .cs { color: #8F5902; font-style: italic } /* Comment.Special */
.hll .gd { color: #a40000 } /* Generic.Deleted */ .hll .gd { color: #A40000 } /* Generic.Deleted */
.hll .ge { color: #000000; font-style: italic } /* Generic.Emph */ .hll .ge { color: #000; font-style: italic } /* Generic.Emph */
.hll .ges { color: #000000; font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .hll .ges { color: #000; font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.hll .gr { color: #ef2929 } /* Generic.Error */ .hll .gr { color: #EF2929 } /* Generic.Error */
.hll .gh { color: #000080; font-weight: bold } /* Generic.Heading */ .hll .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.hll .gi { color: #00A000 } /* Generic.Inserted */ .hll .gi { color: #00A000 } /* Generic.Inserted */
.hll .go { color: #000000; font-style: italic } /* Generic.Output */ .hll .go { color: #000; font-style: italic } /* Generic.Output */
.hll .gp { color: #8f5902 } /* Generic.Prompt */ .hll .gp { color: #8F5902 } /* Generic.Prompt */
.hll .gs { color: #000000; font-weight: bold } /* Generic.Strong */ .hll .gs { color: #000; font-weight: bold } /* Generic.Strong */
.hll .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ .hll .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.hll .gt { color: #a40000; font-weight: bold } /* Generic.Traceback */ .hll .gt { color: #A40000; font-weight: bold } /* Generic.Traceback */
.hll .kc { color: #204a87; font-weight: bold } /* Keyword.Constant */ .hll .kc { color: #204A87; font-weight: bold } /* Keyword.Constant */
.hll .kd { color: #204a87; font-weight: bold } /* Keyword.Declaration */ .hll .kd { color: #204A87; font-weight: bold } /* Keyword.Declaration */
.hll .kn { color: #204a87; font-weight: bold } /* Keyword.Namespace */ .hll .kn { color: #204A87; font-weight: bold } /* Keyword.Namespace */
.hll .kp { color: #204a87; font-weight: bold } /* Keyword.Pseudo */ .hll .kp { color: #204A87; font-weight: bold } /* Keyword.Pseudo */
.hll .kr { color: #204a87; font-weight: bold } /* Keyword.Reserved */ .hll .kr { color: #204A87; font-weight: bold } /* Keyword.Reserved */
.hll .kt { color: #204a87; font-weight: bold } /* Keyword.Type */ .hll .kt { color: #204A87; font-weight: bold } /* Keyword.Type */
.hll .ld { color: #000000 } /* Literal.Date */ .hll .ld { color: #000 } /* Literal.Date */
.hll .m { color: #0000cf; font-weight: bold } /* Literal.Number */ .hll .m { color: #0000CF; font-weight: bold } /* Literal.Number */
.hll .s { color: #4e9a06 } /* Literal.String */ .hll .s { color: #4E9A06 } /* Literal.String */
.hll .na { color: #c4a000 } /* Name.Attribute */ .hll .na { color: #C4A000 } /* Name.Attribute */
.hll .nb { color: #204a87 } /* Name.Builtin */ .hll .nb { color: #204A87 } /* Name.Builtin */
.hll .nc { color: #000000 } /* Name.Class */ .hll .nc { color: #000 } /* Name.Class */
.hll .no { color: #000000 } /* Name.Constant */ .hll .no { color: #000 } /* Name.Constant */
.hll .nd { color: #5c35cc; font-weight: bold } /* Name.Decorator */ .hll .nd { color: #5C35CC; font-weight: bold } /* Name.Decorator */
.hll .ni { color: #ce5c00 } /* Name.Entity */ .hll .ni { color: #CE5C00 } /* Name.Entity */
.hll .ne { color: #cc0000; font-weight: bold } /* Name.Exception */ .hll .ne { color: #C00; font-weight: bold } /* Name.Exception */
.hll .nf { color: #000000 } /* Name.Function */ .hll .nf { color: #000 } /* Name.Function */
.hll .nl { color: #f57900 } /* Name.Label */ .hll .nl { color: #F57900 } /* Name.Label */
.hll .nn { color: #000000 } /* Name.Namespace */ .hll .nn { color: #000 } /* Name.Namespace */
.hll .nx { color: #000000 } /* Name.Other */ .hll .nx { color: #000 } /* Name.Other */
.hll .py { color: #000000 } /* Name.Property */ .hll .py { color: #000 } /* Name.Property */
.hll .nt { color: #204a87; font-weight: bold } /* Name.Tag */ .hll .nt { color: #204A87; font-weight: bold } /* Name.Tag */
.hll .nv { color: #000000 } /* Name.Variable */ .hll .nv { color: #000 } /* Name.Variable */
.hll .ow { color: #204a87; font-weight: bold } /* Operator.Word */ .hll .ow { color: #204A87; font-weight: bold } /* Operator.Word */
.hll .pm { color: #000000; font-weight: bold } /* Punctuation.Marker */ .hll .pm { color: #000; font-weight: bold } /* Punctuation.Marker */
.hll .w { color: #f8f8f8 } /* Text.Whitespace */ .hll .w { color: #F8F8F8 } /* Text.Whitespace */
.hll .mb { color: #0000cf; font-weight: bold } /* Literal.Number.Bin */ .hll .mb { color: #0000CF; font-weight: bold } /* Literal.Number.Bin */
.hll .mf { color: #0000cf; font-weight: bold } /* Literal.Number.Float */ .hll .mf { color: #0000CF; font-weight: bold } /* Literal.Number.Float */
.hll .mh { color: #0000cf; font-weight: bold } /* Literal.Number.Hex */ .hll .mh { color: #0000CF; font-weight: bold } /* Literal.Number.Hex */
.hll .mi { color: #0000cf; font-weight: bold } /* Literal.Number.Integer */ .hll .mi { color: #0000CF; font-weight: bold } /* Literal.Number.Integer */
.hll .mo { color: #0000cf; font-weight: bold } /* Literal.Number.Oct */ .hll .mo { color: #0000CF; font-weight: bold } /* Literal.Number.Oct */
.hll .sa { color: #4e9a06 } /* Literal.String.Affix */ .hll .sa { color: #4E9A06 } /* Literal.String.Affix */
.hll .sb { color: #4e9a06 } /* Literal.String.Backtick */ .hll .sb { color: #4E9A06 } /* Literal.String.Backtick */
.hll .sc { color: #4e9a06 } /* Literal.String.Char */ .hll .sc { color: #4E9A06 } /* Literal.String.Char */
.hll .dl { color: #4e9a06 } /* Literal.String.Delimiter */ .hll .dl { color: #4E9A06 } /* Literal.String.Delimiter */
.hll .sd { color: #8f5902; font-style: italic } /* Literal.String.Doc */ .hll .sd { color: #8F5902; font-style: italic } /* Literal.String.Doc */
.hll .s2 { color: #4e9a06 } /* Literal.String.Double */ .hll .s2 { color: #4E9A06 } /* Literal.String.Double */
.hll .se { color: #4e9a06 } /* Literal.String.Escape */ .hll .se { color: #4E9A06 } /* Literal.String.Escape */
.hll .sh { color: #4e9a06 } /* Literal.String.Heredoc */ .hll .sh { color: #4E9A06 } /* Literal.String.Heredoc */
.hll .si { color: #4e9a06 } /* Literal.String.Interpol */ .hll .si { color: #4E9A06 } /* Literal.String.Interpol */
.hll .sx { color: #4e9a06 } /* Literal.String.Other */ .hll .sx { color: #4E9A06 } /* Literal.String.Other */
.hll .sr { color: #4e9a06 } /* Literal.String.Regex */ .hll .sr { color: #4E9A06 } /* Literal.String.Regex */
.hll .s1 { color: #4e9a06 } /* Literal.String.Single */ .hll .s1 { color: #4E9A06 } /* Literal.String.Single */
.hll .ss { color: #4e9a06 } /* Literal.String.Symbol */ .hll .ss { color: #4E9A06 } /* Literal.String.Symbol */
.hll .bp { color: #3465a4 } /* Name.Builtin.Pseudo */ .hll .bp { color: #3465A4 } /* Name.Builtin.Pseudo */
.hll .fm { color: #000000 } /* Name.Function.Magic */ .hll .fm { color: #000 } /* Name.Function.Magic */
.hll .vc { color: #000000 } /* Name.Variable.Class */ .hll .vc { color: #000 } /* Name.Variable.Class */
.hll .vg { color: #000000 } /* Name.Variable.Global */ .hll .vg { color: #000 } /* Name.Variable.Global */
.hll .vi { color: #000000 } /* Name.Variable.Instance */ .hll .vi { color: #000 } /* Name.Variable.Instance */
.hll .vm { color: #000000 } /* Name.Variable.Magic */ .hll .vm { color: #000 } /* Name.Variable.Magic */
.hll .il { color: #0000cf; font-weight: bold } /* Literal.Number.Integer.Long */ .hll .il { color: #0000CF; font-weight: bold } /* Literal.Number.Integer.Long */