diff --git a/install.sh b/install.sh index 5e843a0..b742b27 100644 --- a/install.sh +++ b/install.sh @@ -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 diff --git a/realms/modules/wiki/models.py b/realms/modules/wiki/models.py index de129ec..273999f 100644 --- a/realms/modules/wiki/models.py +++ b/realms/modules/wiki/models.py @@ -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) diff --git a/realms/modules/wiki/views.py b/realms/modules/wiki/views.py index f5c576c..3a5ed57 100644 --- a/realms/modules/wiki/views.py +++ b/realms/modules/wiki/views.py @@ -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)) \ No newline at end of file diff --git a/realms/static/js/main.js b/realms/static/js/main.js index e565661..1b9ad9c 100644 --- a/realms/static/js/main.js +++ b/realms/static/js/main.js @@ -1,3 +1,9 @@ +// Handlebar helpers +Handlebars.registerHelper('well', function(options) { + return '
{{ name }} |