diff options
| author | 2014-03-09 03:14:40 +0100 | |
|---|---|---|
| committer | 2014-03-09 03:14:40 +0100 | |
| commit | fa50632a9d87c3989566fed3e49c160a132e0d14 (patch) | |
| tree | 81f58cc0dcfbb34710856b59c034bc47c53d91dc /nikola/plugins/compile | |
| parent | 2828399ba5cbb14502b023d4de1ba02f13dd5055 (diff) | |
Imported Upstream version 6.4.0upstream/6.4.0
Diffstat (limited to 'nikola/plugins/compile')
| -rw-r--r-- | nikola/plugins/compile/asciidoc.py | 11 | ||||
| -rw-r--r-- | nikola/plugins/compile/bbcode.py | 11 | ||||
| -rw-r--r-- | nikola/plugins/compile/html.py | 11 | ||||
| -rw-r--r-- | nikola/plugins/compile/ipynb/__init__.py | 11 | ||||
| -rw-r--r-- | nikola/plugins/compile/markdown/__init__.py | 11 | ||||
| -rw-r--r-- | nikola/plugins/compile/misaka.py | 11 | ||||
| -rw-r--r-- | nikola/plugins/compile/pandoc.py | 11 | ||||
| -rw-r--r-- | nikola/plugins/compile/php.py | 11 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/__init__.py | 43 | ||||
| -rw-r--r-- | nikola/plugins/compile/rest/listing.py | 19 | ||||
| -rw-r--r-- | nikola/plugins/compile/textile.py | 11 | ||||
| -rw-r--r-- | nikola/plugins/compile/txt2tags.py | 11 | ||||
| -rw-r--r-- | nikola/plugins/compile/wiki.py | 11 |
13 files changed, 99 insertions, 84 deletions
diff --git a/nikola/plugins/compile/asciidoc.py b/nikola/plugins/compile/asciidoc.py index 12cb4bf..68f96d9 100644 --- a/nikola/plugins/compile/asciidoc.py +++ b/nikola/plugins/compile/asciidoc.py @@ -40,7 +40,7 @@ from nikola.utils import makedirs, req_missing try: from collections import OrderedDict except ImportError: - OrderedDict = None # NOQA + OrderedDict = dict # NOQA class CompileAsciiDoc(PageCompiler): @@ -57,11 +57,8 @@ class CompileAsciiDoc(PageCompiler): if e.strreror == 'No such file or directory': req_missing(['asciidoc'], 'build this site (compile with asciidoc)', python=False) - def create_post(self, path, onefile=False, **kw): - if OrderedDict is not None: - metadata = OrderedDict() - else: - metadata = {} + def create_post(self, path, onefile=False, is_page=False, **kw): + metadata = OrderedDict() metadata.update(self.default_metadata) metadata.update(kw) makedirs(os.path.dirname(path)) @@ -71,4 +68,4 @@ class CompileAsciiDoc(PageCompiler): for k, v in metadata.items(): fd.write('.. {0}: {1}\n'.format(k, v)) fd.write("/////////////////////////////////////////////\n") - fd.write("\nWrite your post here.") + fd.write("\nWrite your {0} here.".format('page' if is_page else 'post')) diff --git a/nikola/plugins/compile/bbcode.py b/nikola/plugins/compile/bbcode.py index 5345be3..0961ffe 100644 --- a/nikola/plugins/compile/bbcode.py +++ b/nikola/plugins/compile/bbcode.py @@ -40,7 +40,7 @@ from nikola.utils import makedirs, req_missing try: from collections import OrderedDict except ImportError: - OrderedDict = None # NOQA + OrderedDict = dict # NOQA class CompileBbcode(PageCompiler): @@ -66,11 +66,8 @@ class CompileBbcode(PageCompiler): output = self.parser.format(data) out_file.write(output) - def create_post(self, path, onefile=False, **kw): - if OrderedDict is not None: - metadata = OrderedDict() - else: - metadata = {} + def create_post(self, path, onefile=False, is_page=False, **kw): + metadata = OrderedDict() metadata.update(self.default_metadata) metadata.update(kw) makedirs(os.path.dirname(path)) @@ -80,4 +77,4 @@ class CompileBbcode(PageCompiler): for k, v in metadata.items(): fd.write('.. {0}: {1}\n'.format(k, v)) fd.write('-->[/note]\n\n') - fd.write("Write your post here.") + fd.write("Write your {0} here.".format('page' if is_page else 'post')) diff --git a/nikola/plugins/compile/html.py b/nikola/plugins/compile/html.py index 5352f00..09a9756 100644 --- a/nikola/plugins/compile/html.py +++ b/nikola/plugins/compile/html.py @@ -36,7 +36,7 @@ from nikola.utils import makedirs try: from collections import OrderedDict except ImportError: - OrderedDict = None # NOQA + OrderedDict = dict # NOQA _META_SEPARATOR = '(' + os.linesep * 2 + '|' + ('\n' * 2) + '|' + ("\r\n" * 2) + ')' @@ -56,11 +56,8 @@ class CompileHtml(PageCompiler): out_file.write(data) return True - def create_post(self, path, onefile=False, **kw): - if OrderedDict is not None: - metadata = OrderedDict() - else: - metadata = {} + def create_post(self, path, onefile=False, is_page=False, **kw): + metadata = OrderedDict() metadata.update(self.default_metadata) metadata.update(kw) makedirs(os.path.dirname(path)) @@ -70,4 +67,4 @@ class CompileHtml(PageCompiler): for k, v in metadata.items(): fd.write('.. {0}: {1}\n'.format(k, v)) fd.write('-->\n\n') - fd.write("\n<p>Write your post here.</p>\n") + fd.write("\n<p>Write your {0} here.</p>\n".format('page' if is_page else 'post')) diff --git a/nikola/plugins/compile/ipynb/__init__.py b/nikola/plugins/compile/ipynb/__init__.py index 5f2f0b3..2b1fd28 100644 --- a/nikola/plugins/compile/ipynb/__init__.py +++ b/nikola/plugins/compile/ipynb/__init__.py @@ -44,7 +44,7 @@ from nikola.utils import makedirs, req_missing try: from collections import OrderedDict except ImportError: - OrderedDict = None # NOQA + OrderedDict = dict # NOQA class CompileIPynb(PageCompiler): @@ -66,11 +66,8 @@ class CompileIPynb(PageCompiler): (body, resources) = exportHtml.from_notebook_node(nb_json) out_file.write(body) - def create_post(self, path, onefile=False, **kw): - if OrderedDict is not None: - metadata = OrderedDict() - else: - metadata = {} + def create_post(self, path, onefile=False, is_page=False, **kw): + metadata = OrderedDict() metadata.update(self.default_metadata) metadata.update(kw) d_name = os.path.dirname(path) @@ -81,7 +78,7 @@ class CompileIPynb(PageCompiler): metadata['date'], metadata['tags'], metadata['link'], metadata['description'], metadata['type']))) - print("Your post's metadata is at: ", meta_path) + print("Your {0}'s metadata is at: {1}".format('page' if is_page else 'post', meta_path)) with codecs.open(path, "wb+", "utf8") as fd: fd.write("""{ "metadata": { diff --git a/nikola/plugins/compile/markdown/__init__.py b/nikola/plugins/compile/markdown/__init__.py index 1376b11..d0fa66a 100644 --- a/nikola/plugins/compile/markdown/__init__.py +++ b/nikola/plugins/compile/markdown/__init__.py @@ -54,7 +54,7 @@ except ImportError: try: from collections import OrderedDict except ImportError: - OrderedDict = None # NOQA + OrderedDict = dict # NOQA from nikola.plugin_categories import PageCompiler from nikola.utils import makedirs, req_missing @@ -81,11 +81,8 @@ class CompileMarkdown(PageCompiler): output = markdown(data, self.extensions) out_file.write(output) - def create_post(self, path, onefile=False, **kw): - if OrderedDict is not None: - metadata = OrderedDict() - else: - metadata = {} + def create_post(self, path, onefile=False, is_page=False, **kw): + metadata = OrderedDict() metadata.update(self.default_metadata) metadata.update(kw) makedirs(os.path.dirname(path)) @@ -95,4 +92,4 @@ class CompileMarkdown(PageCompiler): for k, v in metadata.items(): fd.write('.. {0}: {1}\n'.format(k, v)) fd.write('-->\n\n') - fd.write("Write your post here.") + fd.write("Write your {0} here.".format('page' if is_page else 'post')) diff --git a/nikola/plugins/compile/misaka.py b/nikola/plugins/compile/misaka.py index 8777ffc..4951c9f 100644 --- a/nikola/plugins/compile/misaka.py +++ b/nikola/plugins/compile/misaka.py @@ -40,7 +40,7 @@ except ImportError: try: from collections import OrderedDict except ImportError: - OrderedDict = None # NOQA + OrderedDict = dict # NOQA gist_extension = None podcast_extension = None @@ -73,11 +73,8 @@ class CompileMisaka(PageCompiler): output = misaka.html(data, extensions=self.ext) out_file.write(output) - def create_post(self, path, onefile=False, **kw): - if OrderedDict is not None: - metadata = OrderedDict() - else: - metadata = {} + def create_post(self, path, onefile=False, is_page=False, **kw): + metadata = OrderedDict() metadata.update(self.default_metadata) metadata.update(kw) makedirs(os.path.dirname(path)) @@ -87,4 +84,4 @@ class CompileMisaka(PageCompiler): for k, v in metadata.items(): fd.write('.. {0}: {1}\n'.format(k, v)) fd.write('-->\n\n') - fd.write("\nWrite your post here.") + fd.write("\nWrite your {0} here.".format('page' if is_page else 'post')) diff --git a/nikola/plugins/compile/pandoc.py b/nikola/plugins/compile/pandoc.py index 57c7d71..654c7c8 100644 --- a/nikola/plugins/compile/pandoc.py +++ b/nikola/plugins/compile/pandoc.py @@ -40,7 +40,7 @@ from nikola.utils import req_missing, makedirs try: from collections import OrderedDict except ImportError: - OrderedDict = None # NOQA + OrderedDict = dict # NOQA class CompilePandoc(PageCompiler): @@ -56,11 +56,8 @@ class CompilePandoc(PageCompiler): if e.strreror == 'No such file or directory': req_missing(['pandoc'], 'build this site (compile with pandoc)', python=False) - def create_post(self, path, onefile=False, **kw): - if OrderedDict is not None: - metadata = OrderedDict() - else: - metadata = {} + def create_post(self, path, onefile=False, is_page=False, **kw): + metadata = OrderedDict() metadata.update(self.default_metadata) metadata.update(kw) makedirs(os.path.dirname(path)) @@ -70,4 +67,4 @@ class CompilePandoc(PageCompiler): for k, v in metadata.items(): fd.write('.. {0}: {1}\n'.format(k, v)) fd.write('-->\n\n') - fd.write("Write your post here.") + fd.write("Write your {0} here.".format('page' if is_page else 'post')) diff --git a/nikola/plugins/compile/php.py b/nikola/plugins/compile/php.py index 14b80e8..0a652a6 100644 --- a/nikola/plugins/compile/php.py +++ b/nikola/plugins/compile/php.py @@ -38,7 +38,7 @@ from nikola.utils import makedirs try: from collections import OrderedDict except ImportError: - OrderedDict = None # NOQA + OrderedDict = dict # NOQA class CompilePhp(PageCompiler): @@ -50,11 +50,8 @@ class CompilePhp(PageCompiler): makedirs(os.path.dirname(dest)) shutil.copyfile(source, dest) - def create_post(self, path, onefile=False, **kw): - if OrderedDict is not None: - metadata = OrderedDict() - else: - metadata = {} + def create_post(self, path, onefile=False, is_page=False, **kw): + metadata = OrderedDict() metadata.update(self.default_metadata) metadata.update(kw) os.makedirs(os.path.dirname(path)) @@ -64,7 +61,7 @@ class CompilePhp(PageCompiler): for k, v in metadata.items(): fd.write('.. {0}: {1}\n'.format(k, v)) fd.write('-->\n\n') - fd.write("\n<p>Write your post here.</p>") + fd.write("\n<p>Write your {0} here.</p>".format('page' if is_page else 'post')) def extension(self): return ".php" diff --git a/nikola/plugins/compile/rest/__init__.py b/nikola/plugins/compile/rest/__init__.py index 50b37cf..9a4e19b 100644 --- a/nikola/plugins/compile/rest/__init__.py +++ b/nikola/plugins/compile/rest/__init__.py @@ -43,7 +43,7 @@ except ImportError: try: from collections import OrderedDict except ImportError: - OrderedDict = None # NOQA + OrderedDict = dict # NOQA from nikola.plugin_categories import PageCompiler from nikola.utils import get_logger, makedirs, req_missing @@ -102,11 +102,8 @@ class CompileRest(PageCompiler): else: return False - def create_post(self, path, onefile=False, **kw): - if OrderedDict is not None: - metadata = OrderedDict() - else: - metadata = {} + def create_post(self, path, onefile=False, is_page=False, **kw): + metadata = OrderedDict() metadata.update(self.default_metadata) metadata.update(kw) makedirs(os.path.dirname(path)) @@ -114,7 +111,7 @@ class CompileRest(PageCompiler): if onefile: for k, v in metadata.items(): fd.write('.. {0}: {1}\n'.format(k, v)) - fd.write("\nWrite your post here.") + fd.write("\nWrite your {0} here.".format('page' if is_page else 'post')) def set_site(self, site): for plugin_info in site.plugin_manager.getPluginsOfCategory("RestExtension"): @@ -174,6 +171,38 @@ class NikolaReader(docutils.readers.standalone.Reader): def add_node(node, visit_function=None, depart_function=None): + """ + 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>`_. + + For example:: + + class Plugin(RestExtension): + + name = "rest_math" + + def set_site(self, site): + self.site = site + directives.register_directive('math', MathDirective) + add_node(MathBlock, visit_Math, depart_Math) + return super(Plugin, self).set_site(site) + + class MathDirective(Directive): + def run(self): + node = MathBlock() + return [node] + + class Math(docutils.nodes.Element): pass + + def visit_Math(self, node): + self.body.append(self.starttag(node, 'math')) + + def depart_Math(self, node): + self.body.append('</math>') + + For full example, you can refer to `Microdata plugin <http://plugins.getnikola.com/#microdata>`_ + """ docutils.nodes._add_node_class_names([node.__name__]) if visit_function: setattr(docutils.writers.html4css1.HTMLTranslator, 'visit_' + node.__name__, visit_function) diff --git a/nikola/plugins/compile/rest/listing.py b/nikola/plugins/compile/rest/listing.py index ecf885f..d70e02d 100644 --- a/nikola/plugins/compile/rest/listing.py +++ b/nikola/plugins/compile/rest/listing.py @@ -56,6 +56,18 @@ except ImportError: # docutils < 0.9 (Debian Sid For The Loss) from nikola.plugin_categories import RestExtension +# Add sphinx compatibility option +CodeBlock.option_spec['linenos'] = directives.unchanged + + +class FlexibleCodeBlock(CodeBlock): + + def run(self): + if 'linenos' in self.options: + self.options['number-lines'] = self.options['linenos'] + return super(FlexibleCodeBlock, self).run() +CodeBlock = FlexibleCodeBlock + class Plugin(RestExtension): @@ -71,6 +83,10 @@ class Plugin(RestExtension): directives.register_directive('listing', Listing) return super(Plugin, self).set_site(site) +# Add sphinx compatibility option +listing_spec = Include.option_spec +listing_spec['linenos'] = directives.unchanged + class Listing(Include): """ listing directive: create a highlighted block of code from a file in listings/ @@ -84,6 +100,7 @@ class Listing(Include): has_content = False required_arguments = 1 optional_arguments = 1 + option_spec = listing_spec def run(self): fname = self.arguments.pop(0) @@ -91,6 +108,8 @@ class Listing(Include): fpath = os.path.join('listings', fname) self.arguments.insert(0, fpath) self.options['code'] = lang + if 'linenos' in self.options: + self.options['number-lines'] = self.options['linenos'] with codecs_open(fpath, 'rb+', 'utf8') as fileobject: self.content = fileobject.read().splitlines() self.state.document.settings.record_dependencies.add(fpath) diff --git a/nikola/plugins/compile/textile.py b/nikola/plugins/compile/textile.py index 73f35c0..1679831 100644 --- a/nikola/plugins/compile/textile.py +++ b/nikola/plugins/compile/textile.py @@ -41,7 +41,7 @@ from nikola.utils import makedirs, req_missing try: from collections import OrderedDict except ImportError: - OrderedDict = None # NOQA + OrderedDict = dict # NOQA class CompileTextile(PageCompiler): @@ -62,11 +62,8 @@ class CompileTextile(PageCompiler): output = textile(data, head_offset=1) out_file.write(output) - def create_post(self, path, onefile=False, **kw): - if OrderedDict is not None: - metadata = OrderedDict() - else: - metadata = {} + def create_post(self, path, onefile=False, is_page=False, **kw): + metadata = OrderedDict() metadata.update(self.default_metadata) metadata.update(kw) makedirs(os.path.dirname(path)) @@ -76,4 +73,4 @@ class CompileTextile(PageCompiler): for k, v in metadata.items(): fd.write('.. {0}: {1}\n'.format(k, v)) fd.write('--></notextile>\n\n') - fd.write("\nWrite your post here.") + fd.write("\nWrite your {0} here.".format('page' if is_page else 'post')) diff --git a/nikola/plugins/compile/txt2tags.py b/nikola/plugins/compile/txt2tags.py index 8c9724e..bb6afa5 100644 --- a/nikola/plugins/compile/txt2tags.py +++ b/nikola/plugins/compile/txt2tags.py @@ -43,7 +43,7 @@ except ImportError: try: from collections import OrderedDict except ImportError: - OrderedDict = None # NOQA + OrderedDict = dict # NOQA from nikola.plugin_categories import PageCompiler from nikola.utils import makedirs, req_missing @@ -62,11 +62,8 @@ class CompileTxt2tags(PageCompiler): cmd = ["-t", "html", "--no-headers", "--outfile", dest, source] txt2tags(cmd) - def create_post(self, path, onefile=False, **kw): - if OrderedDict is not None: - metadata = OrderedDict() - else: - metadata = {} + def create_post(self, path, onefile=False, is_page=False, **kw): + metadata = OrderedDict() metadata.update(self.default_metadata) metadata.update(kw) makedirs(os.path.dirname(path)) @@ -76,4 +73,4 @@ class CompileTxt2tags(PageCompiler): for k, v in metadata.items(): fd.write('.. {0}: {1}\n'.format(k, v)) fd.write("-->\n'''\n") - fd.write("\nWrite your post here.") + fd.write("\nWrite your {0} here.".format('page' if is_page else 'post')) diff --git a/nikola/plugins/compile/wiki.py b/nikola/plugins/compile/wiki.py index 9a365fa..f4858c7 100644 --- a/nikola/plugins/compile/wiki.py +++ b/nikola/plugins/compile/wiki.py @@ -40,7 +40,7 @@ from nikola.plugin_categories import PageCompiler try: from collections import OrderedDict except ImportError: - OrderedDict = None # NOQA + OrderedDict = dict # NOQA from nikola.utils import makedirs, req_missing @@ -62,11 +62,8 @@ class CompileWiki(PageCompiler): output = HtmlEmitter(document).emit() out_file.write(output) - def create_post(self, path, onefile=False, **kw): - if OrderedDict is not None: - metadata = OrderedDict() - else: - metadata = {} + def create_post(self, path, onefile=False, is_page=False, **kw): + metadata = OrderedDict() metadata.update(self.default_metadata) metadata.update(kw) makedirs(os.path.dirname(path)) @@ -75,4 +72,4 @@ class CompileWiki(PageCompiler): 'one-file format is not possible, use the -2 ' 'option.') with codecs.open(path, "wb+", "utf8") as fd: - fd.write("Write your post here.") + fd.write("Write your {0} here.".format('page' if is_page else 'post')) |
