forked from ringo/ringowiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
71 lines (62 loc) · 1.6 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var md = require('ringo/markdown');
var {Page} = require('./model');
var {app} = require('./actions');
var strings = require('ringo/utils/strings');
var dates = require('ringo/utils/dates');
var mustache = require("ringo/mustache");
export(
'baseUrl',
'editUrl',
'listUrl',
'recentUrl',
'markdown',
'navigation',
'timeFormat'
);
function baseUrl(name) {
name = name && name.replace(/\s/g, '_');
var url = (app.base || "") + "/";
return name ? url + encodeURI(name) : url;
}
function editUrl(name) {
return baseUrl(name || "home") + "/edit";
}
function listUrl() {
return baseUrl() + "list";
}
function recentUrl() {
return baseUrl() + "recent";
}
function markdown(content) {
return md.process(content, {
lookupLink: function(id) {
if (!strings.startsWith(id, "/") && !strings.isUrl(id.isUrl)) {
return [baseUrl(id),
"link to wiki page"];
}
return null;
},
openTag: function(tag, buffer) {
buffer.append('<').append(tag);
if (tag == "pre") {
buffer.append(' class="sh_javascript"');
}
buffer.append('>');
}
});
}
function navigation() {
var page = Page.byName("navigation");
if (page) {
return mustache.to_html(
getResource('./templates/navigation.txt').getContent(), {
markdown: markdown,
content: page.getRevision().body
}
);
}
return '';
}
function timeFormat(date) {
return dates.format(date, "HH:mm");
}