diff --git a/reimagine/__init__.py b/reimagine/__init__.py index c9fa6c1..84f5920 100644 --- a/reimagine/__init__.py +++ b/reimagine/__init__.py @@ -35,7 +35,7 @@ from models import Site site = Site.get_by_name(".") -wiki = Wiki(site.get('repo')) +w = Wiki(site.get('repo')) def redirect_url(): @@ -65,10 +65,13 @@ def rename(page): @app.route("/edit/", methods=['GET', 'POST']) def edit(page): - pass + data = w.get_page(page) + if data: + return render_template('page/edit.html', page=data) + else: + return redirect('/create/'+page) - -@app.route("/delete/") +@app.route("/delete/", methods=['POST']) def delete(page): pass @@ -80,12 +83,9 @@ def create(page): @app.route("/") def render(page): - file_path = site.get('repo') + "/" + page.lower() + ".md" - if path.isfile(file_path): - f = open(file_path) - content = f.read() - f.close() - return render_template('page/page.html', content=content) + data = w.get_page(page) + if data: + return render_template('page/page.html', page=data) else: return redirect('/create/'+page) diff --git a/reimagine/templates/page/page.html b/reimagine/templates/page/page.html index 4e33b04..bf00042 100644 --- a/reimagine/templates/page/page.html +++ b/reimagine/templates/page/page.html @@ -1,6 +1,6 @@ {% extends 'layout.html' %} {% block body %} -{{ content }} +{{ page.data }} {% endblock %} \ No newline at end of file diff --git a/reimagine/wiki.py b/reimagine/wiki.py index ebb8feb..f23cca3 100644 --- a/reimagine/wiki.py +++ b/reimagine/wiki.py @@ -1,6 +1,7 @@ from gittle import Gittle import os + class Wiki(): path = None base_path = '/' @@ -8,9 +9,11 @@ class Wiki(): default_committer_name = 'Anon' default_committer_email = 'anon@anon.anon' index_page = 'Home' + repo = None def __init__(self, path, **kwargs): self.path = path + self.repo = Gittle(path) def write_page(self, name): name = name.replace(" ", "-") @@ -18,5 +21,6 @@ class Wiki(): def rename_page(self, page, rename, commit={}): pass - def page_exists(self, name): - return None \ No newline at end of file + def get_page(self, name): + name = name.lower() + ".md" + return self.repo.get_commit_files('HEAD', paths=[name]).get(name) \ No newline at end of file