diff --git a/docs/api/build/artifact/index.html b/docs/api/build/artifact/index.html index abb8dff6..070e3407 100644 --- a/docs/api/build/artifact/index.html +++ b/docs/api/build/artifact/index.html @@ -198,7 +198,7 @@ open the artifact for reading or writing. If the build goes well, Lektor will commit those changes and persist them.
ctx = get_ctx() @ctx.sub_artifact('artifact.txt') -def build_stylesheet(artifact): +def build_stylesheet(artifact): with artifact.open('w') as f: f.write('Hello World!\n')
ctx = get_ctx() @ctx.sub_artifact('artifact.txt') -def build_stylesheet(artifact): +def build_stylesheet(artifact): with artifact.open('w') as f: f.write('Hello World!\n')
fail
parameter. This is similar to the behavior of
the render_template method of the
environment.
-class MyBuildProgram(BuildProgram): +Example
diff --git a/docs/api/build/artifact/replace-with-file/index.html b/docs/api/build/artifact/replace-with-file/index.html index abd68bc2..85a33f8e 100644 --- a/docs/api/build/artifact/replace-with-file/index.html +++ b/docs/api/build/artifact/replace-with-file/index.html @@ -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 withclass MyBuildProgram(BuildProgram): ... - def build_artifact(self, artifact): + def build_artifact(self, artifact): artifact.render_template_into( self.source['_template'], this=self.source)copy=True
.Example
diff --git a/docs/api/build/context/index.html b/docs/api/build/context/index.html index 7f783107..315c48d9 100644 --- a/docs/api/build/context/index.html +++ b/docs/api/build/context/index.html @@ -200,7 +200,7 @@ will look at the context to decide on further operations to perform.ctx = get_ctx() @ctx.sub_artifact('artifact.txt') -def build_stylesheet(artifact): +def build_stylesheet(artifact): temporary_file = invoke_external_program() artifact.replace_with_file(temporary_file)The current context can be discovered by calling the get_ctx function which will return it. If there is no artifact build ongoing then the return value will be
-None
.Basic Example
from lektor.context import get_ctx +Basic Example
from lektor.context import get_ctx ctx = get_ctx() print('The current source is %s' % ctx.source) diff --git a/docs/api/build/context/pad/index.html b/docs/api/build/context/pad/index.html index 2f9b275c..2eb6d18e 100644 --- a/docs/api/build/context/pad/index.html +++ b/docs/api/build/context/pad/index.html @@ -197,7 +197,7 @@To access the current pad from the context, this attribute can be used. It refers to the active Pad.
-Example
from lektor.context import get_ctx +Example
from lektor.context import get_ctx ctx = get_ctx() for child in ctx.pad.root.children: diff --git a/docs/api/build/context/record-dependency/index.html b/docs/api/build/context/record-dependency/index.html index 4f6a2395..dcaa6319 100644 --- a/docs/api/build/context/record-dependency/index.html +++ b/docs/api/build/context/record-dependency/index.html @@ -209,13 +209,13 @@ to record this as a dependency. 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. -Example
import os -from lektor.pluginsystem import Plugin +Example
import os +from lektor.pluginsystem import Plugin -class IncludeFilePlugin(Plugin): +class IncludeFilePlugin(Plugin): - def setup_env(self, **extra): - def include_file(filename): + def setup_env(self, **extra): + def include_file(filename): fn = os.path.join(self.env.root_path, 'inc', filename) get_ctx().record_dependency(fn) with open(fn) as f: diff --git a/docs/api/build/context/record/index.html b/docs/api/build/context/record/index.html index c5bfbe18..41982728 100644 --- a/docs/api/build/context/record/index.html +++ b/docs/api/build/context/record/index.html @@ -198,7 +198,7 @@This works almost exactly like the source property but the difference is that it is
-None
if the source object is not a Record.Example
from lektor.context import get_ctx +Example
from lektor.context import get_ctx ctx = get_ctx() print ctx.record.record_label diff --git a/docs/api/build/context/source/index.html b/docs/api/build/context/source/index.html index 10afa746..aa75ad7e 100644 --- a/docs/api/build/context/source/index.html +++ b/docs/api/build/context/source/index.html @@ -199,7 +199,7 @@ created from Source Objects, 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 beNone
. -Example
from lektor.context import get_ctx +Example
from lektor.context import get_ctx ctx = get_ctx() print ctx.source.source_filename diff --git a/docs/api/build/context/sub-artifact/index.html b/docs/api/build/context/sub-artifact/index.html index 5f69378c..1f95c4f3 100644 --- a/docs/api/build/context/sub-artifact/index.html +++ b/docs/api/build/context/sub-artifact/index.html @@ -214,16 +214,16 @@ artifact is already considered up to date. 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 get_structure_hash. -Example
import os -from lektor.pluginsystem import Plugin +Example
import os +from lektor.pluginsystem import Plugin -class IncludeFilePlugin(Plugin): +class IncludeFilePlugin(Plugin): - def setup_env(self, **extra): - def get_css(artifact_name='/demo.css'): + def setup_env(self, **extra): + def get_css(artifact_name='/demo.css'): ctx = get_ctx() @ctx.sub_artifact(artifact_name) - def build_stylesheet(artifact): + def build_stylesheet(artifact): with artifact.open('w') as f: f.write('body { background: red; }\n') return artifact_name diff --git a/docs/api/build/get-ctx/index.html b/docs/api/build/get-ctx/index.html index bbb23010..54d49975 100644 --- a/docs/api/build/get-ctx/index.html +++ b/docs/api/build/get-ctx/index.html @@ -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.For more information: Context.
-Example
from lektor.context import get_ctx +Example
diff --git a/docs/api/build/program/iter-child-sources/index.html b/docs/api/build/program/iter-child-sources/index.html index 06171194..89cc8e53 100644 --- a/docs/api/build/program/iter-child-sources/index.html +++ b/docs/api/build/program/iter-child-sources/index.html @@ -190,7 +190,7 @@from lektor.context import get_ctx ctx = get_ctx()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.
-Example
def iter_child_sources(self): +Example
diff --git a/docs/api/databags/lookup/index.html b/docs/api/databags/lookup/index.html index d98badaa..fd67d6b9 100644 --- a/docs/api/databags/lookup/index.html +++ b/docs/api/databags/lookup/index.html @@ -168,7 +168,7 @@ Python code. Within templates you can also use the bag function which is easier to call.def iter_child_sources(self): for child in self.sources.children: yield childThe key is in dotted notation. For more information about this refer to the main databags documentation.
-Example
-def translate(pad, alt, key): +Example
diff --git a/docs/api/db/expression/and/index.html b/docs/api/db/expression/and/index.html index e2132613..340618e6 100644 --- a/docs/api/db/expression/and/index.html +++ b/docs/api/db/expression/and/index.html @@ -246,7 +246,7 @@ differs between Python and templates. In templates you have to use the {% endfor %} </ul>def translate(pad, alt, key): return pad.databags.lookup('i18n.%s.%s' % (alt, key), key)Python Example
-def get_hotels(page): +Python Example
diff --git a/docs/api/db/expression/or/index.html b/docs/api/db/expression/or/index.html index 4f63910a..f8824ff7 100644 --- a/docs/api/db/expression/or/index.html +++ b/docs/api/db/expression/or/index.html @@ -246,7 +246,7 @@ differs between Python and templates. In templates you have to use the {% endfor %} </ul>def get_hotels(page): return page.children.filter( (F.type == 'hotel') & (F.stars >= 3))Python Example
def get_hotels_or_apartments(page): +Python Example
diff --git a/docs/api/db/obj/index.html b/docs/api/db/obj/index.html index 0adea3ca..700c8f84 100644 --- a/docs/api/db/obj/index.html +++ b/docs/api/db/obj/index.html @@ -248,22 +248,22 @@ in the path. The part after the at sign is called the “virtual path”. the record's path +def get_hotels_or_apartments(page): return page.children.filter( (F.type == 'hotel') | (F.type == 'apartment'))@source
. So if the record was/hello
then the path would be/hello@source
. The true base record it belongs to can be referenced from the record property. -from lektor.sourceobj import VirtualSourceObject -from lektor.utils import build_url +from lektor.sourceobj import VirtualSourceObject +from lektor.utils import build_url -class Source(VirtualSourceObject): +class Source(VirtualSourceObject): @property - def path(self): + def path(self): return self.record.path + '@source' @property - def source_content(self): + def source_content(self): with open(self.record.source_filename) as f: return f.read().decode('utf-8') @property - def url_path(self): + def url_path(self): return build_url([self.record.url_path, 'source.txt'])For more information see add-build-program as well as diff --git a/docs/api/db/pad/index.html b/docs/api/db/pad/index.html index 1eb0cb85..1c242f26 100644 --- a/docs/api/db/pad/index.html +++ b/docs/api/db/pad/index.html @@ -232,7 +232,7 @@ how to do this through the get method:
Plugin Usage
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:
-from lektor.context import get_ctx +from lektor.context import get_ctx ctx = get_ctx() if ctx is not None: @@ -244,7 +244,7 @@ instance.Manual Pad Creation
If you want to work with the database from a script, you can create a pad from the Environment with the help of the new_pad method:
-from lektor.project import Project +from lektor.project import Project project = Project.discover() env = project.make_env() diff --git a/docs/api/db/type/index.html b/docs/api/db/type/index.html index ee69c7f3..4fbbaae2 100644 --- a/docs/api/db/type/index.html +++ b/docs/api/db/type/index.html @@ -202,15 +202,15 @@ method and set thewidget
property as a very basic requirement. to match the type name. If you want to name your typemything
then it needs to be calledMyThingType
. Afterwards you can register it with the environment in setup_env: -from lektor.types.primitives import SingleInputType +from lektor.types.primitives import SingleInputType -class MyThingType(SingleInputType): +class MyThingType(SingleInputType): widget = 'singleline-text' - def value_from_raw(self, raw): + def value_from_raw(self, raw): return raw.value -def setup_env(self, **extra): +def setup_env(self, **extra): self.env.add_type(MyThingType)In the above example, the new type declares a base class of
-SingleInputType
. diff --git a/docs/api/db/type/value-from-raw/index.html b/docs/api/db/type/value-from-raw/index.html index 7adc14ba..940eea24 100644 --- a/docs/api/db/type/value-from-raw/index.html +++ b/docs/api/db/type/value-from-raw/index.html @@ -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.Example
from lektor.types import Type +Example
from lektor.types import Type -class LocationType(Type): +class LocationType(Type): widget = 'singleline-text' - def value_from_raw(self, raw): + def value_from_raw(self, raw): if raw.value is None: return raw.missing_value('Location was not supplied') try: @@ -227,7 +227,7 @@ example provided. return raw.bad_value('Location was malformed') return (lng, lat) -def setup_env(self, **extra): +def setup_env(self, **extra): self.env.add_type(LocationType)Raw Value
The value passed is a
diff --git a/docs/api/db/type/widget/index.html b/docs/api/db/type/widget/index.html index b61743ed..15d28b12 100644 --- a/docs/api/db/type/widget/index.html +++ b/docs/api/db/type/widget/index.html @@ -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 theraw
value type. It has a few properties and methods:select
widget and some others will currently require some extra values be supplied in the to_json method. -Example
from lektor.types import Type +Example
from lektor.types import Type -class MyThingType(Type): +class MyThingType(Type): widget = 'singleline-text' - def value_from_raw(self, raw): + def value_from_raw(self, raw): return raw.valueAvailable Widgets
These widgets are currently available:
diff --git a/docs/api/environment/add-build-program/index.html b/docs/api/environment/add-build-program/index.html index 534bdeba..b8306924 100644 --- a/docs/api/environment/add-build-program/index.html +++ b/docs/api/environment/add-build-program/index.html @@ -196,40 +196,40 @@ custom source objects. This can be used to implement virtual items. This works in combination with generator and urlresolver and is responsible for generating artifacts out of source objects. -Example
from lektor.sourceobj import VirtualSourceObject -from lektor.build_programs import BuildProgram -from lektor.utils import build_url +Example
diff --git a/docs/api/environment/add-publisher/index.html b/docs/api/environment/add-publisher/index.html index 8029b897..02ee5f6f 100644 --- a/docs/api/environment/add-publisher/index.html +++ b/docs/api/environment/add-publisher/index.html @@ -196,9 +196,9 @@from lektor.sourceobj import VirtualSourceObject +from lektor.build_programs import BuildProgram +from lektor.utils import build_url -class Source(VirtualSourceObject): +class Source(VirtualSourceObject): @property - def path(self): + def path(self): return self.record.path + '@source' @property - def source_content(self): + def source_content(self): with open(self.record.source_filename) as f: return f.read().decode('utf-8') @property - def url_path(self): + def url_path(self): return build_url([self.record.url_path, 'source.txt']) -class SourceBuildProgram(BuildProgram): +class SourceBuildProgram(BuildProgram): - def produce_artifacts(self): + def produce_artifacts(self): self.declare_artifact( self.source.url_path, sources=list(self.source.iter_source_filenames())) - def build_artifact(self, artifact): + def build_artifact(self, artifact): artifact.render_template_into('view_source.html', this=self.source) env.add_build_program(Source, SourceBuildProgram) @env.virtualpathresolver('source') -def resolve_virtual_path(record, pieces): +def resolve_virtual_path(record, pieces): if not pieces: return Source(record)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 Publisher.
-Example
from lektor.publisher import Publisher +Example
from lektor.publisher import Publisher -class MyPublisher(Publisher): +class MyPublisher(Publisher): pass env.add_publisher('my', MyPublisher) diff --git a/docs/api/environment/add-type/index.html b/docs/api/environment/add-type/index.html index bb9385f6..8319c5ee 100644 --- a/docs/api/environment/add-type/index.html +++ b/docs/api/environment/add-type/index.html @@ -194,15 +194,15 @@This registers a new Field Type with the environment
-Example
from lektor.types import Type +Example
diff --git a/docs/api/environment/generator/index.html b/docs/api/environment/generator/index.html index c7575c1c..03db8a49 100644 --- a/docs/api/environment/generator/index.html +++ b/docs/api/environment/generator/index.html @@ -198,22 +198,22 @@ the equation.from lektor.types import Type -class MyThingType(Type): +class MyThingType(Type): widget = 'singleline-text' - def value_from_raw(self, raw): + def value_from_raw(self, raw): return raw.value -def setup_env(self, **extra): +def setup_env(self, **extra): self.env.add_type(MyThingType)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.
-Example
from lektor.sourceobj import VirtualSourceObject -from lektor.db import Record -from lektor.utils import build_url +Example
diff --git a/docs/api/environment/index.html b/docs/api/environment/index.html index cfdc412d..a942dc2e 100644 --- a/docs/api/environment/index.html +++ b/docs/api/environment/index.html @@ -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.from lektor.sourceobj import VirtualSourceObject +from lektor.db import Record +from lektor.utils import build_url -class Source(VirtualSourceObject): +class Source(VirtualSourceObject): @property - def path(self): + def path(self): return self.record.path + '@source' @property - def url_path(self): + def url_path(self): return build_url([self.record.url_path, 'source.txt']) @env.generator -def generate_source_file(node): +def generate_source_file(node): if isinstance(node, Record) and not node.is_attachment: yield Source(node)Plugins have access to the environment at any point by accessing
-self.env
.Example
from lektor.project import Project +Example
from lektor.project import Project project = Project.discover() env = project.make_env() diff --git a/docs/api/environment/jinja-env/index.html b/docs/api/environment/jinja-env/index.html index 66c7173a..22008e56 100644 --- a/docs/api/environment/jinja-env/index.html +++ b/docs/api/environment/jinja-env/index.html @@ -194,13 +194,13 @@ refer to the Jinja 2 Documentation.This is where plugins can inject additional data like custom filters, tests or global functions.
-Plugin Example
from lektor.pluginsystem import Plugin +Plugin Example
diff --git a/docs/api/environment/load-config/index.html b/docs/api/environment/load-config/index.html index 6b02a53d..2955d1ba 100644 --- a/docs/api/environment/load-config/index.html +++ b/docs/api/environment/load-config/index.html @@ -198,7 +198,7 @@ gives access to the settings in the project file.from lektor.pluginsystem import Plugin -class MyPlugin(Plugin): +class MyPlugin(Plugin): ... - def on_setup_env(self, **extra): - def shout_filter(value): + def on_setup_env(self, **extra): + def shout_filter(value): return unicode(value).upper() + '!!!!1111' self.env.jinja_env.filters['shout'] = shout_filterThese 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.
-Example
from lektor.project import Project +Example
from lektor.project import Project project = Project.discover() env = project.make_env() diff --git a/docs/api/environment/load-plugins/index.html b/docs/api/environment/load-plugins/index.html index 54352696..e94fc3cf 100644 --- a/docs/api/environment/load-plugins/index.html +++ b/docs/api/environment/load-plugins/index.html @@ -194,7 +194,7 @@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.
-Example
from lektor.project import Project +Example
from lektor.project import Project project = Project.discover() env = project.make_env(load_plugins=False) diff --git a/docs/api/environment/new-pad/index.html b/docs/api/environment/new-pad/index.html index 22df1494..f825a5a1 100644 --- a/docs/api/environment/new-pad/index.html +++ b/docs/api/environment/new-pad/index.html @@ -195,7 +195,7 @@ first construct a Pad. This method can do that for you. For more information about how the pad works, you can refer to the general documentation of it. -Example
from lektor.project import Project +Example
from lektor.project import Project project = Project.discover() env = project.make_env() diff --git a/docs/api/environment/render-template/index.html b/docs/api/environment/render-template/index.html index 000a2fc4..414cb93f 100644 --- a/docs/api/environment/render-template/index.html +++ b/docs/api/environment/render-template/index.html @@ -207,7 +207,7 @@ be the closest renderable thing. Typically this is a this and it will default to_primary
if no other information can be found. -Example
from lektor.project import Project +Example
from lektor.project import Project project = Project.discover() env = project.make_env(load_plugins=False) diff --git a/docs/api/environment/urlresolver/index.html b/docs/api/environment/urlresolver/index.html index 18a40571..33e65116 100644 --- a/docs/api/environment/urlresolver/index.html +++ b/docs/api/environment/urlresolver/index.html @@ -198,21 +198,21 @@ This works in combination with generator URL matching part of the equation.The registered function is invoked with a source object and a list of URL path segments.
-Example
from lektor.sourceobj import VirtualSourceObject -from lektor.utils import build_url +Example
from lektor.sourceobj import VirtualSourceObject +from lektor.utils import build_url -class Source(VirtualSourceObject): +class Source(VirtualSourceObject): @property - def path(self): + def path(self): return self.record.path + '@source' @property - def url_path(self): + def url_path(self): return build_url([self.record.url_path, 'source.txt']) @env.urlresolver -def match_source_file(node, url_path): +def match_source_file(node, url_path): if url_path == ['source.txt'] \ and isinstance(node, Record) \ and not node.is_attachment: diff --git a/docs/api/environment/virtualpathresolver/index.html b/docs/api/environment/virtualpathresolver/index.html index 4e5d3ca5..9351f102 100644 --- a/docs/api/environment/virtualpathresolver/index.html +++ b/docs/api/environment/virtualpathresolver/index.html @@ -208,30 +208,30 @@ segments). If they would request/my-page@feed/recent
then it woul pass['recent']
as path segments.Example
Here an example that would implement a virtual source for feeds and an associated virtual path resolver:
-from lektor.sourceobj import VirtualSourceObject -from lektor.utils import build_url +from lektor.sourceobj import VirtualSourceObject +from lektor.utils import build_url -class Feed(VirtualSourceObject): +class Feed(VirtualSourceObject): - def __init__(self, record, version='default'): + def __init__(self, record, version='default'): VirtualSourceObject.__init__(self, record) self.version = version @property - def path(self): + def path(self): return '%s@feed%s' % ( self.record.path, '/' + self.version if self.version != 'default' else '', ) @property - def url_path(self): + def url_path(self): return build_url([self.record.url_path, 'feed.xml']) -def on_setup_env(self, **extra): +def on_setup_env(self, **extra): @self.env.virtualpathresolver('feed') - def resolve_virtual_path(record, pieces): + def resolve_virtual_path(record, pieces): if not pieces: return Feed(record) elif pieces == ['recent']: diff --git a/docs/api/plugins/events/before-build-all/index.html b/docs/api/plugins/events/before-build-all/index.html index 039ec074..3c505178 100644 --- a/docs/api/plugins/events/before-build-all/index.html +++ b/docs/api/plugins/events/before-build-all/index.html @@ -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.As an example, this is what the Webpack Support uses.
-Example
import subprocess +Example
diff --git a/docs/api/plugins/events/before-build/index.html b/docs/api/plugins/events/before-build/index.html index fdb95790..ac9d8f88 100644 --- a/docs/api/plugins/events/before-build/index.html +++ b/docs/api/plugins/events/before-build/index.html @@ -225,7 +225,7 @@ the usefulness is limited.import subprocess -def on_before_build_all(self, builder, **extra): +def on_before_build_all(self, builder, **extra): root = ospath.join(self.env.root_path, 'webpack') subprocess.Popen(['webpack'], cwd=root).wait()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.
Example
def on_before_build(self, source, prog, **extra): +in future versions.Example
diff --git a/docs/api/plugins/events/markdown-config/index.html b/docs/api/plugins/events/markdown-config/index.html index 03878150..cf4217dd 100644 --- a/docs/api/plugins/events/markdown-config/index.html +++ b/docs/api/plugins/events/markdown-config/index.html @@ -211,9 +211,9 @@def on_before_build(self, source, prog, **extra): print('building %s' % source.source_filename)Future versions of Lektor may change its Markdown parser away from Mistune, and the various markdown related event hooks may be completely removed or work differently if that happens.
This event is emitted right after MarkdownConfig is instantiated, in which configuration can be set. This is done before the renderer is made.
Example
lektor-markdown-header-anchors uses this to register a renderer mixin:
-def on_markdown_config(self, config, **extra): - class HeaderAnchorMixin(object): - def header(renderer, text, level, raw): +def on_markdown_config(self, config, **extra): + class HeaderAnchorMixin(object): + def header(renderer, text, level, raw): if self.get_config().get('anchor-type') == "random": anchor = uuid.uuid4().hex[:6] else: diff --git a/docs/api/plugins/events/markdown-meta-init/index.html b/docs/api/plugins/events/markdown-meta-init/index.html index ae9ae99e..e159bd2b 100644 --- a/docs/api/plugins/events/markdown-meta-init/index.html +++ b/docs/api/plugins/events/markdown-meta-init/index.html @@ -211,7 +211,7 @@Future versions of Lektor may change its Markdown parser away from Mistune, and the various markdown related event hooks may be completely removed or work differently if that happens.
This event is emitted before the markdown meta information is set. This can be used to add custom meta variables to the markdown object.
Example
lektor-markdown-header-anchors uses this to initialize a meta var as an empty list:
-def on_markdown_meta_init(self, meta, **extra): +diff --git a/docs/api/plugins/events/markdown-meta-postprocess/index.html b/docs/api/plugins/events/markdown-meta-postprocess/index.html index c0dbc989..e7591874 100644 --- a/docs/api/plugins/events/markdown-meta-postprocess/index.html +++ b/docs/api/plugins/events/markdown-meta-postprocess/index.html @@ -211,7 +211,7 @@def on_markdown_meta_init(self, meta, **extra): meta['toc'] = []Future versions of Lektor may change its Markdown parser away from Mistune, and the various markdown related event hooks may be completely removed or work differently if that happens.
This event is emitted after the markdown has been rendered. This can be used to change the markdown object meta information after the fact.
Example
lektor-markdown-header-anchors uses this to populate a meta var:
-def on_markdown_meta_postprocess(self, meta, **extra): +def on_markdown_meta_postprocess(self, meta, **extra): prev_level = None toc = [] stack = [toc] diff --git a/docs/api/plugins/events/process-template-context/index.html b/docs/api/plugins/events/process-template-context/index.html index da0fc56f..865dc314 100644 --- a/docs/api/plugins/events/process-template-context/index.html +++ b/docs/api/plugins/events/process-template-context/index.html @@ -223,7 +223,7 @@ unless they are explicitly passed to it. 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. -Example
def on_process_template_context(self, context, **extra): +Example
diff --git a/docs/api/plugins/events/server-spawn/index.html b/docs/api/plugins/events/server-spawn/index.html index 24c5ddc2..4d7bbc99 100644 --- a/docs/api/plugins/events/server-spawn/index.html +++ b/docs/api/plugins/events/server-spawn/index.html @@ -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 server-stop which can be used to detect server shutdowns. -def on_process_template_context(self, context, **extra): context['my_variable'] = 'my value'Example
import os -from subprocess import Popen +Example
diff --git a/docs/api/plugins/events/setup-env/index.html b/docs/api/plugins/events/setup-env/index.html index a1ea6a29..7147dbba 100644 --- a/docs/api/plugins/events/setup-env/index.html +++ b/docs/api/plugins/events/setup-env/index.html @@ -213,7 +213,7 @@ with the environment. This can be used to reconfigure it. For instance this is the perfect place to inject Jinja 2 filters and global variables. -import os +from subprocess import Popen -class MyPlugin(Plugin): +class MyPlugin(Plugin): ... webpack = None - def on_server_spawn(self, **extra): + def on_server_spawn(self, **extra): path = os.path.join(self.env.root_path, 'webpack') self.webpack = Popen(['webpack', '--watch'], cwd=path) - def on_server_stop(self, **extra): + def on_server_stop(self, **extra): if self.webpack is not None: self.webpack.kill()Example
def on_setup_env(self, **extra): +Example
diff --git a/docs/api/plugins/get-plugin/index.html b/docs/api/plugins/get-plugin/index.html index 22bf671a..802a65b4 100644 --- a/docs/api/plugins/get-plugin/index.html +++ b/docs/api/plugins/get-plugin/index.html @@ -169,7 +169,7 @@ or plugin class. This is particularly useful to retrieve state from a plugin. If thedef on_setup_env(self, **extra): self.env.jinja_env.globals['my_variable'] = 'my value'env
is not given a context needs to be active and the env of the context is used. -Example
from lektor.pluginsystem import get_plugin +Example
from lektor.pluginsystem import get_plugin plugin = get_plugin('the-plugin-id') cfg = plugin.get_config() diff --git a/docs/api/plugins/plugin/config-filename/index.html b/docs/api/plugins/plugin/config-filename/index.html index a6b66873..5eb6b893 100644 --- a/docs/api/plugins/plugin/config-filename/index.html +++ b/docs/api/plugins/plugin/config-filename/index.html @@ -191,19 +191,19 @@ plugin in the loaded project. This is by default inconfigs/<plugin-id Plugins could override this in theory but it's not recommended. The primary use of this property is to track dependencies.
For a convenient way to load the config see get_config.
-Example
from lektor.pluginsystem import Plugin -from lektor.context import get_ctx +Example
from lektor.pluginsystem import Plugin +from lektor.context import get_ctx -class MyPlugin(Plugin): +class MyPlugin(Plugin): - def on_setup_env(self, **extra): + def on_setup_env(self, **extra): color = self.get_config().get('color') - def get_css(artifact_name='/static/demo.css'): + def get_css(artifact_name='/static/demo.css'): ctx = get_ctx() @ctx.sub_artifact(artifact_name, sources=[ self.config_filename]) - def build_stylesheet(artifact): + def build_stylesheet(artifact): with artifact.open('w') as f: f.write('body { background: %s }\n' % color) return artifact_name diff --git a/docs/api/plugins/plugin/description/index.html b/docs/api/plugins/plugin/description/index.html index 1ec9dfbc..16f3fa6d 100644 --- a/docs/api/plugins/plugin/description/index.html +++ b/docs/api/plugins/plugin/description/index.html @@ -188,10 +188,10 @@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.
-Example
from lektor.pluginsystem import Plugin +Example
diff --git a/docs/api/plugins/plugin/emit/index.html b/docs/api/plugins/plugin/emit/index.html index 96b91bdf..b208890a 100644 --- a/docs/api/plugins/plugin/emit/index.html +++ b/docs/api/plugins/plugin/emit/index.html @@ -189,21 +189,21 @@from lektor.pluginsystem import Plugin -class MyPlugin(Plugin): +class MyPlugin(Plugin): name = 'My Plugin' description = 'This is a small plugin I wrote for testing purposes'This method can be used to emit an event that other plugins can hook. The event name is prefixed with the plugin ID.
-Example
from lektor.pluginsystem import Plugin +Example
from lektor.pluginsystem import Plugin -class MyPlugin(Plugin): +class MyPlugin(Plugin): - def on_setup_env(self, **extra): + def on_setup_env(self, **extra): self.emit('setup', foo=42)Another plugin can then hook this:
-from lektor.pluginsystem import Plugin +from lektor.pluginsystem import Plugin -class MyPlugin(Plugin): +class MyPlugin(Plugin): - def on_my_plugin_setup(self, foo, **extra): + def on_my_plugin_setup(self, foo, **extra): print('got %s' % foo)(This assumes the plugin id is set to
diff --git a/docs/api/plugins/plugin/get-config/index.html b/docs/api/plugins/plugin/get-config/index.html index 5cd0416f..50d9a45b 100644 --- a/docs/api/plugins/plugin/get-config/index.html +++ b/docs/api/plugins/plugin/get-config/index.html @@ -190,12 +190,12 @@my-plugin
insetup.py
)This loads the config of the plugin as an Ini File.
Dotted paths are used to navigate into sections. So
-get('foo.bar')
would navigate to thebar
key in the[foo]
section.Example
from lektor.pluginsystem import Plugin +Example
diff --git a/docs/api/plugins/plugin/name/index.html b/docs/api/plugins/plugin/name/index.html index a7e2ddbf..6feb7bf1 100644 --- a/docs/api/plugins/plugin/name/index.html +++ b/docs/api/plugins/plugin/name/index.html @@ -188,10 +188,10 @@from lektor.pluginsystem import Plugin -class MyPlugin(Plugin): +class MyPlugin(Plugin): - def on_setup_env(self, **extra): + def on_setup_env(self, **extra): color = self.get_config().get('color') self.env.jinja_env.globals['my_color'] = colorThis 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.
-Example
from lektor.pluginsystem import Plugin +Example
diff --git a/docs/api/project/discover/index.html b/docs/api/project/discover/index.html index 3a8e712f..fef22428 100644 --- a/docs/api/project/discover/index.html +++ b/docs/api/project/discover/index.html @@ -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 thenfrom lektor.pluginsystem import Plugin -class MyPlugin(Plugin): +class MyPlugin(Plugin): name = 'My Plugin'None
is returned. -Example
from lektor.project import Project +Example
diff --git a/docs/api/project/from-file/index.html b/docs/api/project/from-file/index.html index f1d65d0c..c361cbbd 100644 --- a/docs/api/project/from-file/index.html +++ b/docs/api/project/from-file/index.html @@ -170,7 +170,7 @@from lektor.project import Project project = Project.discover()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
-None
is returned.Example
from lektor.project import Project +Example
diff --git a/docs/api/project/make-env/index.html b/docs/api/project/make-env/index.html index 655f4ba8..68626054 100644 --- a/docs/api/project/make-env/index.html +++ b/docs/api/project/make-env/index.html @@ -172,7 +172,7 @@ preferred way to construct such a thing.from lektor.project import Project project = Project.from_file('/path/to/the/project.lektorproject')By default plugins will be loaded and initialized but this can be disabled by passing
-load_plugins=False
.Example
from lektor.project import Project +Example
from lektor.project import Project project = Project.discover() env = project.make_env() diff --git a/docs/api/publisher/fail/index.html b/docs/api/publisher/fail/index.html index 38bdc8c6..1f6e849a 100644 --- a/docs/api/publisher/fail/index.html +++ b/docs/api/publisher/fail/index.html @@ -174,16 +174,16 @@This method takes a message and raises an appropriate failure that aborts the publishing process. This is invoked from within the publish method to indicate a failure:
-Example
from lektor.publisher import Publisher +Example
diff --git a/docs/api/publisher/publish/index.html b/docs/api/publisher/publish/index.html index f8359310..59514290 100644 --- a/docs/api/publisher/publish/index.html +++ b/docs/api/publisher/publish/index.html @@ -192,14 +192,14 @@ keyword arguments. the output in the console or in the deploy/publish window in the admin UI.from lektor.publisher import Publisher -class MyPublisher(Publisher): - def publish(self, target_url, credentials=None, **extra): +class MyPublisher(Publisher): + def publish(self, target_url, credentials=None, **extra): self.fail('This publisher cannot publish :(') -class MyPlugin(Plugin): - def on_setup_env(self, **extra): +class MyPlugin(Plugin): + def on_setup_env(self, **extra): self.env.add_publisher('my', MyPublisher)Example
This example implements a simple publisher that just copies all built files into a new location.
-import os -import shutil -from lektor.publisher import Publisher +import os +import shutil +from lektor.publisher import Publisher -class CopyPublisher(Publisher): +class CopyPublisher(Publisher): - def publish(self, target_url, credentials=None, **extra): + def publish(self, target_url, credentials=None, **extra): src_path = self.output_path dst_path = target_url.path strip = len(src_path) + 1 @@ -226,8 +226,8 @@ into a new location. yield 'Done' -class MyPlugin(Plugin): - def on_setup_env(self, **extra): +class MyPlugin(Plugin): + def on_setup_env(self, **extra): self.env.add_publisher('copy', CopyPublisher)This publisher registers with the
diff --git a/docs/api/utils/build-url/index.html b/docs/api/utils/build-url/index.html index 4cdb0207..05fd472f 100644 --- a/docs/api/utils/build-url/index.html +++ b/docs/api/utils/build-url/index.html @@ -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 passcopy
scheme and could be used like this:True
to enforce a trailing slash orFalse
to avoid it. -Example
>>> from lektor.utils import build_url +Example
>>> from lektor.utils import build_url >>> build_url(['foo', 42]) u'/foo/42/' >>> build_url(['foo', None, 23]) diff --git a/docs/api/utils/get-structure-hash/index.html b/docs/api/utils/get-structure-hash/index.html index 3ebd1a3c..fe20177a 100644 --- a/docs/api/utils/get-structure-hash/index.html +++ b/docs/api/utils/get-structure-hash/index.html @@ -177,7 +177,7 @@Given a Python object (typically a dictionary or tuple) it generates a stable MD5 hash from those recursively. This is useful for the
-config_hash
parameter with artifacts.Example
>>> from lektor.utils import get_structure_hash +Example
>>> from lektor.utils import get_structure_hash >>> get_structure_hash([1, 2, 3]) 'fbcf00cb8f6fc7631af7fbff70ca6f87' >>> get_structure_hash([1, 2, 3, 4]) diff --git a/docs/api/utils/join-path/index.html b/docs/api/utils/join-path/index.html index 969622d5..2de567d5 100644 --- a/docs/api/utils/join-path/index.html +++ b/docs/api/utils/join-path/index.html @@ -179,7 +179,7 @@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.
-Example
>>> from lektor.utils import join_path +Example
>>> from lektor.utils import join_path >>> join_path('/blog', 'hello-world') '/blog/hello-world' >>> join_path('/blog', '@archive') diff --git a/docs/api/utils/parse-path/index.html b/docs/api/utils/parse-path/index.html index 5f3211e1..68379322 100644 --- a/docs/api/utils/parse-path/index.html +++ b/docs/api/utils/parse-path/index.html @@ -179,7 +179,7 @@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.
-Example
>>> from lektor.utils import parse_path +Example
>>> from lektor.utils import parse_path >>> parse_path('/foo/bar') ['foo', 'bar'] >>> parse_path('/') diff --git a/docs/api/utils/process-image/index.html b/docs/api/utils/process-image/index.html index 0aaaee2b..8f2e5072 100644 --- a/docs/api/utils/process-image/index.html +++ b/docs/api/utils/process-image/index.html @@ -182,15 +182,15 @@ width and/or height, and the operation mode. In the default mode, if width or height areNone
, they are calculated from the source image's dimensions so that the image is scaled proportionally.Used internally for the implementation of thumbnail, and exposed as an API for image-processing plugins.
-Example
from lektor.build_programs import AttachmentBuildProgram -from lektor.context import get_ctx -from lektor.db import Image -from lektor.imagetools import process_image, ThumbnailMode -from lektor.pluginsystem import Plugin +Example
diff --git a/docs/plugins/dev/index.html b/docs/plugins/dev/index.html index db3e3e57..c6417d84 100644 --- a/docs/plugins/dev/index.html +++ b/docs/plugins/dev/index.html @@ -169,7 +169,7 @@ package in the packages folder.from lektor.build_programs import AttachmentBuildProgram +from lektor.context import get_ctx +from lektor.db import Image +from lektor.imagetools import process_image, ThumbnailMode +from lektor.pluginsystem import Plugin -class ImageCropBuildProgram(AttachmentBuildProgram): - def build_artifact(self, artifact): +class ImageCropBuildProgram(AttachmentBuildProgram): + def build_artifact(self, artifact): ctx = get_ctx() width, height = 600, 400 source_img = artifact.source_obj.attachment_filename @@ -202,8 +202,8 @@ from the source image's dimensions so that the image is scaled proportionally. width, height, mode=ThumbnailMode.CROP) -class ImageCropPlugin(Plugin): - def on_setup_env(self, **extra): +class ImageCropPlugin(Plugin): + def on_setup_env(self, **extra): self.env.add_build_program(Image, ImageCropBuildProgram)Once that is done, we need to create a
-setup.py
file which tells Lektor what your plugin needs to run. This will already be created for you if you used the wizard.from setuptools import setup +from setuptools import setup setup( name='lektor-hello-world', @@ -213,9 +213,9 @@ example.Creating The Plugin
Now it's time to create our first plugin that does absolutely nothing. We create a new file with the name
-lektor_hello_world.py
next to oursetup.py
and put the following things in:from lektor.pluginsystem import Plugin +@@ -232,7 +232,7 @@ hello-world: Hello World events that can be hooked but we will only cover a very basic one here, thefrom lektor.pluginsystem import Plugin -class HelloWorldPlugin(Plugin): +class HelloWorldPlugin(Plugin): name = 'Hello World' description = 'This is a demo plugin for testing purposes.'setup-env
event. To respond to it, we need to implement a function namedon_setup_env
: -import random +import random MESSAGES = [ 'Reticulating splines', @@ -240,14 +240,14 @@ a function namedon_setup_env
: 'Possessing pawns', ] -def get_random_message(): +def get_random_message(): return random.choice(MESSAGES) -class HelloWorldPlugin(Plugin): +class HelloWorldPlugin(Plugin): name = 'Hello World' description = 'This is a demo plugin for testing purposes.' - def on_setup_env(self, **extra): + def on_setup_env(self, **extra): self.env.jinja_env.globals.update( get_random_message=get_random_message ) diff --git a/docs/plugins/howto/index.html b/docs/plugins/howto/index.html index 907e332f..fefae7f7 100644 --- a/docs/plugins/howto/index.html +++ b/docs/plugins/howto/index.html @@ -161,19 +161,19 @@ plugins and Lektor itself modify so do not provide a function calledget_script
but for instance call itget_my_plugin_script
.A simple example of a plugin that implements Gravatar support:
-from hashlib import md5 -from werkzeug.urls import url_encode -from lektor.pluginsystem import Plugin +from hashlib import md5 +from werkzeug.urls import url_encode +from lektor.pluginsystem import Plugin BASE_URL = 'https://secure.gravatar.com/avatar/' -def get_gravatar(email, **options): +def get_gravatar(email, **options): fn = md5(email.lower().strip().encode('utf-8')).hexdigest() return '%s/%s?%s' % (BASE_URL, fn, url_encode(options)) -class GravatarPlugin(Plugin): +class GravatarPlugin(Plugin): name = 'Gravatar' - def on_setup_env(self, **extra): + def on_setup_env(self, **extra): self.env.jinja_env.filters['gravatar'] = get_gravatarConfigure Plugins