Synchronized build
This commit is contained in:
parent
2cd38ca510
commit
251c54ba15
|
@ -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>
|
||||
<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">'artifact.txt'</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">'w'</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">'Hello World!</span><span class="se">\n</span><span class="s1">'</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
|
|
@ -199,7 +199,7 @@ committed when the entire build process goes through smoothly and the
|
|||
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>
|
||||
<span class="nd">@ctx</span><span class="o">.</span><span class="n">sub_artifact</span><span class="p">(</span><span class="s1">'artifact.txt'</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">'w'</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">'Hello World!</span><span class="se">\n</span><span class="s1">'</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
|
|
@ -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
|
||||
the <a href="../../../environment/render-template/" class="ref">render_template</a> method of the
|
||||
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="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="bp">self</span><span class="o">.</span><span class="n">source</span><span class="p">[</span><span class="s1">'_template'</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>
|
||||
|
|
|
@ -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>
|
||||
<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">'artifact.txt'</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">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>
|
||||
|
|
|
@ -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>
|
||||
function which will return it. If there is no artifact build ongoing then
|
||||
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="nb">print</span><span class="p">(</span><span class="s1">'The current source is </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">ctx</span><span class="o">.</span><span class="n">source</span><span class="p">)</span>
|
||||
|
|
|
@ -197,7 +197,7 @@
|
|||
|
||||
<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>
|
||||
<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="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>
|
||||
|
|
|
@ -209,13 +209,13 @@ to record this as a dependency.</p>
|
|||
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
|
||||
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>
|
||||
<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">import</span><span class="w"> </span><span class="nn">os</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="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">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">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">'inc'</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="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>
|
||||
|
|
|
@ -198,7 +198,7 @@
|
|||
<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
|
||||
<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="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>
|
||||
|
|
|
@ -199,7 +199,7 @@
|
|||
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
|
||||
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="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>
|
||||
|
|
|
@ -214,16 +214,16 @@ artifact is already considered up to date.</p>
|
|||
provided it can identify the configuration that the artifact was created
|
||||
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>
|
||||
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="kn">import</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>
|
||||
<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="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="nf">get_css</span><span class="p">(</span><span class="n">artifact_name</span><span class="o">=</span><span class="s1">'/demo.css'</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="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">'/demo.css'</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="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">'w'</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">'body { background: red; }</span><span class="se">\n</span><span class="s1">'</span><span class="p">)</span>
|
||||
<span class="k">return</span> <span class="n">artifact_name</span>
|
||||
|
|
|
@ -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
|
||||
available.</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>
|
||||
</pre></div>
|
||||
|
|
|
@ -190,7 +190,7 @@
|
|||
<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
|
||||
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">yield</span> <span class="n">child</span>
|
||||
</pre></div>
|
||||
|
|
|
@ -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>
|
||||
<p>The key is in dotted notation. For more information about this refer
|
||||
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">'i18n.</span><span class="si">%s</span><span class="s1">.</span><span class="si">%s</span><span class="s1">'</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>
|
||||
|
||||
|
|
|
@ -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="p"></</span><span class="nt">ul</span><span class="p">></span>
|
||||
</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="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s1">'hotel'</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">stars</span> <span class="o">>=</span> <span class="mi">3</span><span class="p">))</span>
|
||||
</pre></div>
|
||||
|
|
|
@ -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="p"></</span><span class="nt">ul</span><span class="p">></span>
|
||||
</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="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s1">'hotel'</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">'apartment'</span><span class="p">))</span>
|
||||
</pre></div>
|
||||
|
|
|
@ -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
|
||||
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>
|
||||
<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>
|
||||
<span class="kn">from</span> <span class="nn">lektor.utils</span> <span class="kn">import</span> <span class="n">build_url</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="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="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">'@source'</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">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">'utf-8'</span><span class="p">)</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">'source.txt'</span><span class="p">])</span>
|
||||
</pre></div>
|
||||
<p>For more information see <a href="../../environment/add-build-program/" class="ref">add-build-program</a> as well as
|
||||
|
|
|
@ -232,7 +232,7 @@ how to do this through the <a href="get/" class="ref">get</a> method:</p>
|
|||
</pre></div>
|
||||
<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>
|
||||
<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="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
|
||||
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>
|
||||
<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">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>
|
||||
|
|
|
@ -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
|
||||
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>
|
||||
<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">'singleline-text'</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">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>
|
||||
</pre></div>
|
||||
<div class="admonition admonition-tip"><p>In the above example, the new type declares a base class of <code>SingleInputType</code>.
|
||||
|
|
|
@ -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
|
||||
value. For more information see the raw value information below and the
|
||||
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">'singleline-text'</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">return</span> <span class="n">raw</span><span class="o">.</span><span class="n">missing_value</span><span class="p">(</span><span class="s1">'Location was not supplied'</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">'Location was malformed'</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>
|
||||
</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>
|
||||
|
|
|
@ -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.
|
||||
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>
|
||||
<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">'singleline-text'</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>
|
||||
</pre></div>
|
||||
<h2 id="available-widgets">Available Widgets</h2><p>These widgets are currently available:</p>
|
||||
|
|
|
@ -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
|
||||
<a href="../urlresolver/" class="ref">urlresolver</a> and is responsible for generating
|
||||
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>
|
||||
<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="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="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="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="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="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">'@source'</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">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">'utf-8'</span><span class="p">)</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">'source.txt'</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">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="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">'view_source.html'</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="nd">@env</span><span class="o">.</span><span class="n">virtualpathresolver</span><span class="p">(</span><span class="s1">'source'</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">return</span> <span class="n">Source</span><span class="p">(</span><span class="n">record</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
|
|
@ -196,9 +196,9 @@
|
|||
<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
|
||||
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="n">env</span><span class="o">.</span><span class="n">add_publisher</span><span class="p">(</span><span class="s1">'my'</span><span class="p">,</span> <span class="n">MyPublisher</span><span class="p">)</span>
|
||||
|
|
|
@ -194,15 +194,15 @@
|
|||
</ul>
|
||||
|
||||
<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">'singleline-text'</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">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>
|
||||
</pre></div>
|
||||
|
||||
|
|
|
@ -198,22 +198,22 @@ the equation.</p>
|
|||
<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
|
||||
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>
|
||||
<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="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="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="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="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="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">'@source'</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">'source.txt'</span><span class="p">])</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">yield</span> <span class="n">Source</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
|
|
@ -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
|
||||
template engine and more.</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">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>
|
||||
|
|
|
@ -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>
|
||||
<p>This is where plugins can inject additional data like custom filters, tests
|
||||
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="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="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">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">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">'!!!!1111'</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">'shout'</span><span class="p">]</span> <span class="o">=</span> <span class="n">shout_filter</span>
|
||||
</pre></div>
|
||||
|
|
|
@ -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
|
||||
the config file and what to do with it, you have to consult the source
|
||||
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">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>
|
||||
|
|
|
@ -194,7 +194,7 @@
|
|||
<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
|
||||
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">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>
|
||||
|
|
|
@ -195,7 +195,7 @@
|
|||
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
|
||||
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">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>
|
||||
|
|
|
@ -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
|
||||
information can be found.</li>
|
||||
</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">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>
|
||||
|
|
|
@ -198,21 +198,21 @@ This works in combination with <a href="../generator/" class="ref">generator</a>
|
|||
URL matching part of the equation.</p>
|
||||
<p>The registered function is invoked with a source object and a list of
|
||||
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>
|
||||
<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="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="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="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">'@source'</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">'source.txt'</span><span class="p">])</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">'source.txt'</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>
|
||||
|
|
|
@ -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>
|
||||
<h2 id="example">Example</h2><p>Here an example that would implement a virtual source for feeds and an
|
||||
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>
|
||||
<span class="kn">from</span> <span class="nn">lektor.utils</span> <span class="kn">import</span> <span class="n">build_url</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="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">'default'</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">'default'</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="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">'</span><span class="si">%s</span><span class="s1">@feed</span><span class="si">%s</span><span class="s1">'</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="s1">'/'</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">'default'</span> <span class="k">else</span> <span class="s1">''</span><span class="p">,</span>
|
||||
<span class="p">)</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">'feed.xml'</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">'feed'</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">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">'recent'</span><span class="p">]:</span>
|
||||
|
|
|
@ -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
|
||||
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>
|
||||
<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">'webpack'</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">'webpack'</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>
|
||||
|
|
|
@ -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
|
||||
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
|
||||
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">'building </span><span class="si">%s</span><span class="s1">'</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>
|
||||
|
||||
|
|
|
@ -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>
|
||||
<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>
|
||||
<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">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>
|
||||
<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="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="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">'anchor-type'</span><span class="p">)</span> <span class="o">==</span> <span class="s2">"random"</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>
|
||||
|
|
|
@ -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>
|
||||
<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">'toc'</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
|
||||
</pre></div>
|
||||
|
||||
|
|
|
@ -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>
|
||||
<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">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>
|
||||
|
|
|
@ -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
|
||||
more places where templates are rendered in those cases the value will
|
||||
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">'my_variable'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'my value'</span>
|
||||
</pre></div>
|
||||
|
||||
|
|
|
@ -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
|
||||
is a second event called <a href="../server-stop/" class="ref">server-stop</a> which can be
|
||||
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>
|
||||
<span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">Popen</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="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="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">'webpack'</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">'webpack'</span><span class="p">,</span> <span class="s1">'--watch'</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="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>
|
||||
|
|
|
@ -213,7 +213,7 @@
|
|||
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
|
||||
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">'my_variable'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'my value'</span>
|
||||
</pre></div>
|
||||
|
||||
|
|
|
@ -169,7 +169,7 @@
|
|||
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
|
||||
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">'the-plugin-id'</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>
|
||||
|
|
|
@ -191,19 +191,19 @@ plugin in the loaded project. This is by default in <code>configs/<plugin-id
|
|||
Plugins could override this in theory but it's not recommended. The primary
|
||||
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>
|
||||
<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>
|
||||
<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.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">Plugin</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">'color'</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">'/static/demo.css'</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">'/static/demo.css'</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="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">'w'</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">'body { background: </span><span class="si">%s</span><span class="s1"> }</span><span class="se">\n</span><span class="s1">'</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>
|
||||
|
|
|
@ -188,10 +188,10 @@
|
|||
|
||||
<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>
|
||||
<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">'My Plugin'</span>
|
||||
<span class="n">description</span> <span class="o">=</span> <span class="s1">'This is a small plugin I wrote for testing purposes'</span>
|
||||
</pre></div>
|
||||
|
|
|
@ -189,21 +189,21 @@
|
|||
|
||||
<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>
|
||||
<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">'setup'</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>
|
||||
<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">'got </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">foo</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
<p>(This assumes the plugin id is set to <code>my-plugin</code> in <code>setup.py</code>)</p>
|
||||
|
|
|
@ -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>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>
|
||||
<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">'color'</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">'my_color'</span><span class="p">]</span> <span class="o">=</span> <span class="n">color</span>
|
||||
</pre></div>
|
||||
|
|
|
@ -188,10 +188,10 @@
|
|||
|
||||
<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>
|
||||
<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">'My Plugin'</span>
|
||||
</pre></div>
|
||||
|
||||
|
|
|
@ -171,7 +171,7 @@
|
|||
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
|
||||
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>
|
||||
</pre></div>
|
||||
|
|
|
@ -170,7 +170,7 @@
|
|||
<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
|
||||
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">'/path/to/the/project.lektorproject'</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
|
|
@ -172,7 +172,7 @@
|
|||
preferred way to construct such a thing.</p>
|
||||
<p>By default plugins will be loaded and initialized but this can be disabled
|
||||
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">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>
|
||||
|
|
|
@ -174,16 +174,16 @@
|
|||
|
||||
<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>
|
||||
<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">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">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="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">'This publisher cannot publish :('</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">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">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="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">'my'</span><span class="p">,</span> <span class="n">MyPublisher</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
|
|
|
@ -192,14 +192,14 @@ keyword arguments.</li>
|
|||
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
|
||||
into a new location.</p>
|
||||
<div class="hll"><pre><span></span><span class="kn">import</span> <span class="nn">os</span>
|
||||
<span class="kn">import</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>
|
||||
<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="w"> </span><span class="nn">shutil</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">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>
|
||||
|
@ -226,8 +226,8 @@ into a new location.</p>
|
|||
<span class="k">yield</span> <span class="s1">'Done'</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">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">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="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">'copy'</span><span class="p">,</span> <span class="n">CopyPublisher</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
<p>This publisher registers with the <code>copy</code> scheme and could be used like this:</p>
|
||||
|
|
|
@ -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
|
||||
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>
|
||||
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="gp">>>> </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">>>> </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">>>> </span><span class="n">build_url</span><span class="p">([</span><span class="s1">'foo'</span><span class="p">,</span> <span class="mi">42</span><span class="p">])</span>
|
||||
<span class="go">u'/foo/42/'</span>
|
||||
<span class="gp">>>> </span><span class="n">build_url</span><span class="p">([</span><span class="s1">'foo'</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="mi">23</span><span class="p">])</span>
|
||||
|
|
|
@ -177,7 +177,7 @@
|
|||
<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>
|
||||
parameter with artifacts.</p>
|
||||
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="gp">>>> </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">>>> </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">>>> </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">'fbcf00cb8f6fc7631af7fbff70ca6f87'</span>
|
||||
<span class="gp">>>> </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>
|
||||
|
|
|
@ -179,7 +179,7 @@
|
|||
<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
|
||||
virtual paths which have their own join semantics.</p>
|
||||
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="gp">>>> </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">>>> </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">>>> </span><span class="n">join_path</span><span class="p">(</span><span class="s1">'/blog'</span><span class="p">,</span> <span class="s1">'hello-world'</span><span class="p">)</span>
|
||||
<span class="go">'/blog/hello-world'</span>
|
||||
<span class="gp">>>> </span><span class="n">join_path</span><span class="p">(</span><span class="s1">'/blog'</span><span class="p">,</span> <span class="s1">'@archive'</span><span class="p">)</span>
|
||||
|
|
|
@ -179,7 +179,7 @@
|
|||
<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
|
||||
so. The root path is the empty list.</p>
|
||||
<h2 id="example">Example</h2><div class="hll"><pre><span></span><span class="gp">>>> </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">>>> </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">>>> </span><span class="n">parse_path</span><span class="p">(</span><span class="s1">'/foo/bar'</span><span class="p">)</span>
|
||||
<span class="go">['foo', 'bar']</span>
|
||||
<span class="gp">>>> </span><span class="n">parse_path</span><span class="p">(</span><span class="s1">'/'</span><span class="p">)</span>
|
||||
|
|
|
@ -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
|
||||
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>
|
||||
<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>
|
||||
<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="nn">lektor.db</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="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.build_programs</span><span class="w"> </span><span class="kn">import</span> <span class="n">AttachmentBuildProgram</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="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="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="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">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">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="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">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>
|
||||
|
@ -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="k">class</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">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="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>
|
||||
</pre></div>
|
||||
|
||||
|
|
|
@ -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
|
||||
what your plugin needs to run. This will already be created for you if
|
||||
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">name</span><span class="o">=</span><span class="s1">'lektor-hello-world'</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
|
||||
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>
|
||||
<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">'Hello World'</span>
|
||||
<span class="n">description</span> <span class="o">=</span> <span class="s1">'This is a demo plugin for testing purposes.'</span>
|
||||
</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,
|
||||
the <code>setup-env</code> event. To respond to it, we need to implement
|
||||
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="s1">'Reticulating splines'</span><span class="p">,</span>
|
||||
|
@ -240,14 +240,14 @@ a function named <code>on_setup_env</code>:</p>
|
|||
<span class="s1">'Possessing pawns'</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">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">'Hello World'</span>
|
||||
<span class="n">description</span> <span class="o">=</span> <span class="s1">'This is a demo plugin for testing purposes.'</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="n">get_random_message</span><span class="o">=</span><span class="n">get_random_message</span>
|
||||
<span class="p">)</span>
|
||||
|
|
|
@ -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>
|
||||
</ul>
|
||||
<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>
|
||||
<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="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">hashlib</span><span class="w"> </span><span class="kn">import</span> <span class="n">md5</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="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">'https://secure.gravatar.com/avatar/'</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">'utf-8'</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">'</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">'</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">'Gravatar'</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">'gravatar'</span><span class="p">]</span> <span class="o">=</span> <span class="n">get_gravatar</span>
|
||||
</pre></div>
|
||||
<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>
|
||||
</ol>
|
||||
<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>
|
||||
<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="nn">lektor.pluginsystem</span> <span class="kn">import</span> <span class="n">Plugin</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="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="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">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">'-exif.json'</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="k">with</span> <span class="n">artifact</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s1">'wb'</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="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">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">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="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">'dump_exif'</span><span class="p">]</span> <span class="o">=</span> <span class="n">dump_exif</span>
|
||||
</pre></div>
|
||||
<p>This dumps out the EXIF data into a JSON file and returns the artifact name.
|
||||
|
@ -246,13 +246,13 @@ code here
|
|||
----
|
||||
</code></pre>
|
||||
<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="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.pluginsystem</span><span class="w"> </span><span class="kn">import</span> <span class="n">Plugin</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 "-" 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="p">[</span><span class="s1">'asciidoc'</span><span class="p">,</span> <span class="s1">'--no-header-footer'</span><span class="p">,</span>
|
||||
|
@ -268,26 +268,26 @@ code here
|
|||
|
||||
<span class="c1"># Wrapper with an __html__ method prevents</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">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">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="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="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">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">'multiline-text'</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">''</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">'AsciiDoc'</span>
|
||||
<span class="n">description</span> <span class="o">=</span> <span class="sa">u</span><span class="s1">'Adds AsciiDoc field type to Lektor.'</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 "asciidoc" 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>
|
||||
</pre></div>
|
||||
|
|
|
@ -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
|
||||
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>
|
||||
<div class="hll"><pre><span></span><span class="kn">import</span> <span class="nn">ast</span>
|
||||
<span class="kn">import</span> <span class="nn">io</span>
|
||||
<span class="kn">import</span> <span class="nn">re</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="w"> </span><span class="nn">io</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">'README.md'</span><span class="p">,</span> <span class="s1">'rt'</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">"utf8"</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>
|
||||
|
|
|
@ -158,7 +158,7 @@
|
|||
parametrize themes:</p>
|
||||
<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">"Lektor"</span>
|
||||
<span class="na">github_url</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">"https://github.com/lektor"</span>
|
||||
<span class="s">github_url = "https://github.com/lektor"</span>
|
||||
</pre></div>
|
||||
<p>And those settings will be accessed in templates through the config env
|
||||
variable:</p>
|
||||
|
|
|
@ -151,7 +151,7 @@ speak multiple languages and allow you to easily create localized websites.</li>
|
|||
<div class="slideshow-wrapper">
|
||||
<div class="slideshow">
|
||||
<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">
|
||||
|
||||
|
@ -210,11 +210,11 @@ be completely customized.</p>
|
|||
</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="sr-only">Previous</span>
|
||||
</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="sr-only">Next</span>
|
||||
</a>
|
||||
|
|
|
@ -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">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">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="k">[coffee]</span>
|
||||
|
|
|
@ -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="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">polymorphic_type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">'html' if this.body.lstrip().startswith('<') 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('<') else 'markdown'</span>
|
||||
</pre>
|
||||
<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><</code>”, otherwise it will be
|
||||
|
|
|
@ -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>
|
||||
<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>
|
||||
<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>
|
||||
|
|
|
@ -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; }
|
||||
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
|
||||
.hll .hll { background-color: #ffffcc }
|
||||
.hll .c { color: #8f5902; font-style: italic } /* Comment */
|
||||
.hll .err { color: #a40000; border: 1px solid #ef2929 } /* Error */
|
||||
.hll .g { color: #000000 } /* Generic */
|
||||
.hll .k { color: #204a87; font-weight: bold } /* Keyword */
|
||||
.hll .l { color: #000000 } /* Literal */
|
||||
.hll .n { color: #000000 } /* Name */
|
||||
.hll .o { color: #ce5c00; font-weight: bold } /* Operator */
|
||||
.hll .x { color: #000000 } /* Other */
|
||||
.hll .p { color: #000000; font-weight: bold } /* Punctuation */
|
||||
.hll .ch { color: #8f5902; font-style: italic } /* Comment.Hashbang */
|
||||
.hll .cm { color: #8f5902; font-style: italic } /* Comment.Multiline */
|
||||
.hll .cp { color: #8f5902; font-style: italic } /* Comment.Preproc */
|
||||
.hll .cpf { color: #8f5902; font-style: italic } /* Comment.PreprocFile */
|
||||
.hll .c1 { color: #8f5902; font-style: italic } /* Comment.Single */
|
||||
.hll .cs { color: #8f5902; font-style: italic } /* Comment.Special */
|
||||
.hll .gd { color: #a40000 } /* Generic.Deleted */
|
||||
.hll .ge { color: #000000; font-style: italic } /* Generic.Emph */
|
||||
.hll .ges { color: #000000; font-weight: bold; font-style: italic } /* Generic.EmphStrong */
|
||||
.hll .gr { color: #ef2929 } /* Generic.Error */
|
||||
.hll .c { color: #8F5902; font-style: italic } /* Comment */
|
||||
.hll .err { color: #A40000; border: 1px solid #EF2929 } /* Error */
|
||||
.hll .g { color: #000 } /* Generic */
|
||||
.hll .k { color: #204A87; font-weight: bold } /* Keyword */
|
||||
.hll .l { color: #000 } /* Literal */
|
||||
.hll .n { color: #000 } /* Name */
|
||||
.hll .o { color: #CE5C00; font-weight: bold } /* Operator */
|
||||
.hll .x { color: #000 } /* Other */
|
||||
.hll .p { color: #000; font-weight: bold } /* Punctuation */
|
||||
.hll .ch { color: #8F5902; font-style: italic } /* Comment.Hashbang */
|
||||
.hll .cm { color: #8F5902; font-style: italic } /* Comment.Multiline */
|
||||
.hll .cp { color: #8F5902; font-style: italic } /* Comment.Preproc */
|
||||
.hll .cpf { color: #8F5902; font-style: italic } /* Comment.PreprocFile */
|
||||
.hll .c1 { color: #8F5902; font-style: italic } /* Comment.Single */
|
||||
.hll .cs { color: #8F5902; font-style: italic } /* Comment.Special */
|
||||
.hll .gd { color: #A40000 } /* Generic.Deleted */
|
||||
.hll .ge { color: #000; font-style: italic } /* Generic.Emph */
|
||||
.hll .ges { color: #000; font-weight: bold; font-style: italic } /* Generic.EmphStrong */
|
||||
.hll .gr { color: #EF2929 } /* Generic.Error */
|
||||
.hll .gh { color: #000080; font-weight: bold } /* Generic.Heading */
|
||||
.hll .gi { color: #00A000 } /* Generic.Inserted */
|
||||
.hll .go { color: #000000; font-style: italic } /* Generic.Output */
|
||||
.hll .gp { color: #8f5902 } /* Generic.Prompt */
|
||||
.hll .gs { color: #000000; font-weight: bold } /* Generic.Strong */
|
||||
.hll .go { color: #000; font-style: italic } /* Generic.Output */
|
||||
.hll .gp { color: #8F5902 } /* Generic.Prompt */
|
||||
.hll .gs { color: #000; font-weight: bold } /* Generic.Strong */
|
||||
.hll .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
|
||||
.hll .gt { color: #a40000; font-weight: bold } /* Generic.Traceback */
|
||||
.hll .kc { color: #204a87; font-weight: bold } /* Keyword.Constant */
|
||||
.hll .kd { color: #204a87; font-weight: bold } /* Keyword.Declaration */
|
||||
.hll .kn { color: #204a87; font-weight: bold } /* Keyword.Namespace */
|
||||
.hll .kp { color: #204a87; font-weight: bold } /* Keyword.Pseudo */
|
||||
.hll .kr { color: #204a87; font-weight: bold } /* Keyword.Reserved */
|
||||
.hll .kt { color: #204a87; font-weight: bold } /* Keyword.Type */
|
||||
.hll .ld { color: #000000 } /* Literal.Date */
|
||||
.hll .m { color: #0000cf; font-weight: bold } /* Literal.Number */
|
||||
.hll .s { color: #4e9a06 } /* Literal.String */
|
||||
.hll .na { color: #c4a000 } /* Name.Attribute */
|
||||
.hll .nb { color: #204a87 } /* Name.Builtin */
|
||||
.hll .nc { color: #000000 } /* Name.Class */
|
||||
.hll .no { color: #000000 } /* Name.Constant */
|
||||
.hll .nd { color: #5c35cc; font-weight: bold } /* Name.Decorator */
|
||||
.hll .ni { color: #ce5c00 } /* Name.Entity */
|
||||
.hll .ne { color: #cc0000; font-weight: bold } /* Name.Exception */
|
||||
.hll .nf { color: #000000 } /* Name.Function */
|
||||
.hll .nl { color: #f57900 } /* Name.Label */
|
||||
.hll .nn { color: #000000 } /* Name.Namespace */
|
||||
.hll .nx { color: #000000 } /* Name.Other */
|
||||
.hll .py { color: #000000 } /* Name.Property */
|
||||
.hll .nt { color: #204a87; font-weight: bold } /* Name.Tag */
|
||||
.hll .nv { color: #000000 } /* Name.Variable */
|
||||
.hll .ow { color: #204a87; font-weight: bold } /* Operator.Word */
|
||||
.hll .pm { color: #000000; font-weight: bold } /* Punctuation.Marker */
|
||||
.hll .w { color: #f8f8f8 } /* Text.Whitespace */
|
||||
.hll .mb { color: #0000cf; font-weight: bold } /* Literal.Number.Bin */
|
||||
.hll .mf { color: #0000cf; font-weight: bold } /* Literal.Number.Float */
|
||||
.hll .mh { color: #0000cf; font-weight: bold } /* Literal.Number.Hex */
|
||||
.hll .mi { color: #0000cf; font-weight: bold } /* Literal.Number.Integer */
|
||||
.hll .mo { color: #0000cf; font-weight: bold } /* Literal.Number.Oct */
|
||||
.hll .sa { color: #4e9a06 } /* Literal.String.Affix */
|
||||
.hll .sb { color: #4e9a06 } /* Literal.String.Backtick */
|
||||
.hll .sc { color: #4e9a06 } /* Literal.String.Char */
|
||||
.hll .dl { color: #4e9a06 } /* Literal.String.Delimiter */
|
||||
.hll .sd { color: #8f5902; font-style: italic } /* Literal.String.Doc */
|
||||
.hll .s2 { color: #4e9a06 } /* Literal.String.Double */
|
||||
.hll .se { color: #4e9a06 } /* Literal.String.Escape */
|
||||
.hll .sh { color: #4e9a06 } /* Literal.String.Heredoc */
|
||||
.hll .si { color: #4e9a06 } /* Literal.String.Interpol */
|
||||
.hll .sx { color: #4e9a06 } /* Literal.String.Other */
|
||||
.hll .sr { color: #4e9a06 } /* Literal.String.Regex */
|
||||
.hll .s1 { color: #4e9a06 } /* Literal.String.Single */
|
||||
.hll .ss { color: #4e9a06 } /* Literal.String.Symbol */
|
||||
.hll .bp { color: #3465a4 } /* Name.Builtin.Pseudo */
|
||||
.hll .fm { color: #000000 } /* Name.Function.Magic */
|
||||
.hll .vc { color: #000000 } /* Name.Variable.Class */
|
||||
.hll .vg { color: #000000 } /* Name.Variable.Global */
|
||||
.hll .vi { color: #000000 } /* Name.Variable.Instance */
|
||||
.hll .vm { color: #000000 } /* Name.Variable.Magic */
|
||||
.hll .il { color: #0000cf; font-weight: bold } /* Literal.Number.Integer.Long */
|
||||
.hll .gt { color: #A40000; font-weight: bold } /* Generic.Traceback */
|
||||
.hll .kc { color: #204A87; font-weight: bold } /* Keyword.Constant */
|
||||
.hll .kd { color: #204A87; font-weight: bold } /* Keyword.Declaration */
|
||||
.hll .kn { color: #204A87; font-weight: bold } /* Keyword.Namespace */
|
||||
.hll .kp { color: #204A87; font-weight: bold } /* Keyword.Pseudo */
|
||||
.hll .kr { color: #204A87; font-weight: bold } /* Keyword.Reserved */
|
||||
.hll .kt { color: #204A87; font-weight: bold } /* Keyword.Type */
|
||||
.hll .ld { color: #000 } /* Literal.Date */
|
||||
.hll .m { color: #0000CF; font-weight: bold } /* Literal.Number */
|
||||
.hll .s { color: #4E9A06 } /* Literal.String */
|
||||
.hll .na { color: #C4A000 } /* Name.Attribute */
|
||||
.hll .nb { color: #204A87 } /* Name.Builtin */
|
||||
.hll .nc { color: #000 } /* Name.Class */
|
||||
.hll .no { color: #000 } /* Name.Constant */
|
||||
.hll .nd { color: #5C35CC; font-weight: bold } /* Name.Decorator */
|
||||
.hll .ni { color: #CE5C00 } /* Name.Entity */
|
||||
.hll .ne { color: #C00; font-weight: bold } /* Name.Exception */
|
||||
.hll .nf { color: #000 } /* Name.Function */
|
||||
.hll .nl { color: #F57900 } /* Name.Label */
|
||||
.hll .nn { color: #000 } /* Name.Namespace */
|
||||
.hll .nx { color: #000 } /* Name.Other */
|
||||
.hll .py { color: #000 } /* Name.Property */
|
||||
.hll .nt { color: #204A87; font-weight: bold } /* Name.Tag */
|
||||
.hll .nv { color: #000 } /* Name.Variable */
|
||||
.hll .ow { color: #204A87; font-weight: bold } /* Operator.Word */
|
||||
.hll .pm { color: #000; font-weight: bold } /* Punctuation.Marker */
|
||||
.hll .w { color: #F8F8F8 } /* Text.Whitespace */
|
||||
.hll .mb { color: #0000CF; font-weight: bold } /* Literal.Number.Bin */
|
||||
.hll .mf { color: #0000CF; font-weight: bold } /* Literal.Number.Float */
|
||||
.hll .mh { color: #0000CF; font-weight: bold } /* Literal.Number.Hex */
|
||||
.hll .mi { color: #0000CF; font-weight: bold } /* Literal.Number.Integer */
|
||||
.hll .mo { color: #0000CF; font-weight: bold } /* Literal.Number.Oct */
|
||||
.hll .sa { color: #4E9A06 } /* Literal.String.Affix */
|
||||
.hll .sb { color: #4E9A06 } /* Literal.String.Backtick */
|
||||
.hll .sc { color: #4E9A06 } /* Literal.String.Char */
|
||||
.hll .dl { color: #4E9A06 } /* Literal.String.Delimiter */
|
||||
.hll .sd { color: #8F5902; font-style: italic } /* Literal.String.Doc */
|
||||
.hll .s2 { color: #4E9A06 } /* Literal.String.Double */
|
||||
.hll .se { color: #4E9A06 } /* Literal.String.Escape */
|
||||
.hll .sh { color: #4E9A06 } /* Literal.String.Heredoc */
|
||||
.hll .si { color: #4E9A06 } /* Literal.String.Interpol */
|
||||
.hll .sx { color: #4E9A06 } /* Literal.String.Other */
|
||||
.hll .sr { color: #4E9A06 } /* Literal.String.Regex */
|
||||
.hll .s1 { color: #4E9A06 } /* Literal.String.Single */
|
||||
.hll .ss { color: #4E9A06 } /* Literal.String.Symbol */
|
||||
.hll .bp { color: #3465A4 } /* Name.Builtin.Pseudo */
|
||||
.hll .fm { color: #000 } /* Name.Function.Magic */
|
||||
.hll .vc { color: #000 } /* Name.Variable.Class */
|
||||
.hll .vg { color: #000 } /* Name.Variable.Global */
|
||||
.hll .vi { color: #000 } /* Name.Variable.Instance */
|
||||
.hll .vm { color: #000 } /* Name.Variable.Magic */
|
||||
.hll .il { color: #0000CF; font-weight: bold } /* Literal.Number.Integer.Long */
|
Loading…
Reference in New Issue