add partials support
This commit is contained in:
		
							parent
							
								
									036434dd7a
								
							
						
					
					
						commit
						bea662e2e7
					
				
					 7 changed files with 44 additions and 3 deletions
				
			
		| 
						 | 
					@ -9,7 +9,7 @@ add-apt-repository -y ppa:chris-lea/node.js
 | 
				
			||||||
apt-get update
 | 
					apt-get update
 | 
				
			||||||
apt-get install -y python build-essential git libpcre3-dev python-software-properties \
 | 
					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 \
 | 
					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
 | 
					# Default cache is memoization
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,6 +4,7 @@ import lxml.html
 | 
				
			||||||
from lxml.html.clean import Cleaner
 | 
					from lxml.html.clean import Cleaner
 | 
				
			||||||
import ghdiff
 | 
					import ghdiff
 | 
				
			||||||
import gittle.utils
 | 
					import gittle.utils
 | 
				
			||||||
 | 
					import yaml
 | 
				
			||||||
from gittle import Gittle
 | 
					from gittle import Gittle
 | 
				
			||||||
from dulwich.repo import NotGitRepository
 | 
					from dulwich.repo import NotGitRepository
 | 
				
			||||||
from werkzeug.utils import escape, unescape
 | 
					from werkzeug.utils import escape, unescape
 | 
				
			||||||
| 
						 | 
					@ -105,6 +106,9 @@ class Wiki():
 | 
				
			||||||
        content = re.sub(r"(\n>)", "\n>", content)
 | 
					        content = re.sub(r"(\n>)", "\n>", content)
 | 
				
			||||||
        content = re.sub(r"(^>)", ">", 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)
 | 
					        content = re.sub(r"```(.*?)```", unescape_repl, content, flags=re.DOTALL)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        cname = to_canonical(name)
 | 
					        cname = to_canonical(name)
 | 
				
			||||||
| 
						 | 
					@ -157,6 +161,15 @@ class Wiki():
 | 
				
			||||||
            # HEAD doesn't exist yet
 | 
					            # HEAD doesn't exist yet
 | 
				
			||||||
            return None
 | 
					            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):
 | 
					    def compare(self, name, old_sha, new_sha):
 | 
				
			||||||
        old = self.get_page(name, sha=old_sha)
 | 
					        old = self.get_page(name, sha=old_sha)
 | 
				
			||||||
        new = self.get_page(name, sha=new_sha)
 | 
					        new = self.get_page(name, sha=new_sha)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -60,10 +60,15 @@ def edit(name):
 | 
				
			||||||
                        username=current_user.username)
 | 
					                        username=current_user.username)
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        if data:
 | 
					        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'])
 | 
					            name = remove_ext(data['name'])
 | 
				
			||||||
            content = data['data']
 | 
					            content = data['data']
 | 
				
			||||||
            g.assets['js'].append('editor.js')
 | 
					            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:
 | 
					        else:
 | 
				
			||||||
            return redirect(url_for('wiki.create', name=cname))
 | 
					            return redirect(url_for('wiki.create', name=cname))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -102,8 +107,14 @@ def page(name):
 | 
				
			||||||
        return redirect(url_for('wiki.page', name=cname))
 | 
					        return redirect(url_for('wiki.page', name=cname))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    data = wiki.get_page(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:
 | 
					    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:
 | 
					    else:
 | 
				
			||||||
        return redirect(url_for('wiki.create', name=cname))
 | 
					        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
 | 
					/* © 2013 j201
 | 
				
			||||||
 * https://github.com/j201/meta-marked */
 | 
					 * https://github.com/j201/meta-marked */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,11 @@
 | 
				
			||||||
{% block js %}
 | 
					{% block js %}
 | 
				
			||||||
 <script>
 | 
					 <script>
 | 
				
			||||||
    $(function(){
 | 
					    $(function(){
 | 
				
			||||||
 | 
					      {% if partials %}
 | 
				
			||||||
 | 
					        {% for name, value in partials.items() %}
 | 
				
			||||||
 | 
					          Handlebars.registerPartial({{ name|tojson|safe }}, {{ value.data|tojson|safe }});
 | 
				
			||||||
 | 
					        {% endfor %}
 | 
				
			||||||
 | 
					      {% endif %}
 | 
				
			||||||
        $("#start-togetherjs").click(function(){
 | 
					        $("#start-togetherjs").click(function(){
 | 
				
			||||||
            $(this).prop('disabled', true).html("Loading");
 | 
					            $(this).prop('disabled', true).html("Loading");
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,11 @@
 | 
				
			||||||
{% block js %}
 | 
					{% block js %}
 | 
				
			||||||
  <script>
 | 
					  <script>
 | 
				
			||||||
    $(function(){
 | 
					    $(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();
 | 
					      $("#page-content").html(MDR.convert({{ page.data|tojson|safe }})).show();
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  </script>
 | 
					  </script>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,3 +14,4 @@ itsdangerous
 | 
				
			||||||
lxml
 | 
					lxml
 | 
				
			||||||
markdown2
 | 
					markdown2
 | 
				
			||||||
simplejson
 | 
					simplejson
 | 
				
			||||||
 | 
					PyYAML
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue