aboutsummaryrefslogtreecommitdiffstats
path: root/nikola/plugins/compile
diff options
context:
space:
mode:
authorLibravatarAgustin Henze <tin@sluc.org.ar>2015-08-26 07:57:23 -0300
committerLibravatarAgustin Henze <tin@sluc.org.ar>2015-08-26 07:57:23 -0300
commit70ceb871117ca811d63cb02671dc0fefc2700883 (patch)
tree846133ea39797d2cd1101cff2ac0818167353490 /nikola/plugins/compile
parent8559119e2f45b7f6508282962c0430423bfab051 (diff)
parent787b97a4cb24330b36f11297c6d3a7a473a907d0 (diff)
Merge tag 'upstream/7.6.4'
Upstream version 7.6.4
Diffstat (limited to 'nikola/plugins/compile')
-rw-r--r--nikola/plugins/compile/__init__.py2
-rw-r--r--nikola/plugins/compile/html.plugin15
-rw-r--r--nikola/plugins/compile/html.py4
-rw-r--r--nikola/plugins/compile/ipynb.plugin15
-rw-r--r--nikola/plugins/compile/ipynb.py26
-rw-r--r--nikola/plugins/compile/markdown.plugin15
-rw-r--r--nikola/plugins/compile/markdown/__init__.py13
-rw-r--r--nikola/plugins/compile/markdown/mdx_gist.plugin17
-rw-r--r--nikola/plugins/compile/markdown/mdx_gist.py68
-rw-r--r--nikola/plugins/compile/markdown/mdx_nikola.plugin17
-rw-r--r--nikola/plugins/compile/markdown/mdx_nikola.py14
-rw-r--r--nikola/plugins/compile/markdown/mdx_podcast.plugin17
-rw-r--r--nikola/plugins/compile/markdown/mdx_podcast.py27
-rw-r--r--nikola/plugins/compile/pandoc.plugin15
-rw-r--r--nikola/plugins/compile/pandoc.py5
-rw-r--r--nikola/plugins/compile/php.plugin15
-rw-r--r--nikola/plugins/compile/php.py4
-rw-r--r--nikola/plugins/compile/rest.plugin15
-rw-r--r--nikola/plugins/compile/rest/__init__.py40
-rw-r--r--nikola/plugins/compile/rest/chart.plugin16
-rw-r--r--nikola/plugins/compile/rest/chart.py25
-rw-r--r--nikola/plugins/compile/rest/doc.plugin16
-rw-r--r--nikola/plugins/compile/rest/doc.py7
-rw-r--r--nikola/plugins/compile/rest/gist.plugin16
-rw-r--r--nikola/plugins/compile/rest/gist.py19
-rw-r--r--nikola/plugins/compile/rest/listing.plugin16
-rw-r--r--nikola/plugins/compile/rest/listing.py17
-rw-r--r--nikola/plugins/compile/rest/media.plugin16
-rw-r--r--nikola/plugins/compile/rest/media.py9
-rw-r--r--nikola/plugins/compile/rest/post_list.plugin17
-rw-r--r--nikola/plugins/compile/rest/post_list.py26
-rw-r--r--nikola/plugins/compile/rest/slides.plugin16
-rw-r--r--nikola/plugins/compile/rest/slides.py12
-rw-r--r--nikola/plugins/compile/rest/soundcloud.plugin16
-rw-r--r--nikola/plugins/compile/rest/soundcloud.py17
-rw-r--r--nikola/plugins/compile/rest/thumbnail.plugin17
-rw-r--r--nikola/plugins/compile/rest/thumbnail.py10
-rw-r--r--nikola/plugins/compile/rest/vimeo.plugin10
-rw-r--r--nikola/plugins/compile/rest/vimeo.py20
-rw-r--r--nikola/plugins/compile/rest/youtube.plugin12
-rw-r--r--nikola/plugins/compile/rest/youtube.py13
41 files changed, 459 insertions, 228 deletions
diff --git a/nikola/plugins/compile/__init__.py b/nikola/plugins/compile/__init__.py
index a1d17a6..60f1919 100644
--- a/nikola/plugins/compile/__init__.py
+++ b/nikola/plugins/compile/__init__.py
@@ -23,3 +23,5 @@
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+"""Compilers for Nikola."""
diff --git a/nikola/plugins/compile/html.plugin b/nikola/plugins/compile/html.plugin
index 66623b2..53ade61 100644
--- a/nikola/plugins/compile/html.plugin
+++ b/nikola/plugins/compile/html.plugin
@@ -1,10 +1,13 @@
[Core]
-Name = html
-Module = html
+name = html
+module = html
[Documentation]
-Author = Roberto Alsina
-Version = 1.0
-Website = http://getnikola.com
-Description = Compile HTML into HTML (just copy)
+author = Roberto Alsina
+version = 1.0
+website = http://getnikola.com
+description = Compile HTML into HTML (just copy)
+[Nikola]
+plugincategory = Compiler
+friendlyname = HTML
diff --git a/nikola/plugins/compile/html.py b/nikola/plugins/compile/html.py
index ab0c2f6..5f8b244 100644
--- a/nikola/plugins/compile/html.py
+++ b/nikola/plugins/compile/html.py
@@ -36,11 +36,14 @@ from nikola.utils import makedirs, write_metadata
class CompileHtml(PageCompiler):
+
"""Compile HTML into HTML."""
+
name = "html"
friendly_name = "HTML"
def compile_html(self, source, dest, is_two_file=True):
+ """Compile source file into HTML and save as dest."""
makedirs(os.path.dirname(dest))
with io.open(dest, "w+", encoding="utf8") as out_file:
with io.open(source, "r", encoding="utf8") as in_file:
@@ -51,6 +54,7 @@ class CompileHtml(PageCompiler):
return True
def create_post(self, path, **kw):
+ """Create a new post."""
content = kw.pop('content', None)
onefile = kw.pop('onefile', False)
# is_page is not used by create_post as of now.
diff --git a/nikola/plugins/compile/ipynb.plugin b/nikola/plugins/compile/ipynb.plugin
index efe6702..c369ab2 100644
--- a/nikola/plugins/compile/ipynb.plugin
+++ b/nikola/plugins/compile/ipynb.plugin
@@ -1,10 +1,13 @@
[Core]
-Name = ipynb
-Module = ipynb
+name = ipynb
+module = ipynb
[Documentation]
-Author = Damian Avila, Chris Warrick and others
-Version = 2.0.0
-Website = http://www.damian.oquanta.info/
-Description = Compile IPython notebooks into Nikola posts
+author = Damian Avila, Chris Warrick and others
+version = 2.0.0
+website = http://www.damian.oquanta.info/
+description = Compile IPython notebooks into Nikola posts
+[Nikola]
+plugincategory = Compiler
+friendlyname = Jupyter/IPython Notebook
diff --git a/nikola/plugins/compile/ipynb.py b/nikola/plugins/compile/ipynb.py
index 82b76c8..a9dedde 100644
--- a/nikola/plugins/compile/ipynb.py
+++ b/nikola/plugins/compile/ipynb.py
@@ -49,10 +49,11 @@ except ImportError:
flag = None
from nikola.plugin_categories import PageCompiler
-from nikola.utils import makedirs, req_missing, get_logger
+from nikola.utils import makedirs, req_missing, get_logger, STDERR_HANDLER
class CompileIPynb(PageCompiler):
+
"""Compile IPynb into HTML."""
name = "ipynb"
@@ -61,24 +62,30 @@ class CompileIPynb(PageCompiler):
default_kernel = 'python2' if sys.version_info[0] == 2 else 'python3'
def set_site(self, site):
- self.logger = get_logger('compile_ipynb', site.loghandlers)
+ """Set Nikola site."""
+ self.logger = get_logger('compile_ipynb', STDERR_HANDLER)
super(CompileIPynb, self).set_site(site)
- def compile_html(self, source, dest, is_two_file=True):
+ def compile_html_string(self, source, is_two_file=True):
+ """Export notebooks as HTML strings."""
if flag is None:
req_missing(['ipython[notebook]>=2.0.0'], 'build this site (compile ipynb)')
- makedirs(os.path.dirname(dest))
HTMLExporter.default_template = 'basic'
c = Config(self.site.config['IPYNB_CONFIG'])
exportHtml = HTMLExporter(config=c)
+ with io.open(source, "r", encoding="utf8") as in_file:
+ nb_json = nbformat.read(in_file, current_nbformat)
+ (body, resources) = exportHtml.from_notebook_node(nb_json)
+ return body
+
+ def compile_html(self, source, dest, is_two_file=True):
+ """Compile source file into HTML and save as dest."""
+ makedirs(os.path.dirname(dest))
with io.open(dest, "w+", encoding="utf8") as out_file:
- with io.open(source, "r", encoding="utf8") as in_file:
- nb_json = nbformat.read(in_file, current_nbformat)
- (body, resources) = exportHtml.from_notebook_node(nb_json)
- out_file.write(body)
+ out_file.write(self.compile_html_string(source, is_two_file))
def read_metadata(self, post, file_metadata_regexp=None, unslugify_titles=False, lang=None):
- """read metadata directly from ipynb file.
+ """Read metadata directly from ipynb file.
As ipynb file support arbitrary metadata as json, the metadata used by Nikola
will be assume to be in the 'nikola' subfield.
@@ -93,6 +100,7 @@ class CompileIPynb(PageCompiler):
return nb_json.get('metadata', {}).get('nikola', {})
def create_post(self, path, **kw):
+ """Create a new post."""
if flag is None:
req_missing(['ipython[notebook]>=2.0.0'], 'build this site (compile ipynb)')
content = kw.pop('content', None)
diff --git a/nikola/plugins/compile/markdown.plugin b/nikola/plugins/compile/markdown.plugin
index a44b798..f7d11b1 100644
--- a/nikola/plugins/compile/markdown.plugin
+++ b/nikola/plugins/compile/markdown.plugin
@@ -1,10 +1,13 @@
[Core]
-Name = markdown
-Module = markdown
+name = markdown
+module = markdown
[Documentation]
-Author = Roberto Alsina
-Version = 1.0
-Website = http://getnikola.com
-Description = Compile Markdown into HTML
+author = Roberto Alsina
+version = 1.0
+website = http://getnikola.com
+description = Compile Markdown into HTML
+[Nikola]
+plugincategory = Compiler
+friendlyname = Markdown
diff --git a/nikola/plugins/compile/markdown/__init__.py b/nikola/plugins/compile/markdown/__init__.py
index fbe049d..c1425a1 100644
--- a/nikola/plugins/compile/markdown/__init__.py
+++ b/nikola/plugins/compile/markdown/__init__.py
@@ -44,6 +44,7 @@ from nikola.utils import makedirs, req_missing, write_metadata
class CompileMarkdown(PageCompiler):
+
"""Compile Markdown into HTML."""
name = "markdown"
@@ -53,21 +54,18 @@ class CompileMarkdown(PageCompiler):
site = None
def set_site(self, site):
+ """Set Nikola site."""
+ super(CompileMarkdown, self).set_site(site)
self.config_dependencies = []
- for plugin_info in site.plugin_manager.getPluginsOfCategory("MarkdownExtension"):
- if plugin_info.name in site.config['DISABLED_PLUGINS']:
- site.plugin_manager.removePluginFromCategory(plugin_info, "MarkdownExtension")
- continue
+ for plugin_info in self.get_compiler_extensions():
self.config_dependencies.append(plugin_info.name)
- site.plugin_manager.activatePluginByName(plugin_info.name)
- plugin_info.plugin_object.set_site(site)
self.extensions.append(plugin_info.plugin_object)
plugin_info.plugin_object.short_help = plugin_info.description
self.config_dependencies.append(str(sorted(site.config.get("MARKDOWN_EXTENSIONS"))))
- return super(CompileMarkdown, self).set_site(site)
def compile_html(self, source, dest, is_two_file=True):
+ """Compile source file into HTML and save as dest."""
if markdown is None:
req_missing(['markdown'], 'build this site (compile Markdown)')
makedirs(os.path.dirname(dest))
@@ -81,6 +79,7 @@ class CompileMarkdown(PageCompiler):
out_file.write(output)
def create_post(self, path, **kw):
+ """Create a new post."""
content = kw.pop('content', None)
onefile = kw.pop('onefile', False)
# is_page is not used by create_post as of now.
diff --git a/nikola/plugins/compile/markdown/mdx_gist.plugin b/nikola/plugins/compile/markdown/mdx_gist.plugin
index 0e5c578..7fe676c 100644
--- a/nikola/plugins/compile/markdown/mdx_gist.plugin
+++ b/nikola/plugins/compile/markdown/mdx_gist.plugin
@@ -1,9 +1,14 @@
[Core]
-Name = mdx_gist
-Module = mdx_gist
+name = mdx_gist
+module = mdx_gist
+
+[Nikola]
+compiler = markdown
+plugincategory = CompilerExtension
[Documentation]
-Author = Roberto Alsina
-Version = 0.1
-Website = http://getnikola.com
-Description = Extension for embedding gists
+author = Roberto Alsina
+version = 0.1
+website = http://getnikola.com
+description = Extension for embedding gists
+
diff --git a/nikola/plugins/compile/markdown/mdx_gist.py b/nikola/plugins/compile/markdown/mdx_gist.py
index 70e7394..f439fa2 100644
--- a/nikola/plugins/compile/markdown/mdx_gist.py
+++ b/nikola/plugins/compile/markdown/mdx_gist.py
@@ -26,16 +26,16 @@
#
# Inspired by "[Python] reStructuredText GitHub Gist directive"
# (https://gist.github.com/brianhsu/1407759), public domain by Brian Hsu
-'''
-Extension to Python Markdown for Embedded Gists (gist.github.com)
+"""
+Extension to Python Markdown for Embedded Gists (gist.github.com).
Basic Example:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... [:gist: 4747847]
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
@@ -50,10 +50,10 @@ Basic Example:
Example with filename:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... [:gist: 4747847 zen.py]
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
@@ -68,10 +68,10 @@ Example with filename:
Basic Example with hexidecimal id:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... [:gist: c4a43d6fdce612284ac0]
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
@@ -86,10 +86,10 @@ Basic Example with hexidecimal id:
Example with hexidecimal id filename:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... [:gist: c4a43d6fdce612284ac0 cow.txt]
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
@@ -104,10 +104,10 @@ Example with hexidecimal id filename:
Example using reStructuredText syntax:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... .. gist:: 4747847 zen.py
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
@@ -122,10 +122,10 @@ Example using reStructuredText syntax:
Example using hexidecimal ID with reStructuredText syntax:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... .. gist:: c4a43d6fdce612284ac0
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
@@ -140,10 +140,10 @@ Example using hexidecimal ID with reStructuredText syntax:
Example using hexidecimal ID and filename with reStructuredText syntax:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... .. gist:: c4a43d6fdce612284ac0 cow.txt
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
@@ -158,38 +158,36 @@ Example using hexidecimal ID and filename with reStructuredText syntax:
Error Case: non-existent Gist ID:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... [:gist: 0]
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
<div class="gist">
<script src="https://gist.github.com/0.js"></script>
- <noscript><!-- WARNING: Received a 404 response from Gist URL: \
-https://gist.githubusercontent.com/raw/0 --></noscript>
+ <noscript><!-- WARNING: Received a 404 response from Gist URL: https://gist.githubusercontent.com/raw/0 --></noscript>
</div>
</p>
Error Case: non-existent file:
>>> import markdown
- >>> text = """
+ >>> text = '''
... Text of the gist:
... [:gist: 4747847 doesntexist.py]
- ... """
+ ... '''
>>> html = markdown.markdown(text, [GistExtension()])
>>> print(html)
<p>Text of the gist:
<div class="gist">
<script src="https://gist.github.com/4747847.js?file=doesntexist.py"></script>
- <noscript><!-- WARNING: Received a 404 response from Gist URL: \
-https://gist.githubusercontent.com/raw/4747847/doesntexist.py --></noscript>
+ <noscript><!-- WARNING: Received a 404 response from Gist URL: https://gist.githubusercontent.com/raw/4747847/doesntexist.py --></noscript>
</div>
</p>
+"""
-'''
from __future__ import unicode_literals, print_function
try:
@@ -219,20 +217,26 @@ GIST_RST_RE = r'(?m)^\.\.\s*gist::\s*(?P<gist_id>[^\]\s]+)(?:\s*(?P<filename>.+?
class GistFetchException(Exception):
- '''Raised when attempt to fetch content of a Gist from github.com fails.'''
+
+ """Raised when attempt to fetch content of a Gist from github.com fails."""
+
def __init__(self, url, status_code):
+ """Initialize the exception."""
Exception.__init__(self)
self.message = 'Received a {0} response from Gist URL: {1}'.format(
status_code, url)
class GistPattern(Pattern):
- """ InlinePattern for footnote markers in a document's body text. """
+
+ """InlinePattern for footnote markers in a document's body text."""
def __init__(self, pattern, configs):
+ """Initialize the pattern."""
Pattern.__init__(self, pattern)
def get_raw_gist_with_filename(self, gist_id, filename):
+ """Get raw gist text for a filename."""
url = GIST_FILE_RAW_URL.format(gist_id, filename)
resp = requests.get(url)
@@ -242,6 +246,7 @@ class GistPattern(Pattern):
return resp.text
def get_raw_gist(self, gist_id):
+ """Get raw gist text."""
url = GIST_RAW_URL.format(gist_id)
resp = requests.get(url)
@@ -251,6 +256,7 @@ class GistPattern(Pattern):
return resp.text
def handleMatch(self, m):
+ """Handle pattern match."""
gist_id = m.group('gist_id')
gist_file = m.group('filename')
@@ -284,7 +290,11 @@ class GistPattern(Pattern):
class GistExtension(MarkdownExtension, Extension):
+
+ """Gist extension for Markdown."""
+
def __init__(self, configs={}):
+ """Initialize the extension."""
# set extension defaults
self.config = {}
@@ -293,6 +303,7 @@ class GistExtension(MarkdownExtension, Extension):
self.setConfig(key, value)
def extendMarkdown(self, md, md_globals):
+ """Extend Markdown."""
gist_md_pattern = GistPattern(GIST_MD_RE, self.getConfigs())
gist_md_pattern.md = md
md.inlinePatterns.add('gist', gist_md_pattern, "<not_strong")
@@ -304,7 +315,8 @@ class GistExtension(MarkdownExtension, Extension):
md.registerExtension(self)
-def makeExtension(configs=None):
+def makeExtension(configs=None): # pragma: no cover
+ """Make Markdown extension."""
return GistExtension(configs)
if __name__ == '__main__':
diff --git a/nikola/plugins/compile/markdown/mdx_nikola.plugin b/nikola/plugins/compile/markdown/mdx_nikola.plugin
index 7af52a4..12e4fb6 100644
--- a/nikola/plugins/compile/markdown/mdx_nikola.plugin
+++ b/nikola/plugins/compile/markdown/mdx_nikola.plugin
@@ -1,9 +1,14 @@
[Core]
-Name = mdx_nikola
-Module = mdx_nikola
+name = mdx_nikola
+module = mdx_nikola
+
+[Nikola]
+compiler = markdown
+plugincategory = CompilerExtension
[Documentation]
-Author = Roberto Alsina
-Version = 0.1
-Website = http://getnikola.com
-Description = Nikola-specific Markdown extensions
+author = Roberto Alsina
+version = 0.1
+website = http://getnikola.com
+description = Nikola-specific Markdown extensions
+
diff --git a/nikola/plugins/compile/markdown/mdx_nikola.py b/nikola/plugins/compile/markdown/mdx_nikola.py
index a03547f..54cc18c 100644
--- a/nikola/plugins/compile/markdown/mdx_nikola.py
+++ b/nikola/plugins/compile/markdown/mdx_nikola.py
@@ -24,7 +24,8 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-"""Markdown Extension for Nikola-specific post-processing"""
+"""Markdown Extension for Nikola-specific post-processing."""
+
from __future__ import unicode_literals
import re
try:
@@ -41,7 +42,11 @@ CODERE = re.compile('<div class="codehilite"><pre>(.*?)</pre></div>', flags=re.M
class NikolaPostProcessor(Postprocessor):
+
+ """Nikola-specific post-processing for Markdown."""
+
def run(self, text):
+ """Run the postprocessor."""
output = text
# python-markdown's highlighter uses <div class="codehilite"><pre>
@@ -52,11 +57,16 @@ class NikolaPostProcessor(Postprocessor):
class NikolaExtension(MarkdownExtension, Extension):
+
+ """Extension for injecting the postprocessor."""
+
def extendMarkdown(self, md, md_globals):
+ """Extend Markdown with the postprocessor."""
pp = NikolaPostProcessor()
md.postprocessors.add('nikola_post_processor', pp, '_end')
md.registerExtension(self)
-def makeExtension(configs=None):
+def makeExtension(configs=None): # pragma: no cover
+ """Make extension."""
return NikolaExtension(configs)
diff --git a/nikola/plugins/compile/markdown/mdx_podcast.plugin b/nikola/plugins/compile/markdown/mdx_podcast.plugin
index dc16044..c92a8a0 100644
--- a/nikola/plugins/compile/markdown/mdx_podcast.plugin
+++ b/nikola/plugins/compile/markdown/mdx_podcast.plugin
@@ -1,9 +1,14 @@
[Core]
-Name = mdx_podcast
-Module = mdx_podcast
+name = mdx_podcast
+module = mdx_podcast
+
+[Nikola]
+compiler = markdown
+plugincategory = CompilerExtension
[Documentation]
-Author = Roberto Alsina
-Version = 0.1
-Website = http://getnikola.com
-Description = Markdown extensions for embedding podcasts and other audio files
+author = Roberto Alsina
+version = 0.1
+website = http://getnikola.com
+description = Markdown extensions for embedding podcasts and other audio files
+
diff --git a/nikola/plugins/compile/markdown/mdx_podcast.py b/nikola/plugins/compile/markdown/mdx_podcast.py
index 670973a..61afdbf 100644
--- a/nikola/plugins/compile/markdown/mdx_podcast.py
+++ b/nikola/plugins/compile/markdown/mdx_podcast.py
@@ -24,21 +24,19 @@
# Inspired by "[Python] reStructuredText GitHub Podcast directive"
# (https://gist.github.com/brianhsu/1407759), public domain by Brian Hsu
-from __future__ import print_function, unicode_literals
-
-
-'''
-Extension to Python Markdown for Embedded Audio
+"""
+Extension to Python Markdown for Embedded Audio.
Basic Example:
>>> import markdown
->>> text = """[podcast]http://archive.org/download/Rebeldes_Stereotipos/rs20120609_1.mp3[/podcast]"""
+>>> text = "[podcast]http://archive.org/download/Rebeldes_Stereotipos/rs20120609_1.mp3[/podcast]"
>>> html = markdown.markdown(text, [PodcastExtension()])
>>> print(html)
-<p><audio src="http://archive.org/download/Rebeldes_Stereotipos/rs20120609_1.mp3"></audio></p>
-'''
+<p><audio controls=""><source src="http://archive.org/download/Rebeldes_Stereotipos/rs20120609_1.mp3" type="audio/mpeg"></source></audio></p>
+"""
+from __future__ import print_function, unicode_literals
from nikola.plugin_categories import MarkdownExtension
try:
from markdown.extensions import Extension
@@ -53,12 +51,15 @@ PODCAST_RE = r'\[podcast\](?P<url>.+)\[/podcast\]'
class PodcastPattern(Pattern):
- """ InlinePattern for footnote markers in a document's body text. """
+
+ """InlinePattern for footnote markers in a document's body text."""
def __init__(self, pattern, configs):
+ """Initialize pattern."""
Pattern.__init__(self, pattern)
def handleMatch(self, m):
+ """Handle pattern matches."""
url = m.group('url').strip()
audio_elem = etree.Element('audio')
audio_elem.set('controls', '')
@@ -69,7 +70,11 @@ class PodcastPattern(Pattern):
class PodcastExtension(MarkdownExtension, Extension):
+
+ """"Podcast extension for Markdown."""
+
def __init__(self, configs={}):
+ """Initialize extension."""
# set extension defaults
self.config = {}
@@ -78,13 +83,15 @@ class PodcastExtension(MarkdownExtension, Extension):
self.setConfig(key, value)
def extendMarkdown(self, md, md_globals):
+ """Extend Markdown."""
podcast_md_pattern = PodcastPattern(PODCAST_RE, self.getConfigs())
podcast_md_pattern.md = md
md.inlinePatterns.add('podcast', podcast_md_pattern, "<not_strong")
md.registerExtension(self)
-def makeExtension(configs=None):
+def makeExtension(configs=None): # pragma: no cover
+ """Make Markdown extension."""
return PodcastExtension(configs)
if __name__ == '__main__':
diff --git a/nikola/plugins/compile/pandoc.plugin b/nikola/plugins/compile/pandoc.plugin
index ad54b3b..3ff3668 100644
--- a/nikola/plugins/compile/pandoc.plugin
+++ b/nikola/plugins/compile/pandoc.plugin
@@ -1,10 +1,13 @@
[Core]
-Name = pandoc
-Module = pandoc
+name = pandoc
+module = pandoc
[Documentation]
-Author = Roberto Alsina
-Version = 1.0
-Website = http://getnikola.com
-Description = Compile markups into HTML using pandoc
+author = Roberto Alsina
+version = 1.0
+website = http://getnikola.com
+description = Compile markups into HTML using pandoc
+[Nikola]
+plugincategory = Compiler
+friendlyname = Pandoc
diff --git a/nikola/plugins/compile/pandoc.py b/nikola/plugins/compile/pandoc.py
index 361f158..3030626 100644
--- a/nikola/plugins/compile/pandoc.py
+++ b/nikola/plugins/compile/pandoc.py
@@ -27,7 +27,6 @@
"""Implementation of compile_html based on pandoc.
You will need, of course, to install pandoc
-
"""
from __future__ import unicode_literals
@@ -41,16 +40,19 @@ from nikola.utils import req_missing, makedirs, write_metadata
class CompilePandoc(PageCompiler):
+
"""Compile markups into HTML using pandoc."""
name = "pandoc"
friendly_name = "pandoc"
def set_site(self, site):
+ """Set Nikola site."""
self.config_dependencies = [str(site.config['PANDOC_OPTIONS'])]
super(CompilePandoc, self).set_site(site)
def compile_html(self, source, dest, is_two_file=True):
+ """Compile source file into HTML and save as dest."""
makedirs(os.path.dirname(dest))
try:
subprocess.check_call(['pandoc', '-o', dest, source] + self.site.config['PANDOC_OPTIONS'])
@@ -59,6 +61,7 @@ class CompilePandoc(PageCompiler):
req_missing(['pandoc'], 'build this site (compile with pandoc)', python=False)
def create_post(self, path, **kw):
+ """Create a new post."""
content = kw.pop('content', None)
onefile = kw.pop('onefile', False)
# is_page is not used by create_post as of now.
diff --git a/nikola/plugins/compile/php.plugin b/nikola/plugins/compile/php.plugin
index d6623b5..151c022 100644
--- a/nikola/plugins/compile/php.plugin
+++ b/nikola/plugins/compile/php.plugin
@@ -1,10 +1,13 @@
[Core]
-Name = php
-Module = php
+name = php
+module = php
[Documentation]
-Author = Roberto Alsina
-Version = 1.0
-Website = http://getnikola.com
-Description = Compile PHP into HTML (just copy and name the file .php)
+author = Roberto Alsina
+version = 1.0
+website = http://getnikola.com
+description = Compile PHP into HTML (just copy and name the file .php)
+[Nikola]
+plugincategory = Compiler
+friendlyname = PHP
diff --git a/nikola/plugins/compile/php.py b/nikola/plugins/compile/php.py
index bb436e5..28f4923 100644
--- a/nikola/plugins/compile/php.py
+++ b/nikola/plugins/compile/php.py
@@ -37,12 +37,14 @@ from hashlib import md5
class CompilePhp(PageCompiler):
+
"""Compile PHP into PHP."""
name = "php"
friendly_name = "PHP"
def compile_html(self, source, dest, is_two_file=True):
+ """Compile source file into HTML and save as dest."""
makedirs(os.path.dirname(dest))
with io.open(dest, "w+", encoding="utf8") as out_file:
with open(source, "rb") as in_file:
@@ -51,6 +53,7 @@ class CompilePhp(PageCompiler):
return True
def create_post(self, path, **kw):
+ """Create a new post."""
content = kw.pop('content', None)
onefile = kw.pop('onefile', False)
# is_page is not used by create_post as of now.
@@ -80,4 +83,5 @@ class CompilePhp(PageCompiler):
fd.write(content)
def extension(self):
+ """Return extension used for PHP files."""
return ".php"
diff --git a/nikola/plugins/compile/rest.plugin b/nikola/plugins/compile/rest.plugin
index f144809..cf842c7 100644
--- a/nikola/plugins/compile/rest.plugin
+++ b/nikola/plugins/compile/rest.plugin
@@ -1,10 +1,13 @@
[Core]
-Name = rest
-Module = rest
+name = rest
+module = rest
[Documentation]
-Author = Roberto Alsina
-Version = 1.0
-Website = http://getnikola.com
-Description = Compile reSt into HTML
+author = Roberto Alsina
+version = 1.0
+website = http://getnikola.com
+description = Compile reSt into HTML
+[Nikola]
+plugincategory = Compiler
+friendlyname = reStructuredText
diff --git a/nikola/plugins/compile/rest/__init__.py b/nikola/plugins/compile/rest/__init__.py
index d446fe8..b99e872 100644
--- a/nikola/plugins/compile/rest/__init__.py
+++ b/nikola/plugins/compile/rest/__init__.py
@@ -24,6 +24,8 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+"""reStructuredText compiler for Nikola."""
+
from __future__ import unicode_literals
import io
import os
@@ -36,10 +38,11 @@ import docutils.readers.standalone
import docutils.writers.html4css1
from nikola.plugin_categories import PageCompiler
-from nikola.utils import unicode_str, get_logger, makedirs, write_metadata
+from nikola.utils import unicode_str, get_logger, makedirs, write_metadata, STDERR_HANDLER
class CompileRest(PageCompiler):
+
"""Compile reStructuredText into HTML."""
name = "rest"
@@ -48,7 +51,7 @@ class CompileRest(PageCompiler):
logger = None
def _read_extra_deps(self, post):
- """Reads contents of .dep file and returns them as a list"""
+ """Read contents of .dep file and returns them as a list."""
dep_path = post.base_path + '.dep'
if os.path.isfile(dep_path):
with io.open(dep_path, 'r+', encoding='utf8') as depf:
@@ -57,11 +60,11 @@ class CompileRest(PageCompiler):
return []
def register_extra_dependencies(self, post):
- """Adds dependency to post object to check .dep file."""
+ """Add dependency to post object to check .dep file."""
post.add_dependency(lambda: self._read_extra_deps(post), 'fragment')
def compile_html_string(self, data, source_path=None, is_two_file=True):
- """Compile reSt into HTML strings."""
+ """Compile reST into HTML strings."""
# If errors occur, this will be added to the line number reported by
# docutils so the line number matches the actual line number (off by
# 7 with default metadata, could be more or less depending on the post).
@@ -88,7 +91,7 @@ class CompileRest(PageCompiler):
return output, error_level, deps
def compile_html(self, source, dest, is_two_file=True):
- """Compile reSt into HTML files."""
+ """Compile source file into HTML and save as dest."""
makedirs(os.path.dirname(dest))
error_level = 100
with io.open(dest, "w+", encoding="utf8") as out_file:
@@ -110,6 +113,7 @@ class CompileRest(PageCompiler):
return False
def create_post(self, path, **kw):
+ """Create a new post."""
content = kw.pop('content', None)
onefile = kw.pop('onefile', False)
# is_page is not used by create_post as of now.
@@ -127,23 +131,17 @@ class CompileRest(PageCompiler):
fd.write(content)
def set_site(self, site):
+ """Set Nikola site."""
+ super(CompileRest, self).set_site(site)
self.config_dependencies = []
- for plugin_info in site.plugin_manager.getPluginsOfCategory("RestExtension"):
- if plugin_info.name in site.config['DISABLED_PLUGINS']:
- site.plugin_manager.removePluginFromCategory(plugin_info, "RestExtension")
- continue
-
- site.plugin_manager.activatePluginByName(plugin_info.name)
+ for plugin_info in self.get_compiler_extensions():
self.config_dependencies.append(plugin_info.name)
- plugin_info.plugin_object.set_site(site)
plugin_info.plugin_object.short_help = plugin_info.description
- self.logger = get_logger('compile_rest', site.loghandlers)
+ self.logger = get_logger('compile_rest', STDERR_HANDLER)
if not site.debug:
self.logger.level = 4
- return super(CompileRest, self).set_site(site)
-
def get_observer(settings):
"""Return an observer for the docutils Reporter."""
@@ -175,11 +173,15 @@ def get_observer(settings):
class NikolaReader(docutils.readers.standalone.Reader):
+ """Nikola-specific docutils reader."""
+
def __init__(self, *args, **kwargs):
+ """Initialize the reader."""
self.transforms = kwargs.pop('transforms', [])
docutils.readers.standalone.Reader.__init__(self, *args, **kwargs)
def get_transforms(self):
+ """Get docutils transforms."""
return docutils.readers.standalone.Reader(self).get_transforms() + self.transforms
def new_document(self):
@@ -191,8 +193,8 @@ class NikolaReader(docutils.readers.standalone.Reader):
def add_node(node, visit_function=None, depart_function=None):
- """
- Register a Docutils node class.
+ """Register a Docutils node class.
+
This function is completely optional. It is a same concept as
`Sphinx add_node function <http://sphinx-doc.org/ext/appapi.html#sphinx.application.Sphinx.add_node>`_.
@@ -236,8 +238,8 @@ def rst2html(source, source_path=None, source_class=docutils.io.StringInput,
writer_name='html', settings=None, settings_spec=None,
settings_overrides=None, config_section=None,
enable_exit_status=None, logger=None, l_add_ln=0, transforms=None):
- """
- Set up & run a `Publisher`, and return a dictionary of document parts.
+ """Set up & run a ``Publisher``, and return a dictionary of document parts.
+
Dictionary keys are the names of parts, and values are Unicode strings;
encoding is up to the client. For programmatic use with string I/O.
diff --git a/nikola/plugins/compile/rest/chart.plugin b/nikola/plugins/compile/rest/chart.plugin
index 3e27a25..438abe4 100644
--- a/nikola/plugins/compile/rest/chart.plugin
+++ b/nikola/plugins/compile/rest/chart.plugin
@@ -1,10 +1,14 @@
[Core]
-Name = rest_chart
-Module = chart
+name = rest_chart
+module = chart
+
+[Nikola]
+compiler = rest
+plugincategory = CompilerExtension
[Documentation]
-Author = Roberto Alsina
-Version = 0.1
-Website = http://getnikola.com
-Description = Chart directive based in PyGal
+author = Roberto Alsina
+version = 0.1
+website = http://getnikola.com
+description = Chart directive based in PyGal
diff --git a/nikola/plugins/compile/rest/chart.py b/nikola/plugins/compile/rest/chart.py
index 59b9dc7..88fdff3 100644
--- a/nikola/plugins/compile/rest/chart.py
+++ b/nikola/plugins/compile/rest/chart.py
@@ -24,6 +24,8 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+"""Chart directive for reSTructuredText."""
+
from ast import literal_eval
from docutils import nodes
@@ -42,9 +44,12 @@ _site = None
class Plugin(RestExtension):
+ """Plugin for chart role."""
+
name = "rest_chart"
def set_site(self, site):
+ """Set Nikola site."""
global _site
_site = self.site = site
directives.register_directive('chart', Chart)
@@ -52,17 +57,18 @@ class Plugin(RestExtension):
class Chart(Directive):
- """ Restructured text extension for inserting charts as SVG
- Usage:
- .. chart:: Bar
- :title: 'Browser usage evolution (in %)'
- :x_labels: ["2002", "2003", "2004", "2005", "2006", "2007"]
+ """reStructuredText extension for inserting charts as SVG.
+
+ Usage:
+ .. chart:: Bar
+ :title: 'Browser usage evolution (in %)'
+ :x_labels: ["2002", "2003", "2004", "2005", "2006", "2007"]
- 'Firefox', [None, None, 0, 16.6, 25, 31]
- 'Chrome', [None, None, None, None, None, None]
- 'IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6]
- 'Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4]
+ 'Firefox', [None, None, 0, 16.6, 25, 31]
+ 'Chrome', [None, None, None, None, None, None]
+ 'IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6]
+ 'Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4]
"""
has_content = True
@@ -129,6 +135,7 @@ class Chart(Directive):
}
def run(self):
+ """Run the directive."""
if pygal is None:
msg = req_missing(['pygal'], 'use the Chart directive', optional=True)
return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')]
diff --git a/nikola/plugins/compile/rest/doc.plugin b/nikola/plugins/compile/rest/doc.plugin
index 1984f52..facdd03 100644
--- a/nikola/plugins/compile/rest/doc.plugin
+++ b/nikola/plugins/compile/rest/doc.plugin
@@ -1,10 +1,14 @@
[Core]
-Name = rest_doc
-Module = doc
+name = rest_doc
+module = doc
+
+[Nikola]
+compiler = rest
+plugincategory = CompilerExtension
[Documentation]
-Author = Manuel Kaufmann
-Version = 0.1
-Website = http://getnikola.com
-Description = Role to link another page / post from the blog
+author = Manuel Kaufmann
+version = 0.1
+website = http://getnikola.com
+description = Role to link another page / post from the blog
diff --git a/nikola/plugins/compile/rest/doc.py b/nikola/plugins/compile/rest/doc.py
index 703c234..99cce81 100644
--- a/nikola/plugins/compile/rest/doc.py
+++ b/nikola/plugins/compile/rest/doc.py
@@ -24,6 +24,7 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+"""reST role for linking to other documents."""
from docutils import nodes
from docutils.parsers.rst import roles
@@ -34,9 +35,12 @@ from nikola.plugin_categories import RestExtension
class Plugin(RestExtension):
+ """Plugin for doc role."""
+
name = 'rest_doc'
def set_site(self, site):
+ """Set Nikola site."""
self.site = site
roles.register_canonical_role('doc', doc_role)
doc_role.site = site
@@ -45,7 +49,7 @@ class Plugin(RestExtension):
def doc_role(name, rawtext, text, lineno, inliner,
options={}, content=[]):
-
+ """Handle the doc role."""
# split link's text and post's slug in role content
has_explicit_title, title, slug = split_explicit_title(text)
# check if the slug given is part of our blog posts/pages
@@ -82,5 +86,6 @@ def doc_role(name, rawtext, text, lineno, inliner,
def make_link_node(rawtext, text, url, options):
+ """Make a reST link node."""
node = nodes.reference(rawtext, text, refuri=url, *options)
return node
diff --git a/nikola/plugins/compile/rest/gist.plugin b/nikola/plugins/compile/rest/gist.plugin
index 8f498ec..9fa2e82 100644
--- a/nikola/plugins/compile/rest/gist.plugin
+++ b/nikola/plugins/compile/rest/gist.plugin
@@ -1,10 +1,14 @@
[Core]
-Name = rest_gist
-Module = gist
+name = rest_gist
+module = gist
+
+[Nikola]
+compiler = rest
+plugincategory = CompilerExtension
[Documentation]
-Author = Roberto Alsina
-Version = 0.1
-Website = http://getnikola.com
-Description = Gist directive
+author = Roberto Alsina
+version = 0.1
+website = http://getnikola.com
+description = Gist directive
diff --git a/nikola/plugins/compile/rest/gist.py b/nikola/plugins/compile/rest/gist.py
index ab4d56d..736ee37 100644
--- a/nikola/plugins/compile/rest/gist.py
+++ b/nikola/plugins/compile/rest/gist.py
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
# This file is public domain according to its author, Brian Hsu
+"""Gist directive for reStructuredText."""
+
import requests
from docutils.parsers.rst import Directive, directives
from docutils import nodes
@@ -10,26 +12,28 @@ from nikola.plugin_categories import RestExtension
class Plugin(RestExtension):
+ """Plugin for gist directive."""
+
name = "rest_gist"
def set_site(self, site):
+ """Set Nikola site."""
self.site = site
directives.register_directive('gist', GitHubGist)
return super(Plugin, self).set_site(site)
class GitHubGist(Directive):
- """ Embed GitHub Gist.
-
- Usage:
- .. gist:: GIST_ID
+ """Embed GitHub Gist.
- or
+ Usage:
- .. gist:: GIST_URL
+ .. gist:: GIST_ID
+ or
+ .. gist:: GIST_URL
"""
required_arguments = 1
@@ -39,10 +43,12 @@ class GitHubGist(Directive):
has_content = False
def get_raw_gist_with_filename(self, gistID, filename):
+ """Get raw gist text for a filename."""
url = '/'.join(("https://gist.github.com/raw", gistID, filename))
return requests.get(url).text
def get_raw_gist(self, gistID):
+ """Get raw gist text."""
url = "https://gist.github.com/raw/{0}".format(gistID)
try:
return requests.get(url).text
@@ -50,6 +56,7 @@ class GitHubGist(Directive):
raise self.error('Cannot get gist for url={0}'.format(url))
def run(self):
+ """Run the gist directive."""
if 'https://' in self.arguments[0]:
gistID = self.arguments[0].split('/')[-1].strip()
else:
diff --git a/nikola/plugins/compile/rest/listing.plugin b/nikola/plugins/compile/rest/listing.plugin
index 4c9883e..85c780f 100644
--- a/nikola/plugins/compile/rest/listing.plugin
+++ b/nikola/plugins/compile/rest/listing.plugin
@@ -1,10 +1,14 @@
[Core]
-Name = rest_listing
-Module = listing
+name = rest_listing
+module = listing
+
+[Nikola]
+compiler = rest
+plugincategory = CompilerExtension
[Documentation]
-Author = Roberto Alsina
-Version = 0.1
-Website = http://getnikola.com
-Description = Extension for source listings
+author = Roberto Alsina
+version = 0.1
+website = http://getnikola.com
+description = Extension for source listings
diff --git a/nikola/plugins/compile/rest/listing.py b/nikola/plugins/compile/rest/listing.py
index b8340cf..4871bf3 100644
--- a/nikola/plugins/compile/rest/listing.py
+++ b/nikola/plugins/compile/rest/listing.py
@@ -25,7 +25,7 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-""" Define and register a listing directive using the existing CodeBlock """
+"""Define and register a listing directive using the existing CodeBlock."""
from __future__ import unicode_literals
@@ -55,7 +55,9 @@ from nikola.plugin_categories import RestExtension
# A sanitized version of docutils.parsers.rst.directives.body.CodeBlock.
class CodeBlock(Directive):
+
"""Parse and mark up content of a code block."""
+
optional_arguments = 1
option_spec = {'class': directives.class_option,
'name': directives.unchanged,
@@ -65,6 +67,7 @@ class CodeBlock(Directive):
has_content = True
def run(self):
+ """Run code block directive."""
self.assert_has_content()
if 'linenos' in self.options:
@@ -124,9 +127,12 @@ docutils.parsers.rst.directives.misc.CodeBlock = CodeBlock
class Plugin(RestExtension):
+ """Plugin for listing directive."""
+
name = "rest_listing"
def set_site(self, site):
+ """Set Nikola site."""
self.site = site
# Even though listings don't use CodeBlock anymore, I am
# leaving these to make the code directive work with
@@ -146,7 +152,8 @@ listing_spec['linenos'] = directives.unchanged
class Listing(Include):
- """ listing directive: create a highlighted block of code from a file in listings/
+
+ """Create a highlighted block of code from a file in listings/.
Usage:
@@ -154,12 +161,14 @@ class Listing(Include):
:number-lines:
"""
+
has_content = False
required_arguments = 1
optional_arguments = 1
option_spec = listing_spec
def run(self):
+ """Run listing directive."""
_fname = self.arguments.pop(0)
fname = _fname.replace('/', os.sep)
lang = self.arguments.pop(0)
@@ -185,9 +194,9 @@ class Listing(Include):
return generated_nodes
def get_code_from_file(self, data):
- """ Create CodeBlock nodes from file object content """
+ """Create CodeBlock nodes from file object content."""
return super(Listing, self).run()
def assert_has_content(self):
- """ Listing has no content, override check from superclass """
+ """Listing has no content, override check from superclass."""
pass
diff --git a/nikola/plugins/compile/rest/media.plugin b/nikola/plugins/compile/rest/media.plugin
index 5f5276b..9803c8f 100644
--- a/nikola/plugins/compile/rest/media.plugin
+++ b/nikola/plugins/compile/rest/media.plugin
@@ -1,10 +1,14 @@
[Core]
-Name = rest_media
-Module = media
+name = rest_media
+module = media
+
+[Nikola]
+compiler = rest
+plugincategory = CompilerExtension
[Documentation]
-Author = Roberto Alsina
-Version = 0.1
-Website = http://getnikola.com
-Description = Directive to support oembed via micawber
+author = Roberto Alsina
+version = 0.1
+website = http://getnikola.com
+description = Directive to support oembed via micawber
diff --git a/nikola/plugins/compile/rest/media.py b/nikola/plugins/compile/rest/media.py
index 0363d28..345e331 100644
--- a/nikola/plugins/compile/rest/media.py
+++ b/nikola/plugins/compile/rest/media.py
@@ -24,6 +24,7 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+"""Media directive for reStructuredText."""
from docutils import nodes
from docutils.parsers.rst import Directive, directives
@@ -40,21 +41,27 @@ from nikola.utils import req_missing
class Plugin(RestExtension):
+ """Plugin for reST media directive."""
+
name = "rest_media"
def set_site(self, site):
+ """Set Nikola site."""
self.site = site
directives.register_directive('media', Media)
return super(Plugin, self).set_site(site)
class Media(Directive):
- """ Restructured text extension for inserting any sort of media using micawber."""
+
+ """reST extension for inserting any sort of media using micawber."""
+
has_content = False
required_arguments = 1
optional_arguments = 999
def run(self):
+ """Run media directive."""
if micawber is None:
msg = req_missing(['micawber'], 'use the media directive', optional=True)
return [nodes.raw('', '<div class="text-error">{0}</div>'.format(msg), format='html')]
diff --git a/nikola/plugins/compile/rest/post_list.plugin b/nikola/plugins/compile/rest/post_list.plugin
index 82450a0..48969bf 100644
--- a/nikola/plugins/compile/rest/post_list.plugin
+++ b/nikola/plugins/compile/rest/post_list.plugin
@@ -1,9 +1,14 @@
[Core]
-Name = rest_post_list
-Module = post_list
+name = rest_post_list
+module = post_list
+
+[Nikola]
+compiler = rest
+plugincategory = CompilerExtension
[Documentation]
-Author = Udo Spallek
-Version = 0.1
-Website = http://getnikola.com
-Description = Includes a list of posts with tag and slide based filters.
+author = Udo Spallek
+version = 0.1
+website = http://getnikola.com
+description = Includes a list of posts with tag and slide based filters.
+
diff --git a/nikola/plugins/compile/rest/post_list.py b/nikola/plugins/compile/rest/post_list.py
index ddbd82d..a22ee85 100644
--- a/nikola/plugins/compile/rest/post_list.py
+++ b/nikola/plugins/compile/rest/post_list.py
@@ -23,6 +23,9 @@
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+"""Post list directive for reStructuredText."""
+
from __future__ import unicode_literals
import os
@@ -40,9 +43,13 @@ from nikola.plugin_categories import RestExtension
class Plugin(RestExtension):
+
+ """Plugin for reST post-list directive."""
+
name = "rest_post_list"
def set_site(self, site):
+ """Set Nikola site."""
self.site = site
directives.register_directive('post-list', PostList)
PostList.site = site
@@ -50,14 +57,15 @@ class Plugin(RestExtension):
class PostList(Directive):
- """
+
+ """Provide a reStructuredText directive to create a list of posts.
+
Post List
=========
:Directive Arguments: None.
- :Directive Options: lang, start, stop, reverse, sort, tags, template, id
+ :Directive Options: lang, start, stop, reverse, sort, tags, categories, slugs, all, template, id
:Directive Content: None.
- Provides a reStructuredText directive to create a list of posts.
The posts appearing in the list can be filtered by options.
*List slicing* is provided with the *start*, *stop* and *reverse* options.
@@ -87,6 +95,10 @@ class PostList(Directive):
Filter posts to show only posts having at least one of the ``tags``.
Defaults to None.
+ ``categories`` : string [, string...]
+ Filter posts to show only posts having one of the ``categories``.
+ Defaults to None.
+
``slugs`` : string [, string...]
Filter posts to show only posts having at least one of the ``slugs``.
Defaults to None.
@@ -107,12 +119,14 @@ class PostList(Directive):
A manual id for the post list.
Defaults to a random name composed by 'post_list_' + uuid.uuid4().hex.
"""
+
option_spec = {
'start': int,
'stop': int,
'reverse': directives.flag,
'sort': directives.unchanged,
'tags': directives.unchanged,
+ 'categories': directives.unchanged,
'slugs': directives.unchanged,
'all': directives.flag,
'lang': directives.unchanged,
@@ -121,11 +135,14 @@ class PostList(Directive):
}
def run(self):
+ """Run post-list directive."""
start = self.options.get('start')
stop = self.options.get('stop')
reverse = self.options.get('reverse', False)
tags = self.options.get('tags')
tags = [t.strip().lower() for t in tags.split(',')] if tags else []
+ categories = self.options.get('categories')
+ categories = [c.strip().lower() for c in categories.split(',')] if categories else []
slugs = self.options.get('slugs')
slugs = [s.strip() for s in slugs.split(',')] if slugs else []
show_all = self.options.get('all', False)
@@ -145,6 +162,9 @@ class PostList(Directive):
else:
timeline = [p for p in self.site.timeline if p.use_in_feeds]
+ if categories:
+ timeline = [p for p in timeline if p.meta('category', lang=lang).lower() in categories]
+
for post in timeline:
if tags:
cont = True
diff --git a/nikola/plugins/compile/rest/slides.plugin b/nikola/plugins/compile/rest/slides.plugin
index cee4b06..5c05b89 100644
--- a/nikola/plugins/compile/rest/slides.plugin
+++ b/nikola/plugins/compile/rest/slides.plugin
@@ -1,10 +1,14 @@
[Core]
-Name = rest_slides
-Module = slides
+name = rest_slides
+module = slides
+
+[Nikola]
+compiler = rest
+plugincategory = CompilerExtension
[Documentation]
-Author = Roberto Alsina
-Version = 0.1
-Website = http://getnikola.com
-Description = Slides directive
+author = Roberto Alsina
+version = 0.1
+website = http://getnikola.com
+description = Slides directive
diff --git a/nikola/plugins/compile/rest/slides.py b/nikola/plugins/compile/rest/slides.py
index 7826f6a..2522e55 100644
--- a/nikola/plugins/compile/rest/slides.py
+++ b/nikola/plugins/compile/rest/slides.py
@@ -24,6 +24,8 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+"""Slides directive for reStructuredText."""
+
from __future__ import unicode_literals
import uuid
@@ -36,9 +38,12 @@ from nikola.plugin_categories import RestExtension
class Plugin(RestExtension):
+ """Plugin for reST slides directive."""
+
name = "rest_slides"
def set_site(self, site):
+ """Set Nikola site."""
self.site = site
directives.register_directive('slides', Slides)
Slides.site = site
@@ -46,11 +51,14 @@ class Plugin(RestExtension):
class Slides(Directive):
- """ Restructured text extension for inserting slideshows."""
+
+ """reST extension for inserting slideshows."""
+
has_content = True
def run(self):
- if len(self.content) == 0:
+ """Run the slides directive."""
+ if len(self.content) == 0: # pragma: no cover
return
if self.site.invariant: # for testing purposes
diff --git a/nikola/plugins/compile/rest/soundcloud.plugin b/nikola/plugins/compile/rest/soundcloud.plugin
index 1d31a8f..75469e4 100644
--- a/nikola/plugins/compile/rest/soundcloud.plugin
+++ b/nikola/plugins/compile/rest/soundcloud.plugin
@@ -1,10 +1,14 @@
[Core]
-Name = rest_soundcloud
-Module = soundcloud
+name = rest_soundcloud
+module = soundcloud
+
+[Nikola]
+compiler = rest
+plugincategory = CompilerExtension
[Documentation]
-Author = Roberto Alsina
-Version = 0.1
-Website = http://getnikola.com
-Description = Soundcloud directive
+author = Roberto Alsina
+version = 0.1
+website = http://getnikola.com
+description = Soundcloud directive
diff --git a/nikola/plugins/compile/rest/soundcloud.py b/nikola/plugins/compile/rest/soundcloud.py
index a26806c..30134a9 100644
--- a/nikola/plugins/compile/rest/soundcloud.py
+++ b/nikola/plugins/compile/rest/soundcloud.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
+"""SoundCloud directive for reStructuredText."""
from docutils import nodes
from docutils.parsers.rst import Directive, directives
@@ -10,9 +11,12 @@ from nikola.plugin_categories import RestExtension
class Plugin(RestExtension):
+ """Plugin for soundclound directive."""
+
name = "rest_soundcloud"
def set_site(self, site):
+ """Set Nikola site."""
self.site = site
directives.register_directive('soundcloud', SoundCloud)
directives.register_directive('soundcloud_playlist', SoundCloudPlaylist)
@@ -27,7 +31,8 @@ src="https://w.soundcloud.com/player/?url=http://api.soundcloud.com/{preslug}/""
class SoundCloud(Directive):
- """ Restructured text extension for inserting SoundCloud embedded music
+
+ """reST extension for inserting SoundCloud embedded music.
Usage:
.. soundcloud:: <sound id>
@@ -35,6 +40,7 @@ class SoundCloud(Directive):
:width: 600
"""
+
has_content = True
required_arguments = 1
option_spec = {
@@ -44,7 +50,7 @@ class SoundCloud(Directive):
preslug = "tracks"
def run(self):
- """ Required by the Directive interface. Create docutils nodes """
+ """Run the soundcloud directive."""
self.check_content()
options = {
'sid': self.arguments[0],
@@ -56,12 +62,15 @@ class SoundCloud(Directive):
return [nodes.raw('', CODE.format(**options), format='html')]
def check_content(self):
- """ Emit a deprecation warning if there is content """
- if self.content:
+ """Emit a deprecation warning if there is content."""
+ if self.content: # pragma: no cover
raise self.warning("This directive does not accept content. The "
"'key=value' format for options is deprecated, "
"use ':key: value' instead")
class SoundCloudPlaylist(SoundCloud):
+
+ """reST directive for SoundCloud playlists."""
+
preslug = "playlists"
diff --git a/nikola/plugins/compile/rest/thumbnail.plugin b/nikola/plugins/compile/rest/thumbnail.plugin
index 3b73340..0084310 100644
--- a/nikola/plugins/compile/rest/thumbnail.plugin
+++ b/nikola/plugins/compile/rest/thumbnail.plugin
@@ -1,9 +1,14 @@
[Core]
-Name = rest_thumbnail
-Module = thumbnail
+name = rest_thumbnail
+module = thumbnail
+
+[Nikola]
+compiler = rest
+plugincategory = CompilerExtension
[Documentation]
-Author = Pelle Nilsson
-Version = 0.1
-Website = http://getnikola.com
-Description = reST directive to facilitate enlargeable images with thumbnails
+author = Pelle Nilsson
+version = 0.1
+website = http://getnikola.com
+description = reST directive to facilitate enlargeable images with thumbnails
+
diff --git a/nikola/plugins/compile/rest/thumbnail.py b/nikola/plugins/compile/rest/thumbnail.py
index 5388d8d..1fae06c 100644
--- a/nikola/plugins/compile/rest/thumbnail.py
+++ b/nikola/plugins/compile/rest/thumbnail.py
@@ -24,6 +24,8 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+"""Thumbnail directive for reStructuredText."""
+
import os
from docutils.parsers.rst import directives
@@ -34,9 +36,12 @@ from nikola.plugin_categories import RestExtension
class Plugin(RestExtension):
+ """Plugin for thumbnail directive."""
+
name = "rest_thumbnail"
def set_site(self, site):
+ """Set Nikola site."""
self.site = site
directives.register_directive('thumbnail', Thumbnail)
return super(Plugin, self).set_site(site)
@@ -44,10 +49,14 @@ class Plugin(RestExtension):
class Thumbnail(Figure):
+ """Thumbnail directive for reST."""
+
def align(argument):
+ """Return thumbnail alignment."""
return directives.choice(argument, Image.align_values)
def figwidth_value(argument):
+ """Return figure width."""
if argument.lower() == 'image':
return 'image'
else:
@@ -59,6 +68,7 @@ class Thumbnail(Figure):
has_content = True
def run(self):
+ """Run the thumbnail directive."""
uri = directives.uri(self.arguments[0])
self.options['target'] = uri
self.arguments[0] = '.thumbnail'.join(os.path.splitext(uri))
diff --git a/nikola/plugins/compile/rest/vimeo.plugin b/nikola/plugins/compile/rest/vimeo.plugin
index e0ff3f1..688f981 100644
--- a/nikola/plugins/compile/rest/vimeo.plugin
+++ b/nikola/plugins/compile/rest/vimeo.plugin
@@ -1,7 +1,11 @@
[Core]
-Name = rest_vimeo
-Module = vimeo
+name = rest_vimeo
+module = vimeo
+
+[Nikola]
+compiler = rest
+plugincategory = CompilerExtension
[Documentation]
-Description = Vimeo directive
+description = Vimeo directive
diff --git a/nikola/plugins/compile/rest/vimeo.py b/nikola/plugins/compile/rest/vimeo.py
index bc44b0e..c694a87 100644
--- a/nikola/plugins/compile/rest/vimeo.py
+++ b/nikola/plugins/compile/rest/vimeo.py
@@ -24,6 +24,7 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+"""Vimeo directive for reStructuredText."""
from docutils import nodes
from docutils.parsers.rst import Directive, directives
@@ -37,9 +38,12 @@ from nikola.plugin_categories import RestExtension
class Plugin(RestExtension):
+ """Plugin for vimeo reST directive."""
+
name = "rest_vimeo"
def set_site(self, site):
+ """Set Nikola site."""
self.site = site
directives.register_directive('vimeo', Vimeo)
return super(Plugin, self).set_site(site)
@@ -56,14 +60,16 @@ VIDEO_DEFAULT_WIDTH = 281
class Vimeo(Directive):
- """ Restructured text extension for inserting vimeo embedded videos
- Usage:
- .. vimeo:: 20241459
- :height: 400
- :width: 600
+ """reST extension for inserting vimeo embedded videos.
+
+ Usage:
+ .. vimeo:: 20241459
+ :height: 400
+ :width: 600
"""
+
has_content = True
required_arguments = 1
option_spec = {
@@ -75,6 +81,7 @@ class Vimeo(Directive):
request_size = True
def run(self):
+ """Run the vimeo directive."""
self.check_content()
options = {
'vimeo_id': self.arguments[0],
@@ -90,9 +97,11 @@ class Vimeo(Directive):
return [nodes.raw('', CODE.format(**options), format='html')]
def check_modules(self):
+ """Check modules."""
return None
def set_video_size(self):
+ """Set video size."""
# Only need to make a connection if width and height aren't provided
if 'height' not in self.options or 'width' not in self.options:
self.options['height'] = VIDEO_DEFAULT_HEIGHT
@@ -111,6 +120,7 @@ class Vimeo(Directive):
pass
def check_content(self):
+ """Check if content exists."""
if self.content:
raise self.warning("This directive does not accept content. The "
"'key=value' format for options is deprecated, "
diff --git a/nikola/plugins/compile/rest/youtube.plugin b/nikola/plugins/compile/rest/youtube.plugin
index 01275be..5fbd67b 100644
--- a/nikola/plugins/compile/rest/youtube.plugin
+++ b/nikola/plugins/compile/rest/youtube.plugin
@@ -1,8 +1,12 @@
[Core]
-Name = rest_youtube
-Module = youtube
+name = rest_youtube
+module = youtube
+
+[Nikola]
+compiler = rest
+plugincategory = CompilerExtension
[Documentation]
-Version = 0.1
-Description = Youtube directive
+version = 0.1
+description = Youtube directive
diff --git a/nikola/plugins/compile/rest/youtube.py b/nikola/plugins/compile/rest/youtube.py
index 7c6bba1..6c5c211 100644
--- a/nikola/plugins/compile/rest/youtube.py
+++ b/nikola/plugins/compile/rest/youtube.py
@@ -24,6 +24,8 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+"""YouTube directive for reStructuredText."""
+
from docutils import nodes
from docutils.parsers.rst import Directive, directives
@@ -33,9 +35,12 @@ from nikola.plugin_categories import RestExtension
class Plugin(RestExtension):
+ """Plugin for the youtube directive."""
+
name = "rest_youtube"
def set_site(self, site):
+ """Set Nikola site."""
self.site = site
directives.register_directive('youtube', Youtube)
return super(Plugin, self).set_site(site)
@@ -49,7 +54,8 @@ src="//www.youtube.com/embed/{yid}?rel=0&amp;hd=1&amp;wmode=transparent"
class Youtube(Directive):
- """ Restructured text extension for inserting youtube embedded videos
+
+ """reST extension for inserting youtube embedded videos.
Usage:
.. youtube:: lyViVmaBQDg
@@ -57,6 +63,7 @@ class Youtube(Directive):
:width: 600
"""
+
has_content = True
required_arguments = 1
option_spec = {
@@ -65,6 +72,7 @@ class Youtube(Directive):
}
def run(self):
+ """Run the youtube directive."""
self.check_content()
options = {
'yid': self.arguments[0],
@@ -75,7 +83,8 @@ class Youtube(Directive):
return [nodes.raw('', CODE.format(**options), format='html')]
def check_content(self):
- if self.content:
+ """Check if content exists."""
+ if self.content: # pragma: no cover
raise self.warning("This directive does not accept content. The "
"'key=value' format for options is deprecated, "
"use ':key: value' instead")