Added publisher docs
This commit is contained in:
parent
46c71b7b19
commit
325eb1fe7e
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,26 @@
|
||||||
|
title: add_publisher
|
||||||
|
---
|
||||||
|
type: method
|
||||||
|
---
|
||||||
|
signature: scheme, publisher
|
||||||
|
---
|
||||||
|
summary: Registers a publisher class with the environment.
|
||||||
|
---
|
||||||
|
body:
|
||||||
|
|
||||||
|
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 :ref](../../publisher/).
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from lektor.publisher import Publisher
|
||||||
|
|
||||||
|
class MyPublisher(Publisher):
|
||||||
|
pass
|
||||||
|
|
||||||
|
env.add_publisher('my', MyPublisher)
|
||||||
|
```
|
||||||
|
---
|
||||||
|
version_added: 2.0
|
|
@ -0,0 +1,23 @@
|
||||||
|
title: Publisher
|
||||||
|
---
|
||||||
|
module: lektor.publisher
|
||||||
|
---
|
||||||
|
summary: The interface for extending the deployment process
|
||||||
|
---
|
||||||
|
type: class
|
||||||
|
---
|
||||||
|
body:
|
||||||
|
|
||||||
|
This class can be subclassed to implement custom deployment methods.
|
||||||
|
Internally these are called “publishers” and to register them with the
|
||||||
|
environment the [add_publisher :ref](../environment/add-publisher/) method can
|
||||||
|
be used.
|
||||||
|
|
||||||
|
Publishers have one method called [publish :ref](publish/) which is used to
|
||||||
|
trigger the actual deployment process. It also has a reference back to the
|
||||||
|
environment it belongs to as well as the output path of the build process.
|
||||||
|
|
||||||
|
For a minimal example of a publisher refer to the documentation of the
|
||||||
|
[publish :ref](publish/) method.
|
||||||
|
---
|
||||||
|
version_added: 2.0
|
|
@ -0,0 +1,12 @@
|
||||||
|
title: env
|
||||||
|
---
|
||||||
|
summary: Reference to the creating environment
|
||||||
|
---
|
||||||
|
type: property
|
||||||
|
---
|
||||||
|
version_added: 2.0
|
||||||
|
---
|
||||||
|
body:
|
||||||
|
|
||||||
|
As each publisher is bound to an [Environment :ref](../../environment/) that
|
||||||
|
created it. This is useful to discover related information.
|
|
@ -0,0 +1,31 @@
|
||||||
|
title: fail
|
||||||
|
---
|
||||||
|
summary: Notifies a failure during publishing
|
||||||
|
---
|
||||||
|
signature: message
|
||||||
|
---
|
||||||
|
type: method
|
||||||
|
---
|
||||||
|
version_added: 2.0
|
||||||
|
---
|
||||||
|
body:
|
||||||
|
|
||||||
|
This method takes a message and raises an appropriate failure that aborts
|
||||||
|
the publishing process. This is invoked from within the [publish
|
||||||
|
:ref](../publish/) method to indicate a failure:
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```python
|
||||||
|
from lektor.publisher import Publisher
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
self.env.add_publisher('my', MyPublisher)
|
||||||
|
```
|
|
@ -0,0 +1,15 @@
|
||||||
|
title: output_path
|
||||||
|
---
|
||||||
|
type: property
|
||||||
|
---
|
||||||
|
summary: The path to the folder with the build artifacts
|
||||||
|
---
|
||||||
|
version_added: 2.0
|
||||||
|
---
|
||||||
|
body:
|
||||||
|
|
||||||
|
This attribute holds the path to the folder where the build process put the
|
||||||
|
final artifacts. Usually a publisher walks that folder and does something
|
||||||
|
with all contents of it. The publishers however are heavily encourated to
|
||||||
|
ignore the special `.lektor` folder which contains lektor specific information
|
||||||
|
that should not end up on the resulting server.
|
|
@ -0,0 +1,79 @@
|
||||||
|
title: publish
|
||||||
|
---
|
||||||
|
signature: target_url, credentials=None, **extra
|
||||||
|
---
|
||||||
|
summary: The method that triggers the deployment
|
||||||
|
---
|
||||||
|
type: method
|
||||||
|
---
|
||||||
|
version_added: 2.0
|
||||||
|
---
|
||||||
|
body:
|
||||||
|
|
||||||
|
This method implements the actual publishing process. It's supposed to
|
||||||
|
implement a generator that reports the progress of the publishing. If at any
|
||||||
|
point something happens that would cause an error for the deployment this can
|
||||||
|
be signalled with the [fail :ref](../fail/) method which aborts the execution
|
||||||
|
and reports an error.
|
||||||
|
|
||||||
|
The parameters to the function are as follows:
|
||||||
|
|
||||||
|
* `target_url`: a URL object with the parsed URL. This object comes from the
|
||||||
|
Werkzeug library and gives access to the individual parts of a URL by the
|
||||||
|
exposed attributes ([Read about the URL object :ext](http://werkzeug.pocoo.org/docs/0.11/urls/)).
|
||||||
|
* `credentials`: an optional dictionary with command line supplied credentials.
|
||||||
|
Note that these credentials might be completely absent and the keys which are
|
||||||
|
provided might change with future versions of Lektor.
|
||||||
|
* `**extra`: for forwards compatibility publishers are required to ignore extra
|
||||||
|
keyword arguments.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
This example implements a simple publisher that just copies all built files
|
||||||
|
into a new location.
|
||||||
|
|
||||||
|
```python
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
from lektor.publisher import Publisher
|
||||||
|
|
||||||
|
|
||||||
|
class CopyPublisher(Publisher):
|
||||||
|
|
||||||
|
def publish(self, target_url, credentials=None, **extra):
|
||||||
|
src_path = self.output_path
|
||||||
|
dst_path = target_url.path
|
||||||
|
strip = len(src_path) + 1
|
||||||
|
|
||||||
|
for path, folders, filenames in os.walk(src_path):
|
||||||
|
# Ignore the .lektor folder.
|
||||||
|
folders[:] = [x for x in folders if x != '.lektor']
|
||||||
|
|
||||||
|
# Copy all files over
|
||||||
|
for filename in filenames:
|
||||||
|
full_path = os.path.join(src_path, path, filename)
|
||||||
|
dst = os.path.join(path, full_path[strip:])
|
||||||
|
|
||||||
|
# Make sure the destination folder exists.
|
||||||
|
try:
|
||||||
|
os.makedirs(os.path.dirname(dst))
|
||||||
|
except (OSError, IOError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Copy the file
|
||||||
|
yield 'Copy %s' % filename
|
||||||
|
shutil.copy(full_path, dst)
|
||||||
|
|
||||||
|
yield 'Done'
|
||||||
|
|
||||||
|
|
||||||
|
class MyPlugin(Plugin):
|
||||||
|
def on_setup_env(self, **extra):
|
||||||
|
self.env.add_publisher('copy', CopyPublisher)
|
||||||
|
```
|
||||||
|
|
||||||
|
This publisher registers with the `copy` scheme and could be used like this:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
target_url = copy:///path/to/destination/folder
|
||||||
|
```
|
|
@ -57,3 +57,7 @@ description = An optional signature for a type.
|
||||||
label = Template Variable
|
label = Template Variable
|
||||||
type = string
|
type = string
|
||||||
description = An optional template variable if it exists there as such.
|
description = An optional template variable if it exists there as such.
|
||||||
|
|
||||||
|
[fields.version_added]
|
||||||
|
label = Added in version
|
||||||
|
type = string
|
||||||
|
|
|
@ -33,21 +33,35 @@
|
||||||
<div class="col-sm-9 doc-styling">
|
<div class="col-sm-9 doc-styling">
|
||||||
{{ get_doc_header(this) }}
|
{{ get_doc_header(this) }}
|
||||||
|
|
||||||
|
<ul class=page-meta>
|
||||||
{% if this.type == 'method' %}
|
{% if this.type == 'method' %}
|
||||||
<p class="type-info">Method of {{ get_doc_link(this.parent) }}
|
<li>Method of {{ get_doc_link(this.parent) }}
|
||||||
{% elif this.type == 'property' %}
|
{% elif this.type == 'property' %}
|
||||||
<p class="type-info">Property of {{ get_doc_link(this.parent) }}
|
<li>Property of {{ get_doc_link(this.parent) }}
|
||||||
{% elif this.type == 'operator' %}
|
{% elif this.type == 'operator' %}
|
||||||
<p class="type-info">Operator of {{ get_doc_link(this.parent) }}
|
<li>Operator of {{ get_doc_link(this.parent) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if this.template_var %}
|
{% if this.template_var %}
|
||||||
<p class="type-info">Template variable: <a href="{{ (
|
<li>Template variable: <a href="{{ (
|
||||||
'/docs/api/templates/globals/' ~ this.template_var|lower ~ '/')|url
|
'/docs/api/templates/globals/' ~ this.template_var|lower ~ '/')|url
|
||||||
}}"><code>{{ this.template_var }}</code></a>
|
}}"><code>{{ this.template_var }}</code></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if this.version_added %}
|
||||||
|
<li>New in Lektor Version <em>{{ this.version_added }}</em>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
{{ this.body }}
|
{{ this.body }}
|
||||||
|
|
||||||
|
{% if this.version_history %}
|
||||||
|
<div class="version-info version-info-collapsed">
|
||||||
|
<h2>Version Info</h2>
|
||||||
|
<div class="contents">
|
||||||
|
{{ this.version_history }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if this.children %}
|
{% if this.children %}
|
||||||
<div class="child-pages">
|
<div class="child-pages">
|
||||||
{% for cols in this.children|batch(2) %}
|
{% for cols in this.children|batch(2) %}
|
||||||
|
|
|
@ -291,11 +291,24 @@ div.doc-styling {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p.type-info {
|
ul.page-meta {
|
||||||
|
list-style: none;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0 0 0 30px;
|
||||||
|
line-height: 1.4;
|
||||||
|
|
||||||
|
> li {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
&:last-child {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
em {
|
||||||
|
background: #eee;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
p.type-info + p.type-info {
|
|
||||||
margin-top: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
table {
|
table {
|
||||||
|
|
Loading…
Reference in New Issue