add partials support
This commit is contained in:
parent
036434dd7a
commit
bea662e2e7
|
@ -9,7 +9,7 @@ add-apt-repository -y ppa:chris-lea/node.js
|
|||
apt-get update
|
||||
apt-get install -y python build-essential git libpcre3-dev python-software-properties \
|
||||
python-pip python-virtualenv python-dev pkg-config curl libxml2-dev libxslt1-dev zlib1g-dev \
|
||||
libffi-dev nodejs screen node-cleancss
|
||||
libffi-dev nodejs screen node-cleancss libyaml-dev
|
||||
|
||||
# Default cache is memoization
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import lxml.html
|
|||
from lxml.html.clean import Cleaner
|
||||
import ghdiff
|
||||
import gittle.utils
|
||||
import yaml
|
||||
from gittle import Gittle
|
||||
from dulwich.repo import NotGitRepository
|
||||
from werkzeug.utils import escape, unescape
|
||||
|
@ -105,6 +106,9 @@ class Wiki():
|
|||
content = re.sub(r"(\n>)", "\n>", content)
|
||||
content = re.sub(r"(^>)", ">", content)
|
||||
|
||||
# Handlebars partial ">"
|
||||
content = re.sub(r"\{\{>(.*?)\}\}", r'{{>\1}}', content)
|
||||
|
||||
content = re.sub(r"```(.*?)```", unescape_repl, content, flags=re.DOTALL)
|
||||
|
||||
cname = to_canonical(name)
|
||||
|
@ -157,6 +161,15 @@ class Wiki():
|
|||
# HEAD doesn't exist yet
|
||||
return None
|
||||
|
||||
def get_meta(self, content):
|
||||
if not content.startswith("---"):
|
||||
return None
|
||||
meta_end = re.search("\n(\.{3}|\-{3})", content)
|
||||
if not meta_end:
|
||||
return None
|
||||
return yaml.safe_load(content[0:meta_end.start()])
|
||||
#return [content[0:meta_end.start()], content[meta_end.end():]]
|
||||
|
||||
def compare(self, name, old_sha, new_sha):
|
||||
old = self.get_page(name, sha=old_sha)
|
||||
new = self.get_page(name, sha=new_sha)
|
||||
|
|
|
@ -60,10 +60,15 @@ def edit(name):
|
|||
username=current_user.username)
|
||||
else:
|
||||
if data:
|
||||
partials = {}
|
||||
meta = wiki.get_meta(data['data'])
|
||||
if meta and 'import' in meta:
|
||||
for partial_name in meta['import']:
|
||||
partials[partial_name] = wiki.get_page(partial_name)
|
||||
name = remove_ext(data['name'])
|
||||
content = data['data']
|
||||
g.assets['js'].append('editor.js')
|
||||
return render_template('wiki/edit.html', name=name, content=content)
|
||||
return render_template('wiki/edit.html', name=name, content=content, partials=partials)
|
||||
else:
|
||||
return redirect(url_for('wiki.create', name=cname))
|
||||
|
||||
|
@ -102,8 +107,14 @@ def page(name):
|
|||
return redirect(url_for('wiki.page', name=cname))
|
||||
|
||||
data = wiki.get_page(cname)
|
||||
meta = wiki.get_meta(data['data'])
|
||||
|
||||
partials = {}
|
||||
if meta and 'import' in meta:
|
||||
for partial_name in meta['import']:
|
||||
partials[partial_name] = wiki.get_page(partial_name)
|
||||
|
||||
if data:
|
||||
return render_template('wiki/page.html', name=cname, page=data)
|
||||
return render_template('wiki/page.html', name=cname, page=data, partials=partials)
|
||||
else:
|
||||
return redirect(url_for('wiki.create', name=cname))
|
|
@ -1,3 +1,9 @@
|
|||
// Handlebar helpers
|
||||
Handlebars.registerHelper('well', function(options) {
|
||||
return '<div class="well">' + options.fn(this) + '</div>';
|
||||
});
|
||||
|
||||
Handlebars.registerPartial('item', '<table class="table table-bordered"><tr><td>{{ name }}<td><td></tr></table>')
|
||||
/* © 2013 j201
|
||||
* https://github.com/j201/meta-marked */
|
||||
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
{% block js %}
|
||||
<script>
|
||||
$(function(){
|
||||
{% if partials %}
|
||||
{% for name, value in partials.items() %}
|
||||
Handlebars.registerPartial({{ name|tojson|safe }}, {{ value.data|tojson|safe }});
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
$("#start-togetherjs").click(function(){
|
||||
$(this).prop('disabled', true).html("Loading");
|
||||
});
|
||||
|
|
|
@ -24,6 +24,11 @@
|
|||
{% block js %}
|
||||
<script>
|
||||
$(function(){
|
||||
{% if partials %}
|
||||
{% for name, value in partials.items() %}
|
||||
Handlebars.registerPartial({{ name|tojson|safe }}, {{ value.data|tojson|safe }});
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
$("#page-content").html(MDR.convert({{ page.data|tojson|safe }})).show();
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -14,3 +14,4 @@ itsdangerous
|
|||
lxml
|
||||
markdown2
|
||||
simplejson
|
||||
PyYAML
|
||||
|
|
Loading…
Reference in a new issue