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,505 @@
1
+ /*
2
+ Syntax highlighting with language autodetection.
3
+ http://softwaremaniacs.org/soft/highlight/
4
+ */
5
+
6
+ var hljs = new function() {
7
+
8
+ var DEFAULT_LANGUAGES = ['python', 'ruby', 'perl', 'php', 'css', 'xml', 'html', 'django', 'javascript', 'java', 'cpp', 'sql', 'ini', 'diff'];
9
+ var ALL_LANGUAGES = (DEFAULT_LANGUAGES.join(',') + ',' + ['1c', 'axapta', 'delphi', 'rib', 'rsl', 'vbscript', 'profile', 'dos', 'bash', 'lisp', 'smalltalk', 'mel'].join(',')).split(',');
10
+ var LANGUAGE_GROUPS = {
11
+ 'xml': 'www',
12
+ 'html': 'www',
13
+ 'css': 'www',
14
+ 'django': 'www',
15
+ 'python': 'dynamic',
16
+ 'perl': 'dynamic',
17
+ 'php': 'dynamic',
18
+ 'ruby': 'dynamic',
19
+ 'cpp': 'static',
20
+ 'java': 'static',
21
+ 'delphi': 'static',
22
+ 'rib': 'renderman',
23
+ 'rsl': 'renderman'
24
+ }
25
+
26
+ var LANGUAGES = {}
27
+ var selected_languages = {};
28
+
29
+ function escape(value) {
30
+ return value.replace(/&/gm, '&amp;').replace(/</gm, '&lt;').replace(/>/gm, '&gt;');
31
+ }
32
+
33
+ function contains(array, item) {
34
+ if (!array)
35
+ return false;
36
+ for (var key in array)
37
+ if (array[key] == item)
38
+ return true;
39
+ return false;
40
+ }
41
+
42
+ function highlight(language_name, value) {
43
+ function compileSubModes(mode, language) {
44
+ mode.sub_modes = [];
45
+ for (var i in mode.contains) {
46
+ for (var j in language.modes) {
47
+ if (language.modes[j].className == mode.contains[i]) {
48
+ mode.sub_modes[mode.sub_modes.length] = language.modes[j];
49
+ }
50
+ }
51
+ }
52
+ }
53
+
54
+ function subMode(lexem, mode) {
55
+ if (!mode.contains) {
56
+ return null;
57
+ }
58
+ if (!mode.sub_modes) {
59
+ compileSubModes(mode, language);
60
+ }
61
+ for (var i = 0; i < mode.sub_modes.length; i++) {
62
+ if (mode.sub_modes[i].beginRe.test(lexem)) {
63
+ return mode.sub_modes[i];
64
+ }
65
+ }
66
+ return null;
67
+ }
68
+
69
+ function endOfMode(mode_index, lexem) {
70
+ if (modes[mode_index].end && modes[mode_index].endRe.test(lexem))
71
+ return 1;
72
+ if (modes[mode_index].endsWithParent) {
73
+ var level = endOfMode(mode_index - 1, lexem);
74
+ return level ? level + 1 : 0;
75
+ }
76
+ return 0;
77
+ }
78
+
79
+ function isIllegal(lexem, mode) {
80
+ return mode.illegalRe && mode.illegalRe.test(lexem);
81
+ }
82
+
83
+ function compileTerminators(mode, language) {
84
+ var terminators = [];
85
+
86
+ function addTerminator(re) {
87
+ if (!contains(terminators, re)) {
88
+ terminators[terminators.length] = re;
89
+ }
90
+ }
91
+
92
+ if (mode.contains)
93
+ for (var key in language.modes) {
94
+ if (contains(mode.contains, language.modes[key].className)) {
95
+ addTerminator(language.modes[key].begin);
96
+ }
97
+ }
98
+
99
+ var index = modes.length - 1;
100
+ do {
101
+ if (modes[index].end) {
102
+ addTerminator(modes[index].end);
103
+ }
104
+ index--;
105
+ } while (modes[index + 1].endsWithParent);
106
+
107
+ if (mode.illegal) {
108
+ addTerminator(mode.illegal);
109
+ }
110
+
111
+ var terminator_re = '(' + terminators[0];
112
+ for (var i = 0; i < terminators.length; i++)
113
+ terminator_re += '|' + terminators[i];
114
+ terminator_re += ')';
115
+ return langRe(language, terminator_re);
116
+ }
117
+
118
+ function eatModeChunk(value, index) {
119
+ var mode = modes[modes.length - 1];
120
+ if (!mode.terminators) {
121
+ mode.terminators = compileTerminators(mode, language);
122
+ }
123
+ value = value.substr(index);
124
+ var match = mode.terminators.exec(value);
125
+ if (!match)
126
+ return [value, '', true];
127
+ if (match.index == 0)
128
+ return ['', match[0], false];
129
+ else
130
+ return [value.substr(0, match.index), match[0], false];
131
+ }
132
+
133
+ function keywordMatch(mode, match) {
134
+ var match_str = language.case_insensitive ? match[0].toLowerCase() : match[0]
135
+ for (var className in mode.keywordGroups) {
136
+ var value = mode.keywordGroups[className].hasOwnProperty(match_str);
137
+ if (value)
138
+ return [className, value];
139
+ }
140
+ return false;
141
+ }
142
+
143
+ function processKeywords(buffer, mode) {
144
+ if (!mode.keywords || !mode.lexems)
145
+ return escape(buffer);
146
+ if (!mode.lexemsRe) {
147
+ var lexems_re = '(' + mode.lexems[0];
148
+ for (var i = 1; i < mode.lexems.length; i++)
149
+ lexems_re += '|' + mode.lexems[i];
150
+ lexems_re += ')';
151
+ mode.lexemsRe = langRe(language, lexems_re, true);
152
+ }
153
+ var result = '';
154
+ var last_index = 0;
155
+ mode.lexemsRe.lastIndex = 0;
156
+ var match = mode.lexemsRe.exec(buffer);
157
+ while (match) {
158
+ result += escape(buffer.substr(last_index, match.index - last_index));
159
+ keyword_match = keywordMatch(mode, match);
160
+ if (keyword_match) {
161
+ keyword_count += keyword_match[1];
162
+ result += '<span class="'+ keyword_match[0] +'">' + escape(match[0]) + '</span>';
163
+ } else {
164
+ result += escape(match[0]);
165
+ }
166
+ last_index = mode.lexemsRe.lastIndex;
167
+ match = mode.lexemsRe.exec(buffer);
168
+ }
169
+ result += escape(buffer.substr(last_index, buffer.length - last_index));
170
+ return result;
171
+ }
172
+
173
+ function processBuffer(buffer, mode) {
174
+ if (mode.subLanguage && selected_languages[mode.subLanguage]) {
175
+ var result = highlight(mode.subLanguage, buffer);
176
+ keyword_count += result.keyword_count;
177
+ relevance += result.relevance;
178
+ return result.value;
179
+ } else {
180
+ return processKeywords(buffer, mode);
181
+ }
182
+ }
183
+
184
+ function startNewMode(mode, lexem) {
185
+ if (mode.returnBegin) {
186
+ result += '<span class="' + mode.className + '">';
187
+ mode.buffer = '';
188
+ } else if (mode.excludeBegin) {
189
+ result += escape(lexem) + '<span class="' + mode.className + '">';
190
+ mode.buffer = '';
191
+ } else {
192
+ result += '<span class="' + mode.className + '">';
193
+ mode.buffer = lexem;
194
+ }
195
+ modes[modes.length] = mode;
196
+ }
197
+
198
+ function processModeInfo(buffer, lexem, end) {
199
+ var current_mode = modes[modes.length - 1];
200
+ if (end) {
201
+ result += processBuffer(current_mode.buffer + buffer, current_mode);
202
+ return false;
203
+ }
204
+
205
+ var new_mode = subMode(lexem, current_mode);
206
+ if (new_mode) {
207
+ result += processBuffer(current_mode.buffer + buffer, current_mode);
208
+ startNewMode(new_mode, lexem);
209
+ relevance += new_mode.relevance;
210
+ return new_mode.returnBegin;
211
+ }
212
+
213
+ var end_level = endOfMode(modes.length - 1, lexem);
214
+ if (end_level) {
215
+ if (current_mode.returnEnd) {
216
+ result += processBuffer(current_mode.buffer + buffer, current_mode) + '</span>';
217
+ } else if (current_mode.excludeEnd) {
218
+ result += processBuffer(current_mode.buffer + buffer, current_mode) + '</span>' + escape(lexem);
219
+ } else {
220
+ result += processBuffer(current_mode.buffer + buffer + lexem, current_mode) + '</span>';
221
+ }
222
+ while (end_level > 1) {
223
+ result += '</span>';
224
+ end_level--;
225
+ modes.length--;
226
+ }
227
+ modes.length--;
228
+ modes[modes.length - 1].buffer = '';
229
+ if (current_mode.starts) {
230
+ for (var i = 0; i < language.modes.length; i++) {
231
+ if (language.modes[i].className == current_mode.starts) {
232
+ startNewMode(language.modes[i], '');
233
+ break;
234
+ }
235
+ }
236
+ }
237
+ return current_mode.returnEnd;
238
+ }
239
+
240
+ if (isIllegal(lexem, current_mode))
241
+ throw 'Illegal';
242
+ }
243
+
244
+ var language = LANGUAGES[language_name];
245
+ var modes = [language.defaultMode];
246
+ var relevance = 0;
247
+ var keyword_count = 0;
248
+ var result = '';
249
+ try {
250
+ var index = 0;
251
+ language.defaultMode.buffer = '';
252
+ do {
253
+ var mode_info = eatModeChunk(value, index);
254
+ var return_lexem = processModeInfo(mode_info[0], mode_info[1], mode_info[2]);
255
+ index += mode_info[0].length;
256
+ if (!return_lexem) {
257
+ index += mode_info[1].length;
258
+ }
259
+ } while (!mode_info[2]);
260
+ if(modes.length > 1)
261
+ throw 'Illegal';
262
+ return {
263
+ relevance: relevance,
264
+ keyword_count: keyword_count,
265
+ value: result
266
+ }
267
+ } catch (e) {
268
+ if (e == 'Illegal') {
269
+ return {
270
+ relevance: 0,
271
+ keyword_count: 0,
272
+ value: escape(value)
273
+ }
274
+ } else {
275
+ throw e;
276
+ }
277
+ }
278
+ }
279
+
280
+ function blockText(block) {
281
+ var result = '';
282
+ for (var i = 0; i < block.childNodes.length; i++)
283
+ if (block.childNodes[i].nodeType == 3)
284
+ result += block.childNodes[i].nodeValue;
285
+ else if (block.childNodes[i].nodeName == 'BR')
286
+ result += '\n';
287
+ else
288
+ throw 'No highlight';
289
+ return result;
290
+ }
291
+
292
+ function blockLanguage(block) {
293
+ var classes = block.className.split(/\s+/);
294
+ for (var i = 0; i < classes.length; i++) {
295
+ if (classes[i] == 'no-highlight') {
296
+ throw 'No highlight'
297
+ }
298
+ if (LANGUAGES[classes[i]]) {
299
+ return classes[i];
300
+ }
301
+ }
302
+ }
303
+
304
+ function highlightBlock(block) {
305
+ try {
306
+ var text = blockText(block);
307
+ var language = blockLanguage(block);
308
+ } catch (e) {
309
+ if (e == 'No highlight')
310
+ return;
311
+ }
312
+
313
+ if (language) {
314
+ var result = highlight(language, text).value;
315
+ } else {
316
+ var max_relevance = 2;
317
+ var relevance = 0;
318
+ for (var key in selected_languages) {
319
+ var r = highlight(key, text);
320
+ relevance = r.keyword_count + r.relevance;
321
+ if (relevance > max_relevance) {
322
+ max_relevance = relevance;
323
+ var result = r.value;
324
+ language = key;
325
+ }
326
+ }
327
+ }
328
+
329
+ if (result) {
330
+ var className = block.className;
331
+ if (!className.match(language)) {
332
+ className += ' ' + language;
333
+ }
334
+ // See these 4 lines? This is IE's notion of "block.innerHTML = result". Love this browser :-/
335
+ var container = document.createElement('div');
336
+ container.innerHTML = '<pre><code class="' + className + '">' + result + '</code></pre>';
337
+ var environment = block.parentNode.parentNode;
338
+ environment.replaceChild(container.firstChild, block.parentNode);
339
+ }
340
+ }
341
+
342
+ function langRe(language, value, global) {
343
+ var mode = 'm' + (language.case_insensitive ? 'i' : '') + (global ? 'g' : '');
344
+ return new RegExp(value, mode);
345
+ }
346
+
347
+ function compileModes() {
348
+ for (var i in LANGUAGES) {
349
+ var language = LANGUAGES[i];
350
+ for (var key in language.modes) {
351
+ if (language.modes[key].begin)
352
+ language.modes[key].beginRe = langRe(language, '^' + language.modes[key].begin);
353
+ if (language.modes[key].end)
354
+ language.modes[key].endRe = langRe(language, '^' + language.modes[key].end);
355
+ if (language.modes[key].illegal)
356
+ language.modes[key].illegalRe = langRe(language, '^(?:' + language.modes[key].illegal + ')');
357
+ language.defaultMode.illegalRe = langRe(language, '^(?:' + language.defaultMode.illegal + ')');
358
+ if (language.modes[key].relevance == undefined) {
359
+ language.modes[key].relevance = 1;
360
+ }
361
+ }
362
+ }
363
+ }
364
+
365
+ function compileKeywords() {
366
+
367
+ function compileModeKeywords(mode) {
368
+ if (!mode.keywordGroups) {
369
+ for (var key in mode.keywords) {
370
+ if (mode.keywords[key] instanceof Object)
371
+ mode.keywordGroups = mode.keywords;
372
+ else
373
+ mode.keywordGroups = {'keyword': mode.keywords};
374
+ break;
375
+ }
376
+ }
377
+ }
378
+
379
+ for (var i in LANGUAGES) {
380
+ var language = LANGUAGES[i];
381
+ compileModeKeywords(language.defaultMode);
382
+ for (var key in language.modes) {
383
+ compileModeKeywords(language.modes[key]);
384
+ }
385
+ }
386
+ }
387
+
388
+ function findCode(pre) {
389
+ for (var i = 0; i < pre.childNodes.length; i++) {
390
+ node = pre.childNodes[i];
391
+ if (node.nodeName == 'CODE')
392
+ return node;
393
+ if (!(node.nodeType == 3 && node.nodeValue.match(/\s+/)))
394
+ return null;
395
+ }
396
+ }
397
+
398
+ function initHighlighting() {
399
+ if (initHighlighting.called)
400
+ return;
401
+ initHighlighting.called = true;
402
+ compileModes();
403
+ compileKeywords();
404
+ if (arguments.length) {
405
+ for (var i = 0; i < arguments.length; i++) {
406
+ if (LANGUAGES[arguments[i]]) {
407
+ selected_languages[arguments[i]] = LANGUAGES[arguments[i]];
408
+ }
409
+ }
410
+ } else
411
+ selected_languages = LANGUAGES;
412
+ var pres = document.getElementsByTagName('pre');
413
+ for (var i = 0; i < pres.length; i++) {
414
+ var code = findCode(pres[i]);
415
+ if (code)
416
+ highlightBlock(code);
417
+ }
418
+ }
419
+
420
+ function injectScripts(languages) {
421
+ var scripts = document.getElementsByTagName('SCRIPT');
422
+ for (var i=0; i < scripts.length; i++) {
423
+ if (scripts[i].src.match(/highlight\.js(\?.+)?$/)) {
424
+ var path = scripts[i].src.replace(/highlight\.js(\?.+)?$/, '');
425
+ break;
426
+ }
427
+ }
428
+ if (languages.length == 0) {
429
+ languages = DEFAULT_LANGUAGES;
430
+ }
431
+ var injected = {}
432
+ for (var i=0; i < languages.length; i++) {
433
+ var filename = LANGUAGE_GROUPS[languages[i]] ? LANGUAGE_GROUPS[languages[i]] : languages[i];
434
+ if (!injected[filename]) {
435
+ document.write('<script type="text/javascript" src="' + path + 'languages/' + filename + '.js"></script>');
436
+ injected[filename] = true;
437
+ }
438
+ }
439
+ }
440
+
441
+ function initHighlightingOnLoad() {
442
+ var original_arguments = arguments;
443
+ injectScripts(arguments);
444
+ var handler = function(){initHighlighting.apply(null, original_arguments)};
445
+ if (window.addEventListener) {
446
+ window.addEventListener('DOMContentLoaded', handler, false);
447
+ window.addEventListener('load', handler, false);
448
+ } else if (window.attachEvent)
449
+ window.attachEvent('onload', handler);
450
+ else
451
+ window.onload = handler;
452
+ }
453
+
454
+ this.LANGUAGES = LANGUAGES;
455
+ this.ALL_LANGUAGES = ALL_LANGUAGES;
456
+ this.initHighlightingOnLoad = initHighlightingOnLoad;
457
+ this.highlightBlock = highlightBlock;
458
+
459
+ // Common regexps
460
+ this.IDENT_RE = '[a-zA-Z][a-zA-Z0-9_]*';
461
+ this.UNDERSCORE_IDENT_RE = '[a-zA-Z_][a-zA-Z0-9_]*';
462
+ this.NUMBER_RE = '\\b\\d+(\\.\\d+)?';
463
+ this.C_NUMBER_RE = '\\b(0x[A-Za-z0-9]+|\\d+(\\.\\d+)?)';
464
+
465
+ // Common modes
466
+ this.APOS_STRING_MODE = {
467
+ className: 'string',
468
+ begin: '\'', end: '\'',
469
+ illegal: '\\n',
470
+ contains: ['escape'],
471
+ relevance: 0
472
+ };
473
+ this.QUOTE_STRING_MODE = {
474
+ className: 'string',
475
+ begin: '"', end: '"',
476
+ illegal: '\\n',
477
+ contains: ['escape'],
478
+ relevance: 0
479
+ };
480
+ this.BACKSLASH_ESCAPE = {
481
+ className: 'escape',
482
+ begin: '\\\\.', end: '^',
483
+ relevance: 0
484
+ };
485
+ this.C_LINE_COMMENT_MODE = {
486
+ className: 'comment',
487
+ begin: '//', end: '$',
488
+ relevance: 0
489
+ };
490
+ this.C_BLOCK_COMMENT_MODE = {
491
+ className: 'comment',
492
+ begin: '/\\*', end: '\\*/'
493
+ };
494
+ this.HASH_COMMENT_MODE = {
495
+ className: 'comment',
496
+ begin: '#', end: '$'
497
+ };
498
+ this.C_NUMBER_MODE = {
499
+ className: 'number',
500
+ begin: this.C_NUMBER_RE, end: '^',
501
+ relevance: 0
502
+ };
503
+ }();
504
+
505
+ var initHighlightingOnLoad = hljs.initHighlightingOnLoad;