liquid_cms 0.3.1.0 → 0.3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. data/CHANGELOG.rdoc +10 -0
  2. data/Gemfile +0 -3
  3. data/README.rdoc +16 -2
  4. data/TODO.rdoc +0 -2
  5. data/app/controllers/cms/assets_controller.rb +20 -6
  6. data/app/controllers/cms/components_controller.rb +11 -3
  7. data/app/controllers/cms/pages_controller.rb +15 -4
  8. data/app/helpers/cms/common_helper.rb +31 -32
  9. data/app/liquid/cms_paperclip_extension.rb +75 -3
  10. data/app/liquid/tags/{data_tag.rb → cms/data_tag.rb} +0 -0
  11. data/app/models/cms/asset.rb +1 -1
  12. data/app/models/cms/component.rb +3 -3
  13. data/app/views/cms/assets/_form.html.erb +1 -2
  14. data/app/views/cms/assets/update.js.rjs +1 -0
  15. data/app/views/cms/components/update.js.rjs +1 -0
  16. data/app/views/cms/pages/_form.html.erb +3 -3
  17. data/app/views/cms/pages/update.js.rjs +1 -0
  18. data/app/views/layouts/cms.html.erb +4 -3
  19. data/config/initializers/cms/simple_form.rb +70 -12
  20. data/config/initializers/cms/simple_form_updates.rb +9 -3
  21. data/config/locales/cms/en.yml +6 -0
  22. data/lib/generators/liquid_cms/install_generator.rb +5 -1
  23. data/lib/generators/liquid_cms/templates/migration_rev2.rb +13 -0
  24. data/lib/generators/liquid_cms/templates/public/cms/codemirror/LICENSE +16 -20
  25. data/lib/generators/liquid_cms/templates/public/cms/codemirror/lib/codemirror.css +68 -0
  26. data/lib/generators/liquid_cms/templates/public/cms/codemirror/lib/codemirror.js +2197 -0
  27. data/lib/generators/liquid_cms/templates/public/cms/codemirror/lib/overlay.js +51 -0
  28. data/lib/generators/liquid_cms/templates/public/cms/codemirror/lib/runmode.js +27 -0
  29. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/clike/clike.js +247 -0
  30. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/clike/index.html +102 -0
  31. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/clojure/clojure.js +207 -0
  32. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/clojure/index.html +85 -0
  33. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/LICENSE +22 -0
  34. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/coffeescript.js +325 -0
  35. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/index.html +722 -0
  36. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/css/css.js +124 -0
  37. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/css/index.html +56 -0
  38. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/diff.css +3 -0
  39. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/diff.js +13 -0
  40. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/index.html +99 -0
  41. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/haskell/haskell.js +242 -0
  42. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/haskell/index.html +60 -0
  43. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/htmlmixed/htmlmixed.js +79 -0
  44. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/htmlmixed/index.html +52 -0
  45. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/javascript/index.html +78 -0
  46. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/javascript/javascript.js +352 -0
  47. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/jinja2/index.html +38 -0
  48. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/jinja2/jinja2.js +42 -0
  49. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/lua/index.html +72 -0
  50. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/lua/lua.js +140 -0
  51. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/index.html +340 -0
  52. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/markdown.css +10 -0
  53. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/markdown.js +230 -0
  54. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/ntriples/index.html +33 -0
  55. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/ntriples/ntriples.js +172 -0
  56. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/LICENSE +7 -0
  57. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/index.html +49 -0
  58. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/pascal.js +138 -0
  59. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/php/index.html +49 -0
  60. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/php/php.js +116 -0
  61. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/plsql/index.html +63 -0
  62. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/plsql/plsql.js +217 -0
  63. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/python/LICENSE.txt +21 -0
  64. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/python/index.html +123 -0
  65. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/python/python.js +320 -0
  66. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/r/LICENSE +24 -0
  67. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/r/index.html +74 -0
  68. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/r/r.js +141 -0
  69. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/index.html +526 -0
  70. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/rst.css +75 -0
  71. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/rst.js +333 -0
  72. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/LICENSE +24 -0
  73. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/index.html +172 -0
  74. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/ruby.js +195 -0
  75. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/scheme/index.html +65 -0
  76. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/scheme/scheme.js +202 -0
  77. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/smalltalk/index.html +56 -0
  78. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/smalltalk/smalltalk.js +122 -0
  79. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/sparql/index.html +41 -0
  80. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/sparql/sparql.js +143 -0
  81. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/stex/index.html +96 -0
  82. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/stex/stex.js +167 -0
  83. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/velocity/index.html +103 -0
  84. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/velocity/velocity.js +146 -0
  85. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/xml/index.html +42 -0
  86. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/xml/xml.js +231 -0
  87. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/xmlpure/index.html +60 -0
  88. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/xmlpure/xmlpure.js +481 -0
  89. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/yaml/index.html +68 -0
  90. data/lib/generators/liquid_cms/templates/public/cms/codemirror/mode/yaml/yaml.js +95 -0
  91. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/cobalt.css +17 -0
  92. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/default.css +19 -0
  93. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/eclipse.css +24 -0
  94. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/elegant.css +9 -0
  95. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/neat.css +8 -0
  96. data/lib/generators/liquid_cms/templates/public/cms/codemirror/theme/night.css +20 -0
  97. data/lib/generators/liquid_cms/templates/public/cms/javascripts/cms.js +1 -1
  98. data/lib/generators/liquid_cms/templates/public/cms/javascripts/codemirror_custom.js +96 -0
  99. data/lib/generators/liquid_cms/templates/public/cms/stylesheets/codemirror_changes.css +26 -0
  100. data/lib/generators/liquid_cms/templates/public/cms/stylesheets/liquid.css +7 -0
  101. data/lib/generators/liquid_cms/templates/public/cms/stylesheets/simple_form.css +0 -8
  102. data/lib/liquid_cms/version.rb +1 -1
  103. data/liquid_cms.gemspec +1 -1
  104. data/test/functional/assets_controller_test.rb +35 -20
  105. data/test/functional/components_controller_test.rb +15 -5
  106. data/test/functional/pages_controller_test.rb +19 -6
  107. data/test/rails_app/Gemfile +1 -2
  108. data/test/rails_app/config/locales/cms/en.yml +26 -4
  109. data/test/rails_app/db/migrate/20110511161859_create_liquid_cms_upgrade_rev2.rb +13 -0
  110. data/test/unit/asset_test.rb +1 -1
  111. data/test/unit/component_test.rb +1 -1
  112. metadata +89 -32
  113. data/generators/liquid_cms/templates/migration_rev1.rb +0 -38
  114. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/csscolors.css +0 -55
  115. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/docs.css +0 -158
  116. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/font.js +0 -15
  117. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/jscolors.css +0 -59
  118. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/sparqlcolors.css +0 -43
  119. data/lib/generators/liquid_cms/templates/public/cms/codemirror/css/xmlcolors.css +0 -55
  120. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/codemirror.js +0 -582
  121. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/editor.js +0 -1671
  122. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/highlight.js +0 -68
  123. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/mirrorframe.js +0 -81
  124. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsecss.js +0 -161
  125. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsedummy.js +0 -32
  126. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsehtmlmixed.js +0 -93
  127. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsejavascript.js +0 -359
  128. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsesparql.js +0 -162
  129. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/parsexml.js +0 -291
  130. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/select.js +0 -699
  131. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/stringstream.js +0 -159
  132. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/tokenize.js +0 -57
  133. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/tokenizejavascript.js +0 -174
  134. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/undo.js +0 -413
  135. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/unittests.js +0 -44
  136. data/lib/generators/liquid_cms/templates/public/cms/codemirror/js/util.js +0 -133
@@ -0,0 +1,56 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>CodeMirror 2: Smalltalk mode</title>
5
+ <link rel="stylesheet" href="../../lib/codemirror.css">
6
+ <script src="../../lib/codemirror.js"></script>
7
+ <script src="smalltalk.js"></script>
8
+ <link rel="stylesheet" href="../../theme/default.css">
9
+ <link rel="stylesheet" href="../../css/docs.css">
10
+ <style>
11
+ .CodeMirror {border: 2px solid #dee; border-right-width: 10px;}
12
+ .CodeMirror-gutter {border: none; background: #dee;}
13
+ .CodeMirror-gutter pre {color: white; font-weight: bold;}
14
+ </style>
15
+ </head>
16
+ <body>
17
+ <h1>CodeMirror 2: Smalltalk mode</h1>
18
+
19
+ <form><textarea id="code" name="code">
20
+ "
21
+ This is a test of the Smalltalk code
22
+ "
23
+ Seaside.WAComponent subclass: #MyCounter [
24
+ | count |
25
+ MyCounter class &gt;&gt; canBeRoot [ ^true ]
26
+
27
+ initialize [
28
+ super initialize.
29
+ count := 0.
30
+ ]
31
+ states [ ^{ self } ]
32
+ renderContentOn: html [
33
+ html heading: count.
34
+ html anchor callback: [ count := count + 1 ]; with: '++'.
35
+ html space.
36
+ html anchor callback: [ count := count - 1 ]; with: '--'.
37
+ ]
38
+ ]
39
+
40
+ MyCounter registerAsApplication: 'mycounter'
41
+ </textarea></form>
42
+
43
+ <script>
44
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
45
+ lineNumbers: true,
46
+ matchBrackets: true,
47
+ mode: "text/x-stsrc",
48
+ indentUnit: 4
49
+ });
50
+ </script>
51
+
52
+ <p>Simple Smalltalk mode.</p>
53
+
54
+ <p><strong>MIME types defined:</strong> <code>text/x-stsrc</code>.</p>
55
+ </body>
56
+ </html>
@@ -0,0 +1,122 @@
1
+ CodeMirror.defineMode("smalltalk", function(config, parserConfig) {
2
+ var keywords = {"true": 1, "false": 1, nil: 1, self: 1, "super": 1, thisContext: 1};
3
+ var indentUnit = config.indentUnit;
4
+
5
+ function chain(stream, state, f) {
6
+ state.tokenize = f;
7
+ return f(stream, state);
8
+ }
9
+
10
+ var type;
11
+ function ret(tp, style) {
12
+ type = tp;
13
+ return style;
14
+ }
15
+
16
+ function tokenBase(stream, state) {
17
+ var ch = stream.next();
18
+ if (ch == '"')
19
+ return chain(stream, state, tokenComment(ch));
20
+ else if (ch == "'")
21
+ return chain(stream, state, tokenString(ch));
22
+ else if (ch == "#") {
23
+ stream.eatWhile(/[\w\$_]/);
24
+ return ret("string", "string");
25
+ }
26
+ else if (/\d/.test(ch)) {
27
+ stream.eatWhile(/[\w\.]/)
28
+ return ret("number", "number");
29
+ }
30
+ else if (/[\[\]()]/.test(ch)) {
31
+ return ret(ch, null);
32
+ }
33
+ else {
34
+ stream.eatWhile(/[\w\$_]/);
35
+ if (keywords && keywords.propertyIsEnumerable(stream.current())) return ret("keyword", "keyword");
36
+ return ret("word", "variable");
37
+ }
38
+ }
39
+
40
+ function tokenString(quote) {
41
+ return function(stream, state) {
42
+ var escaped = false, next, end = false;
43
+ while ((next = stream.next()) != null) {
44
+ if (next == quote && !escaped) {end = true; break;}
45
+ escaped = !escaped && next == "\\";
46
+ }
47
+ if (end || !(escaped))
48
+ state.tokenize = tokenBase;
49
+ return ret("string", "string");
50
+ };
51
+ }
52
+
53
+ function tokenComment(quote) {
54
+ return function(stream, state) {
55
+ var next, end = false;
56
+ while ((next = stream.next()) != null) {
57
+ if (next == quote) {end = true; break;}
58
+ }
59
+ if (end)
60
+ state.tokenize = tokenBase;
61
+ return ret("comment", "comment");
62
+ };
63
+ }
64
+
65
+ function Context(indented, column, type, align, prev) {
66
+ this.indented = indented;
67
+ this.column = column;
68
+ this.type = type;
69
+ this.align = align;
70
+ this.prev = prev;
71
+ }
72
+
73
+ function pushContext(state, col, type) {
74
+ return state.context = new Context(state.indented, col, type, null, state.context);
75
+ }
76
+ function popContext(state) {
77
+ return state.context = state.context.prev;
78
+ }
79
+
80
+ // Interface
81
+
82
+ return {
83
+ startState: function(basecolumn) {
84
+ return {
85
+ tokenize: tokenBase,
86
+ context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
87
+ indented: 0,
88
+ startOfLine: true
89
+ };
90
+ },
91
+
92
+ token: function(stream, state) {
93
+ var ctx = state.context;
94
+ if (stream.sol()) {
95
+ if (ctx.align == null) ctx.align = false;
96
+ state.indented = stream.indentation();
97
+ state.startOfLine = true;
98
+ }
99
+ if (stream.eatSpace()) return null;
100
+ var style = state.tokenize(stream, state);
101
+ if (type == "comment") return style;
102
+ if (ctx.align == null) ctx.align = true;
103
+
104
+ if (type == "[") pushContext(state, stream.column(), "]");
105
+ else if (type == "(") pushContext(state, stream.column(), ")");
106
+ else if (type == ctx.type) popContext(state);
107
+ state.startOfLine = false;
108
+ return style;
109
+ },
110
+
111
+ indent: function(state, textAfter) {
112
+ if (state.tokenize != tokenBase) return 0;
113
+ var firstChar = textAfter && textAfter.charAt(0), ctx = state.context, closing = firstChar == ctx.type;
114
+ if (ctx.align) return ctx.column + (closing ? 0 : 1);
115
+ else return ctx.indented + (closing ? 0 : indentUnit);
116
+ },
117
+
118
+ electricChars: "]"
119
+ };
120
+ });
121
+
122
+ CodeMirror.defineMIME("text/x-stsrc", {name: "smalltalk"});
@@ -0,0 +1,41 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>CodeMirror 2: SPARQL mode</title>
5
+ <link rel="stylesheet" href="../../lib/codemirror.css">
6
+ <script src="../../lib/codemirror.js"></script>
7
+ <script src="sparql.js"></script>
8
+ <link rel="stylesheet" href="../../theme/default.css">
9
+ <style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
10
+ <link rel="stylesheet" href="../../css/docs.css">
11
+ </head>
12
+ <body>
13
+ <h1>CodeMirror 2: SPARQL mode</h1>
14
+ <form><textarea id="code" name="code">
15
+ PREFIX a: &lt;http://www.w3.org/2000/10/annotation-ns#>
16
+ PREFIX dc: &lt;http://purl.org/dc/elements/1.1/>
17
+ PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/>
18
+
19
+ # Comment!
20
+
21
+ SELECT ?given ?family
22
+ WHERE {
23
+ ?annot a:annotates &lt;http://www.w3.org/TR/rdf-sparql-query/> .
24
+ ?annot dc:creator ?c .
25
+ OPTIONAL {?c foaf:given ?given ;
26
+ foaf:family ?family } .
27
+ FILTER isBlank(?c)
28
+ }
29
+ </textarea></form>
30
+ <script>
31
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
32
+ mode: "application/x-sparql-query",
33
+ tabMode: "indent",
34
+ matchBrackets: true
35
+ });
36
+ </script>
37
+
38
+ <p><strong>MIME types defined:</strong> <code>application/x-sparql-query</code>.</p>
39
+
40
+ </body>
41
+ </html>
@@ -0,0 +1,143 @@
1
+ CodeMirror.defineMode("sparql", function(config) {
2
+ var indentUnit = config.indentUnit;
3
+ var curPunc;
4
+
5
+ function wordRegexp(words) {
6
+ return new RegExp("^(?:" + words.join("|") + ")$", "i");
7
+ }
8
+ var ops = wordRegexp(["str", "lang", "langmatches", "datatype", "bound", "sameterm", "isiri", "isuri",
9
+ "isblank", "isliteral", "union", "a"]);
10
+ var keywords = wordRegexp(["base", "prefix", "select", "distinct", "reduced", "construct", "describe",
11
+ "ask", "from", "named", "where", "order", "limit", "offset", "filter", "optional",
12
+ "graph", "by", "asc", "desc"]);
13
+ var operatorChars = /[*+\-<>=&|]/;
14
+
15
+ function tokenBase(stream, state) {
16
+ var ch = stream.next();
17
+ curPunc = null;
18
+ if (ch == "$" || ch == "?") {
19
+ stream.match(/^[\w\d]*/);
20
+ return "variable-2";
21
+ }
22
+ else if (ch == "<" && !stream.match(/^[\s\u00a0=]/, false)) {
23
+ stream.match(/^[^\s\u00a0>]*>?/);
24
+ return "atom";
25
+ }
26
+ else if (ch == "\"" || ch == "'") {
27
+ state.tokenize = tokenLiteral(ch);
28
+ return state.tokenize(stream, state);
29
+ }
30
+ else if (/[{}\(\),\.;\[\]]/.test(ch)) {
31
+ curPunc = ch;
32
+ return null;
33
+ }
34
+ else if (ch == "#") {
35
+ stream.skipToEnd();
36
+ return "comment";
37
+ }
38
+ else if (operatorChars.test(ch)) {
39
+ stream.eatWhile(operatorChars);
40
+ return null;
41
+ }
42
+ else if (ch == ":") {
43
+ stream.eatWhile(/[\w\d\._\-]/);
44
+ return "atom";
45
+ }
46
+ else {
47
+ stream.eatWhile(/[_\w\d]/);
48
+ if (stream.eat(":")) {
49
+ stream.eatWhile(/[\w\d_\-]/);
50
+ return "atom";
51
+ }
52
+ var word = stream.current(), type;
53
+ if (ops.test(word))
54
+ return null;
55
+ else if (keywords.test(word))
56
+ return "keyword";
57
+ else
58
+ return "variable";
59
+ }
60
+ }
61
+
62
+ function tokenLiteral(quote) {
63
+ return function(stream, state) {
64
+ var escaped = false, ch;
65
+ while ((ch = stream.next()) != null) {
66
+ if (ch == quote && !escaped) {
67
+ state.tokenize = tokenBase;
68
+ break;
69
+ }
70
+ escaped = !escaped && ch == "\\";
71
+ }
72
+ return "string";
73
+ };
74
+ }
75
+
76
+ function pushContext(state, type, col) {
77
+ state.context = {prev: state.context, indent: state.indent, col: col, type: type};
78
+ }
79
+ function popContext(state) {
80
+ state.indent = state.context.indent;
81
+ state.context = state.context.prev;
82
+ }
83
+
84
+ return {
85
+ startState: function(base) {
86
+ return {tokenize: tokenBase,
87
+ context: null,
88
+ indent: 0,
89
+ col: 0};
90
+ },
91
+
92
+ token: function(stream, state) {
93
+ if (stream.sol()) {
94
+ if (state.context && state.context.align == null) state.context.align = false;
95
+ state.indent = stream.indentation();
96
+ }
97
+ if (stream.eatSpace()) return null;
98
+ var style = state.tokenize(stream, state);
99
+
100
+ if (style != "comment" && state.context && state.context.align == null && state.context.type != "pattern") {
101
+ state.context.align = true;
102
+ }
103
+
104
+ if (curPunc == "(") pushContext(state, ")", stream.column());
105
+ else if (curPunc == "[") pushContext(state, "]", stream.column());
106
+ else if (curPunc == "{") pushContext(state, "}", stream.column());
107
+ else if (/[\]\}\)]/.test(curPunc)) {
108
+ while (state.context && state.context.type == "pattern") popContext(state);
109
+ if (state.context && curPunc == state.context.type) popContext(state);
110
+ }
111
+ else if (curPunc == "." && state.context && state.context.type == "pattern") popContext(state);
112
+ else if (/atom|string|variable/.test(style) && state.context) {
113
+ if (/[\}\]]/.test(state.context.type))
114
+ pushContext(state, "pattern", stream.column());
115
+ else if (state.context.type == "pattern" && !state.context.align) {
116
+ state.context.align = true;
117
+ state.context.col = stream.column();
118
+ }
119
+ }
120
+
121
+ return style;
122
+ },
123
+
124
+ indent: function(state, textAfter) {
125
+ var firstChar = textAfter && textAfter.charAt(0);
126
+ var context = state.context;
127
+ if (/[\]\}]/.test(firstChar))
128
+ while (context && context.type == "pattern") context = context.prev;
129
+
130
+ var closing = context && firstChar == context.type;
131
+ if (!context)
132
+ return 0;
133
+ else if (context.type == "pattern")
134
+ return context.col;
135
+ else if (context.align)
136
+ return context.col + (closing ? 0 : 1);
137
+ else
138
+ return context.indent + (closing ? 0 : indentUnit);
139
+ }
140
+ };
141
+ });
142
+
143
+ CodeMirror.defineMIME("application/x-sparql-query", "sparql");
@@ -0,0 +1,96 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>CodeMirror 2: sTeX mode</title>
5
+ <link rel="stylesheet" href="../../lib/codemirror.css">
6
+ <script src="../../lib/codemirror.js"></script>
7
+ <script src="stex.js"></script>
8
+ <link rel="stylesheet" href="../../theme/default.css">
9
+ <style>.CodeMirror {background: #f8f8f8;}</style>
10
+ <link rel="stylesheet" href="../../css/docs.css">
11
+ </head>
12
+ <body>
13
+ <h1>CodeMirror 2: sTeX mode</h1>
14
+ <form><textarea id="code" name="code">
15
+ \begin{module}[id=bbt-size]
16
+ \importmodule[balanced-binary-trees]{balanced-binary-trees}
17
+ \importmodule[\KWARCslides{dmath/en/cardinality}]{cardinality}
18
+
19
+ \begin{frame}
20
+ \frametitle{Size Lemma for Balanced Trees}
21
+ \begin{itemize}
22
+ \item
23
+ \begin{assertion}[id=size-lemma,type=lemma]
24
+ Let $G=\tup{V,E}$ be a \termref[cd=binary-trees]{balanced binary tree}
25
+ of \termref[cd=graph-depth,name=vertex-depth]{depth}$n>i$, then the set
26
+ $\defeq{\livar{V}i}{\setst{\inset{v}{V}}{\gdepth{v} = i}}$ of
27
+ \termref[cd=graphs-intro,name=node]{nodes} at
28
+ \termref[cd=graph-depth,name=vertex-depth]{depth} $i$ has
29
+ \termref[cd=cardinality,name=cardinality]{cardinality} $\power2i$.
30
+ \end{assertion}
31
+ \item
32
+ \begin{sproof}[id=size-lemma-pf,proofend=,for=size-lemma]{via induction over the depth $i$.}
33
+ \begin{spfcases}{We have to consider two cases}
34
+ \begin{spfcase}{$i=0$}
35
+ \begin{spfstep}[display=flow]
36
+ then $\livar{V}i=\set{\livar{v}r}$, where $\livar{v}r$ is the root, so
37
+ $\eq{\card{\livar{V}0},\card{\set{\livar{v}r}},1,\power20}$.
38
+ \end{spfstep}
39
+ \end{spfcase}
40
+ \begin{spfcase}{$i>0$}
41
+ \begin{spfstep}[display=flow]
42
+ then $\livar{V}{i-1}$ contains $\power2{i-1}$ vertexes
43
+ \begin{justification}[method=byIH](IH)\end{justification}
44
+ \end{spfstep}
45
+ \begin{spfstep}
46
+ By the \begin{justification}[method=byDef]definition of a binary
47
+ tree\end{justification}, each $\inset{v}{\livar{V}{i-1}}$ is a leaf or has
48
+ two children that are at depth $i$.
49
+ \end{spfstep}
50
+ \begin{spfstep}
51
+ As $G$ is \termref[cd=balanced-binary-trees,name=balanced-binary-tree]{balanced} and $\gdepth{G}=n>i$, $\livar{V}{i-1}$ cannot contain
52
+ leaves.
53
+ \end{spfstep}
54
+ \begin{spfstep}[type=conclusion]
55
+ Thus $\eq{\card{\livar{V}i},{\atimes[cdot]{2,\card{\livar{V}{i-1}}}},{\atimes[cdot]{2,\power2{i-1}}},\power2i}$.
56
+ \end{spfstep}
57
+ \end{spfcase}
58
+ \end{spfcases}
59
+ \end{sproof}
60
+ \item
61
+ \begin{assertion}[id=fbbt,type=corollary]
62
+ A fully balanced tree of depth $d$ has $\power2{d+1}-1$ nodes.
63
+ \end{assertion}
64
+ \item
65
+ \begin{sproof}[for=fbbt,id=fbbt-pf]{}
66
+ \begin{spfstep}
67
+ Let $\defeq{G}{\tup{V,E}}$ be a fully balanced tree
68
+ \end{spfstep}
69
+ \begin{spfstep}
70
+ Then $\card{V}=\Sumfromto{i}1d{\power2i}= \power2{d+1}-1$.
71
+ \end{spfstep}
72
+ \end{sproof}
73
+ \end{itemize}
74
+ \end{frame}
75
+ \begin{note}
76
+ \begin{omtext}[type=conclusion,for=binary-tree]
77
+ This shows that balanced binary trees grow in breadth very quickly, a consequence of
78
+ this is that they are very shallow (and this compute very fast), which is the essence of
79
+ the next result.
80
+ \end{omtext}
81
+ \end{note}
82
+ \end{module}
83
+
84
+ %%% Local Variables:
85
+ %%% mode: LaTeX
86
+ %%% TeX-master: "all"
87
+ %%% End: \end{document}
88
+ </textarea></form>
89
+ <script>
90
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
91
+ </script>
92
+
93
+ <p><strong>MIME types defined:</strong> <code>text/stex</code>.</p>
94
+
95
+ </body>
96
+ </html>