Add index page resolves #23 and #8

This commit is contained in:
Matthew Scragg 2014-10-09 15:47:12 -05:00
parent 992cfb96d2
commit 672856e9af
6 changed files with 54 additions and 10 deletions

View file

@ -14,6 +14,8 @@
"js-yaml": "~3.2.1",
"store-js": "~1.3.16",
"bootswatch-dist": "3.2.0-flatly",
"bootbox": "4.3.0"
"bootbox": "4.3.0",
"datatables": "1.10.3",
"datatables-plugins": "latest"
}
}

View file

@ -81,11 +81,15 @@ def setup_redis(**kw):
install_redis()
def get_prefix():
import sys
return sys.prefix
def get_pip():
""" Get virtualenv path for pip
"""
import sys
return sys.prefix + '/bin/pip'
return get_prefix() + '/bin/pip'
@cli.command()
@ -173,6 +177,13 @@ def drop_db():
db.drop_all()
@cli.command()
def test():
""" Run tests
"""
call([get_prefix() + "/bin/nosetests", config.APP_PATH])
@cli.command()
def version():
""" Output version

View file

@ -206,6 +206,8 @@ assets.register('main.js',
'js/html-sanitizer-minified.js', # don't minify?
'vendor/highlightjs/highlight.pack.js',
'vendor/parsleyjs/dist/parsley.js',
'vendor/datatables/media/js/jquery.dataTables.js',
'vendor/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.js',
'js/hbs-helpers.js',
'js/mdr.js')
@ -213,6 +215,7 @@ assets.register('main.css',
'vendor/bootswatch-dist/css/bootstrap.css',
'vendor/components-font-awesome/css/font-awesome.css',
'vendor/highlightjs/styles/github.css',
'vendor/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css',
'css/style.css')
app.discover()

View file

@ -13,6 +13,16 @@ from realms import cache
from realms.lib.hook import HookMixin
def cname_to_filename(cname):
return cname.lower() + ".md"
def filename_to_cname(filename):
""" It's assumed filename is already cname format
"""
return os.path.splitext(filename)[0]
class Wiki(HookMixin):
path = None
base_path = '/'
@ -87,7 +97,7 @@ class Wiki(HookMixin):
content = re.sub(r"```(.*?)```", unescape_repl, content, flags=re.DOTALL)
filename = self.cname_to_filename(cname)
filename = cname_to_filename(cname)
with open(self.path + "/" + filename, 'w') as f:
f.write(content)
@ -113,7 +123,7 @@ class Wiki(HookMixin):
return ret
def rename_page(self, old_name, new_name, user=None):
old_filename, new_filename = map(self.cname_to_filename, [old_name, new_name])
old_filename, new_filename = map(cname_to_filename, [old_name, new_name])
if old_filename not in self.gittle.index:
# old doesn't exist
return None
@ -140,7 +150,7 @@ class Wiki(HookMixin):
return cached
# commit = gittle.utils.git.commit_info(self.repo[sha])
filename = self.cname_to_filename(name).encode('latin-1')
filename = cname_to_filename(name).encode('latin-1')
sha = sha.encode('latin-1')
try:
@ -177,8 +187,21 @@ class Wiki(HookMixin):
new = self.get_page(name, sha=new_sha)
return ghdiff.diff(old['data'], new['data'])
def get_index(self):
rv = []
index = self.repo.open_index()
for name in index:
rv.append(dict(name=filename_to_cname(name),
filename=name,
ctime=index[name].ctime[0],
mtime=index[name].mtime[0],
sha=index[name].sha,
size=index[name].size))
return rv
def get_history(self, name, limit=100):
file_path = self.cname_to_filename(name)
file_path = cname_to_filename(name)
versions = []
walker = self.repo.get_walker(paths=[file_path], max_entries=limit)
for entry in walker:
@ -198,6 +221,3 @@ class Wiki(HookMixin):
return versions
@staticmethod
def cname_to_filename(cname):
return cname.lower() + ".md"

View file

@ -121,6 +121,11 @@ def create(name):
info={})
@blueprint.route("/_index")
def index():
return render_template('wiki/index.html', index=g.current_wiki.get_index())
@blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<name>")
def page(name):

View file

@ -40,6 +40,9 @@
</div>
<div class="navbar-collapse collapse navbar-inverse-collapse">
<ul class="nav navbar-nav">
{% if config.get('ROOT_ENDPOINT') != 'wiki.index' %}
<li><a href="{{ url_for('wiki.index') }}"><i class="fa fa-list"></i> Index</a></li>
{% endif %}
<li><a href="{{ url_for('wiki.create') }}"><i class="fa fa-plus"></i> New</a></li>
{% if name %}
<li><a href="{{ url_for('wiki.edit', name=name) }}"><i class="fa fa-pencil"></i> Edit</a></li>