shinmun 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/LICENSE +18 -0
- data/README.md +249 -0
- data/Rakefile +60 -0
- data/bin/shinmun +12 -0
- data/example/posts/2008/9/example.md +19 -0
- data/example/posts/blog.yml +10 -0
- data/example/posts/uuid.state +3 -0
- data/example/public/controllers/comments.php +56 -0
- data/example/public/images/loading.gif +0 -0
- data/example/public/javascripts/comments.js +60 -0
- data/example/public/javascripts/highlight.js +505 -0
- data/example/public/javascripts/images/bg-fill.png +0 -0
- data/example/public/javascripts/images/bg.png +0 -0
- data/example/public/javascripts/images/blockquote.png +0 -0
- data/example/public/javascripts/images/bold.png +0 -0
- data/example/public/javascripts/images/code.png +0 -0
- data/example/public/javascripts/images/h1.png +0 -0
- data/example/public/javascripts/images/hr.png +0 -0
- data/example/public/javascripts/images/img.png +0 -0
- data/example/public/javascripts/images/italic.png +0 -0
- data/example/public/javascripts/images/link.png +0 -0
- data/example/public/javascripts/images/ol.png +0 -0
- data/example/public/javascripts/images/redo.png +0 -0
- data/example/public/javascripts/images/separator.png +0 -0
- data/example/public/javascripts/images/ul.png +0 -0
- data/example/public/javascripts/images/undo.png +0 -0
- data/example/public/javascripts/images/wmd-on.png +0 -0
- data/example/public/javascripts/images/wmd.png +0 -0
- data/example/public/javascripts/jquery-form.js +869 -0
- data/example/public/javascripts/jquery.js +3383 -0
- data/example/public/javascripts/languages/1c.js +82 -0
- data/example/public/javascripts/languages/axapta.js +52 -0
- data/example/public/javascripts/languages/bash.js +80 -0
- data/example/public/javascripts/languages/diff.js +64 -0
- data/example/public/javascripts/languages/dos.js +33 -0
- data/example/public/javascripts/languages/dynamic.js +460 -0
- data/example/public/javascripts/languages/ini.js +36 -0
- data/example/public/javascripts/languages/javascript.js +38 -0
- data/example/public/javascripts/languages/lisp.js +86 -0
- data/example/public/javascripts/languages/mel.js +50 -0
- data/example/public/javascripts/languages/profile.js +50 -0
- data/example/public/javascripts/languages/renderman.js +71 -0
- data/example/public/javascripts/languages/smalltalk.js +53 -0
- data/example/public/javascripts/languages/sql.js +50 -0
- data/example/public/javascripts/languages/static.js +175 -0
- data/example/public/javascripts/languages/vbscript.js +25 -0
- data/example/public/javascripts/languages/www.js +245 -0
- data/example/public/javascripts/prettyDate.js +36 -0
- data/example/public/javascripts/showdown.js +421 -0
- data/example/public/javascripts/template.js +165 -0
- data/example/public/javascripts/wmd-base.js +1799 -0
- data/example/public/javascripts/wmd-plus.js +311 -0
- data/example/public/javascripts/wmd.js +73 -0
- data/example/public/stylesheets/grid.css +243 -0
- data/example/public/stylesheets/grid.png +0 -0
- data/example/public/stylesheets/highlight/ascetic.css +38 -0
- data/example/public/stylesheets/highlight/dark.css +96 -0
- data/example/public/stylesheets/highlight/default.css +91 -0
- data/example/public/stylesheets/highlight/far.css +95 -0
- data/example/public/stylesheets/highlight/idea.css +75 -0
- data/example/public/stylesheets/highlight/sunburst.css +112 -0
- data/example/public/stylesheets/highlight/zenburn.css +108 -0
- data/example/public/stylesheets/print.css +76 -0
- data/example/public/stylesheets/reset.css +45 -0
- data/example/public/stylesheets/style.css +141 -0
- data/example/public/stylesheets/typography.css +59 -0
- data/example/templates/feed.rxml +21 -0
- data/example/templates/layout.rhtml +54 -0
- data/example/templates/page.rhtml +4 -0
- data/example/templates/post.rhtml +57 -0
- data/example/templates/posts.rhtml +10 -0
- data/lib/shinmun.rb +420 -0
- metadata +151 -0
@@ -0,0 +1,165 @@
|
|
1
|
+
/*
|
2
|
+
* Patroon - Javascript Template Engine
|
3
|
+
*
|
4
|
+
* Copyright (c) 2008 Matthias Georgi (matthias-georgi.de)
|
5
|
+
*
|
6
|
+
* Permission is hereby granted, free of charge, to any person
|
7
|
+
* obtaining a copy of this software and associated documentation
|
8
|
+
* files (the "Software"), to deal in the Software without
|
9
|
+
* restriction, including without limitation the rights to use,
|
10
|
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
* copies of the Software, and to permit persons to whom the
|
12
|
+
* Software is furnished to do so, subject to the following
|
13
|
+
* conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be
|
16
|
+
* included in all copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
20
|
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
22
|
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
23
|
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
24
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
25
|
+
* OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
*/
|
27
|
+
|
28
|
+
function Template(id) {
|
29
|
+
this.element = document.getElementById(id);
|
30
|
+
|
31
|
+
if (this.element) {
|
32
|
+
this.element.parentNode.removeChild(this.element);
|
33
|
+
} else {
|
34
|
+
throw "template not found: " + id;
|
35
|
+
}
|
36
|
+
};
|
37
|
+
|
38
|
+
Template.prototype = {
|
39
|
+
|
40
|
+
expand: function(data) {
|
41
|
+
var node = this.element.cloneNode(true);
|
42
|
+
this.expandData(data, node);
|
43
|
+
return node;
|
44
|
+
},
|
45
|
+
|
46
|
+
expandData: function(data, node) {
|
47
|
+
switch (typeof data) {
|
48
|
+
case 'string':
|
49
|
+
case 'number':
|
50
|
+
node.innerHTML = data;
|
51
|
+
break;
|
52
|
+
case 'object':
|
53
|
+
if (data.constructor == Array) {
|
54
|
+
this.expandArray(data, node);
|
55
|
+
} else {
|
56
|
+
this.expandObject(data, node);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
},
|
60
|
+
|
61
|
+
expandArray: function(data, node) {
|
62
|
+
var parent = node.parentNode;
|
63
|
+
parent.removeChild(node);
|
64
|
+
for (var i = 0; i < data.length; i++) {
|
65
|
+
var child = node.cloneNode(true);
|
66
|
+
parent.appendChild(child);
|
67
|
+
this.expandData(data[i], child);
|
68
|
+
}
|
69
|
+
},
|
70
|
+
|
71
|
+
cache: {},
|
72
|
+
|
73
|
+
compile: function(str) {
|
74
|
+
var len = str.length;
|
75
|
+
var expr = false;
|
76
|
+
var cmd = "";
|
77
|
+
var lit = "";
|
78
|
+
var out = [];
|
79
|
+
|
80
|
+
for (var i = 0; i < len; i++) {
|
81
|
+
var c = str[i];
|
82
|
+
|
83
|
+
if (c == "'") {
|
84
|
+
c = "\\'";
|
85
|
+
}
|
86
|
+
|
87
|
+
if (c == "\\") {
|
88
|
+
c = "\\\\";
|
89
|
+
}
|
90
|
+
|
91
|
+
switch (c) {
|
92
|
+
case '{':
|
93
|
+
expr = true;
|
94
|
+
if (lit.length > 0) {
|
95
|
+
out.push("'" + lit + "'");
|
96
|
+
}
|
97
|
+
lit = "";
|
98
|
+
break;
|
99
|
+
case '}':
|
100
|
+
expr = false;
|
101
|
+
out.push("(" + cmd + ")");
|
102
|
+
cmd = "";
|
103
|
+
break;
|
104
|
+
default:
|
105
|
+
if (expr) {
|
106
|
+
cmd += c;
|
107
|
+
} else {
|
108
|
+
lit += c;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
if (lit.length > 0) {
|
114
|
+
out.push("'" + lit + "'");
|
115
|
+
}
|
116
|
+
|
117
|
+
var code = '(function (data) { with (data) { return ' + out.join('+') + '; } })';
|
118
|
+
|
119
|
+
return eval(code);
|
120
|
+
},
|
121
|
+
|
122
|
+
evaluate: function(str, data) {
|
123
|
+
var fn = this.cache[str];
|
124
|
+
if (!fn) {
|
125
|
+
fn = this.cache[str] = this.compile(str);
|
126
|
+
}
|
127
|
+
return fn(data);
|
128
|
+
},
|
129
|
+
|
130
|
+
expandObject: function(object, node) {
|
131
|
+
var i, name;
|
132
|
+
var attr = node.attributes;
|
133
|
+
var nodes = node.childNodes;
|
134
|
+
|
135
|
+
for (i = 0; i < attr.length; i++) {
|
136
|
+
var value = attr[i].value;
|
137
|
+
if (value.indexOf('{') != -1) {
|
138
|
+
attr[i].value = this.evaluate(value, object);
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
for (i = 0; i < nodes.length; i++) {
|
143
|
+
var child = nodes[i];
|
144
|
+
if (child.nodeType == 1 && child.className[0] == '_') {
|
145
|
+
this.expandData(object, child);
|
146
|
+
}
|
147
|
+
if (child.nodeType == 3 && child.nodeValue.indexOf('{') != -1) {
|
148
|
+
child.nodeValue = this.evaluate(child.nodeValue, object);
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
for (name in object) {
|
153
|
+
var child = node.getElementsByClassName(name)[0];
|
154
|
+
if (child) {
|
155
|
+
this.expandData(object[name], child);
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}
|
159
|
+
};
|
160
|
+
|
161
|
+
if (jQuery) {
|
162
|
+
jQuery.fn.expand = function(template, data) {
|
163
|
+
return this.html(template.expand(data));
|
164
|
+
};
|
165
|
+
}
|