shinmun 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/.gitignore +1 -0
  2. data/LICENSE +18 -0
  3. data/README.md +249 -0
  4. data/Rakefile +60 -0
  5. data/bin/shinmun +12 -0
  6. data/example/posts/2008/9/example.md +19 -0
  7. data/example/posts/blog.yml +10 -0
  8. data/example/posts/uuid.state +3 -0
  9. data/example/public/controllers/comments.php +56 -0
  10. data/example/public/images/loading.gif +0 -0
  11. data/example/public/javascripts/comments.js +60 -0
  12. data/example/public/javascripts/highlight.js +505 -0
  13. data/example/public/javascripts/images/bg-fill.png +0 -0
  14. data/example/public/javascripts/images/bg.png +0 -0
  15. data/example/public/javascripts/images/blockquote.png +0 -0
  16. data/example/public/javascripts/images/bold.png +0 -0
  17. data/example/public/javascripts/images/code.png +0 -0
  18. data/example/public/javascripts/images/h1.png +0 -0
  19. data/example/public/javascripts/images/hr.png +0 -0
  20. data/example/public/javascripts/images/img.png +0 -0
  21. data/example/public/javascripts/images/italic.png +0 -0
  22. data/example/public/javascripts/images/link.png +0 -0
  23. data/example/public/javascripts/images/ol.png +0 -0
  24. data/example/public/javascripts/images/redo.png +0 -0
  25. data/example/public/javascripts/images/separator.png +0 -0
  26. data/example/public/javascripts/images/ul.png +0 -0
  27. data/example/public/javascripts/images/undo.png +0 -0
  28. data/example/public/javascripts/images/wmd-on.png +0 -0
  29. data/example/public/javascripts/images/wmd.png +0 -0
  30. data/example/public/javascripts/jquery-form.js +869 -0
  31. data/example/public/javascripts/jquery.js +3383 -0
  32. data/example/public/javascripts/languages/1c.js +82 -0
  33. data/example/public/javascripts/languages/axapta.js +52 -0
  34. data/example/public/javascripts/languages/bash.js +80 -0
  35. data/example/public/javascripts/languages/diff.js +64 -0
  36. data/example/public/javascripts/languages/dos.js +33 -0
  37. data/example/public/javascripts/languages/dynamic.js +460 -0
  38. data/example/public/javascripts/languages/ini.js +36 -0
  39. data/example/public/javascripts/languages/javascript.js +38 -0
  40. data/example/public/javascripts/languages/lisp.js +86 -0
  41. data/example/public/javascripts/languages/mel.js +50 -0
  42. data/example/public/javascripts/languages/profile.js +50 -0
  43. data/example/public/javascripts/languages/renderman.js +71 -0
  44. data/example/public/javascripts/languages/smalltalk.js +53 -0
  45. data/example/public/javascripts/languages/sql.js +50 -0
  46. data/example/public/javascripts/languages/static.js +175 -0
  47. data/example/public/javascripts/languages/vbscript.js +25 -0
  48. data/example/public/javascripts/languages/www.js +245 -0
  49. data/example/public/javascripts/prettyDate.js +36 -0
  50. data/example/public/javascripts/showdown.js +421 -0
  51. data/example/public/javascripts/template.js +165 -0
  52. data/example/public/javascripts/wmd-base.js +1799 -0
  53. data/example/public/javascripts/wmd-plus.js +311 -0
  54. data/example/public/javascripts/wmd.js +73 -0
  55. data/example/public/stylesheets/grid.css +243 -0
  56. data/example/public/stylesheets/grid.png +0 -0
  57. data/example/public/stylesheets/highlight/ascetic.css +38 -0
  58. data/example/public/stylesheets/highlight/dark.css +96 -0
  59. data/example/public/stylesheets/highlight/default.css +91 -0
  60. data/example/public/stylesheets/highlight/far.css +95 -0
  61. data/example/public/stylesheets/highlight/idea.css +75 -0
  62. data/example/public/stylesheets/highlight/sunburst.css +112 -0
  63. data/example/public/stylesheets/highlight/zenburn.css +108 -0
  64. data/example/public/stylesheets/print.css +76 -0
  65. data/example/public/stylesheets/reset.css +45 -0
  66. data/example/public/stylesheets/style.css +141 -0
  67. data/example/public/stylesheets/typography.css +59 -0
  68. data/example/templates/feed.rxml +21 -0
  69. data/example/templates/layout.rhtml +54 -0
  70. data/example/templates/page.rhtml +4 -0
  71. data/example/templates/post.rhtml +57 -0
  72. data/example/templates/posts.rhtml +10 -0
  73. data/lib/shinmun.rb +420 -0
  74. 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
+ }