summaryrefslogtreecommitdiffstats
path: root/nikola/plugins/task/mustache
diff options
context:
space:
mode:
authorLibravatarAgustin Henze <tin@sluc.org.ar>2014-06-13 21:51:02 -0300
committerLibravatarAgustin Henze <tin@sluc.org.ar>2014-06-13 21:51:02 -0300
commit58c4878526dec5510f23c812274686787d8724ba (patch)
tree5f2374bc17adb10e15f7e5b4576595d9cc2ef17e /nikola/plugins/task/mustache
parentfa50632a9d87c3989566fed3e49c160a132e0d14 (diff)
Imported Upstream version 7.0.1upstream/7.0.1
Diffstat (limited to 'nikola/plugins/task/mustache')
-rw-r--r--nikola/plugins/task/mustache/__init__.py184
-rw-r--r--nikola/plugins/task/mustache/mustache-template.html29
-rw-r--r--nikola/plugins/task/mustache/mustache.html34
3 files changed, 0 insertions, 247 deletions
diff --git a/nikola/plugins/task/mustache/__init__.py b/nikola/plugins/task/mustache/__init__.py
deleted file mode 100644
index 5be98f0..0000000
--- a/nikola/plugins/task/mustache/__init__.py
+++ /dev/null
@@ -1,184 +0,0 @@
-# -*- coding: utf-8 -*-
-
-# Copyright © 2012-2014 Roberto Alsina and others.
-
-# Permission is hereby granted, free of charge, to any
-# person obtaining a copy of this software and associated
-# documentation files (the "Software"), to deal in the
-# Software without restriction, including without limitation
-# the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the
-# Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice
-# shall be included in all copies or substantial portions of
-# the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
-# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
-# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
-# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
-# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-# 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.
-
-from __future__ import unicode_literals
-
-import codecs
-import json
-import os
-
-from nikola.plugin_categories import Task
-from nikola.utils import (
- config_changed, copy_file, LocaleBorg, makedirs, unicode_str,
-)
-
-
-class Mustache(Task):
- """Render the blog posts as JSON data."""
-
- name = "render_mustache"
-
- def gen_tasks(self):
- self.site.scan_posts()
-
- kw = {
- "translations": self.site.config['TRANSLATIONS'],
- "index_display_post_count":
- self.site.config['INDEX_DISPLAY_POST_COUNT'],
- "messages": self.site.MESSAGES,
- "index_teasers": self.site.config['INDEX_TEASERS'],
- "output_folder": self.site.config['OUTPUT_FOLDER'],
- "filters": self.site.config['FILTERS'],
- "blog_title": self.site.config['BLOG_TITLE'],
- "content_footer": self.site.config['CONTENT_FOOTER'],
- }
-
- # TODO: timeline is global, get rid of it
- posts = [x for x in self.site.timeline if x.use_in_feeds]
- if not posts:
- yield {
- 'basename': 'render_mustache',
- 'actions': [],
- }
- return
-
- def write_file(path, post, lang):
-
- # Prev/Next links
- prev_link = False
- if post.prev_post:
- prev_link = post.prev_post.permalink(lang).replace(".html",
- ".json")
- next_link = False
- if post.next_post:
- next_link = post.next_post.permalink(lang).replace(".html",
- ".json")
- data = {}
-
- # Configuration
- for k, v in self.site.config.items():
- if isinstance(v, (str, unicode_str)): # NOQA
- data[k] = v
-
- # Tag data
- tags = []
- for tag in post.tags:
- tags.append({'name': tag, 'link': self.site.link("tag", tag,
- lang)})
- data.update({
- "tags": tags,
- "tags?": True if tags else False,
- })
-
- # Template strings
- for k, v in kw["messages"][lang].items():
- data["message_" + k] = v
-
- # Post data
- data.update({
- "title": post.title(lang),
- "text": post.text(lang),
- "prev": prev_link,
- "next": next_link,
- "date":
- post.date.strftime(self.site.GLOBAL_CONTEXT['date_format']),
- })
-
- # Comments
- context = dict(post=post, lang=LocaleBorg().current_lang)
- context.update(self.site.GLOBAL_CONTEXT)
- data["comment_html"] = self.site.template_system.render_template(
- 'mustache-comment-form.tmpl', None, context).strip()
-
- # Post translations
- translations = []
- for langname in kw["translations"]:
- if langname == lang:
- continue
- translations.append({'name':
- kw["messages"][langname]["Read in English"],
- 'link': "javascript:load_data('%s');"
- % post.permalink(langname).replace(
- ".html", ".json")})
- data["translations"] = translations
-
- makedirs(os.path.dirname(path))
- with codecs.open(path, 'wb+', 'utf8') as fd:
- fd.write(json.dumps(data))
-
- for lang in kw["translations"]:
- for i, post in enumerate(posts):
- out_path = post.destination_path(lang, ".json")
- out_file = os.path.join(kw['output_folder'], out_path)
- task = {
- 'basename': 'render_mustache',
- 'name': out_file,
- 'file_dep': post.fragment_deps(lang),
- 'targets': [out_file],
- 'actions': [(write_file, (out_file, post, lang))],
- 'task_dep': ['render_posts'],
- 'uptodate': [config_changed({
- 1: post.text(lang),
- 2: post.prev_post,
- 3: post.next_post,
- 4: post.title(lang),
- })]
- }
- yield task
-
- if posts:
- first_post_data = posts[0].permalink(
- self.site.config["DEFAULT_LANG"]).replace(".html", ".json")
-
- # Copy mustache template
- src = os.path.join(os.path.dirname(__file__), 'mustache-template.html')
- dst = os.path.join(kw['output_folder'], 'mustache-template.html')
- yield {
- 'basename': 'render_mustache',
- 'name': dst,
- 'targets': [dst],
- 'file_dep': [src],
- 'actions': [(copy_file, (src, dst))],
- }
-
- # Copy mustache.html with the right starting file in it
- src = os.path.join(os.path.dirname(__file__), 'mustache.html')
- dst = os.path.join(kw['output_folder'], 'mustache.html')
-
- def copy_mustache():
- with codecs.open(src, 'rb', 'utf8') as in_file:
- with codecs.open(dst, 'wb+', 'utf8') as out_file:
- data = in_file.read().replace('{{first_post_data}}',
- first_post_data)
- out_file.write(data)
- yield {
- 'basename': 'render_mustache',
- 'name': dst,
- 'targets': [dst],
- 'file_dep': [src],
- 'uptodate': [config_changed({1: first_post_data})],
- 'actions': [(copy_mustache, [])],
- }
diff --git a/nikola/plugins/task/mustache/mustache-template.html b/nikola/plugins/task/mustache/mustache-template.html
deleted file mode 100644
index e9a0213..0000000
--- a/nikola/plugins/task/mustache/mustache-template.html
+++ /dev/null
@@ -1,29 +0,0 @@
-<script id="view" type="text/html">
-<div class="container" id="container">
- <div class="postbox">
- <h1>{{BLOG_TITLE}}</h1>
- <hr>
- <h2>{{title}}</h2>
- Posted on: {{date}}</br>
- {{#tags?}} More posts about:
- {{#tags}}<a class="tag" href={{link}}><span class="badge badge-info">{{name}}</span></a>{{/tags}}
- </br>
- {{/tags?}}
- {{#translations}}<a href={{link}}>{{name}}</a>{{/translations}}&nbsp;</br>
- <hr>
- {{{text}}}
- <ul class="pager">
- {{#prev}}
- <li class="previous"><a href="javascript:load_data('{{prev}}')">{{message_Previous post}}</a></li>
- {{/prev}}
- {{#next}}
- <li class="next"><a href="javascript:load_data('{{next}}')">{{message_Next post}}</a></li>
- {{/next}}
- </ul>
- {{{comment_html}}}
- </div>
- <div class="footerbox">
- {{{CONTENT_FOOTER}}}
- </div>
-</div>
-</script>
diff --git a/nikola/plugins/task/mustache/mustache.html b/nikola/plugins/task/mustache/mustache.html
deleted file mode 100644
index 7ff6312..0000000
--- a/nikola/plugins/task/mustache/mustache.html
+++ /dev/null
@@ -1,34 +0,0 @@
-<head>
- <link href="/assets/css/bootstrap.css" rel="stylesheet" type="text/css">
- <link href="/assets/css/bootstrap-responsive.css" rel="stylesheet" type="text/css">
- <link href="/assets/css/rst.css" rel="stylesheet" type="text/css">
- <link href="/assets/css/code.css" rel="stylesheet" type="text/css">
- <link href="/assets/css/colorbox.css" rel="stylesheet" type="text/css"/>
- <link href="/assets/css/theme.css" rel="stylesheet" type="text/css"/>
- <link href="/assets/css/custom.css" rel="stylesheet" type="text/css">
- <script src="/assets/js/jquery-1.10.2.min.js" type="text/javascript"></script>
- <script src="//cdn.jsdelivr.net/jquery.mustache/0.2.7/jquery.mustache.js"></script>
- <script src="//cdn.jsdelivr.net/mustache.js/0.7.2/mustache.js"></script>
- <script src="/assets/js/jquery.colorbox-min.js" type="text/javascript"></script>
- <script type="text/javascript">
-function load_data(dataurl) {
- jQuery.getJSON(dataurl, function(data) {
- $('body').mustache('view', data, { method: 'html' });
- window.location.hash = '#' + dataurl;
- })
-};
-$(document).ready(function() {
-$.Mustache.load('/mustache-template.html')
- .done(function () {
- if (window.location.hash != '') {
- load_data(window.location.hash.slice(1));
- }
- else {
- load_data('{{first_post_data}}');
- };
- })
-});
-</script>
-</head>
-<body style="padding-top: 0;">
-</body>