keydown 0.7.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.travis.yml +3 -0
- data/LICENSE +1 -1
- data/README.md +16 -15
- data/VERSION +1 -1
- data/keydown.gemspec +9 -6
- data/lib/keydown.rb +9 -22
- data/lib/keydown/html_helpers.rb +12 -0
- data/lib/keydown/{lib/slide.rb → slide.rb} +16 -19
- data/lib/keydown/{lib/slidedeck.rb → slidedeck.rb} +20 -5
- data/lib/keydown/tasks.rb +5 -0
- data/lib/keydown/tasks/base.rb +15 -0
- data/lib/keydown/tasks/generate.rb +5 -1
- data/lib/keydown/tasks/slides.rb +1 -1
- data/lib/version.rb +1 -1
- data/spec/lib/html_helpers_spec.rb +26 -0
- data/spec/lib/slide_spec.rb +29 -17
- data/spec/lib/slidedeck_spec.rb +41 -13
- data/spec/spec_helper.rb +2 -6
- data/spec/tasks/generate_spec.rb +41 -20
- data/spec/tasks/slides_spec.rb +83 -44
- data/templates/deck.js/code.html.haml +1 -0
- data/templates/deck.js/index.html.haml +54 -0
- data/templates/deck.js/slide.html.haml +6 -0
- data/templates/generate/css/%presentation_name%.css +12 -1
- data/templates/generate/deck.js/core/deck.core.css +394 -0
- data/templates/generate/deck.js/core/deck.core.js +461 -0
- data/templates/generate/deck.js/core/deck.core.scss +432 -0
- data/templates/generate/deck.js/extensions/codemirror/CONTRIBUTORS.txt +2 -0
- data/templates/generate/deck.js/extensions/codemirror/MIT-LICENSE.txt +21 -0
- data/templates/generate/deck.js/extensions/codemirror/README.md +120 -0
- data/templates/generate/deck.js/extensions/codemirror/VERSION.txt +1 -0
- data/templates/generate/deck.js/extensions/codemirror/codemirror.js +21 -0
- data/templates/generate/deck.js/extensions/codemirror/deck.codemirror.css +89 -0
- data/templates/generate/deck.js/extensions/codemirror/deck.codemirror.js +213 -0
- data/templates/generate/deck.js/extensions/codemirror/deck.codemirror.scss +107 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/clike/clike.js +247 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/clike/index.html +102 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/clojure/clojure.js +207 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/clojure/index.html +85 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/coffeescript/LICENSE +22 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/coffeescript/coffeescript.js +325 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/coffeescript/index.html +722 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/css/css.js +124 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/css/index.html +56 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/diff/diff.css +3 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/diff/diff.js +13 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/diff/index.html +99 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/haskell/haskell.js +242 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/haskell/index.html +60 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/htmlmixed/htmlmixed.js +79 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/htmlmixed/index.html +52 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/javascript/index.html +78 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/javascript/javascript.js +348 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/lua/index.html +72 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/lua/lua.js +138 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/php/index.html +49 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/php/php.js +115 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/plsql/index.html +63 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/plsql/plsql.js +217 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/python/LICENSE.txt +21 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/python/index.html +123 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/python/python.js +321 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/r/LICENSE +24 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/r/index.html +74 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/r/r.js +141 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/rst/index.html +526 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/rst/rst.css +75 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/rst/rst.js +333 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/ruby/LICENSE +24 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/ruby/index.html +172 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/ruby/ruby.js +195 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/scheme/index.html +65 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/scheme/scheme.js +202 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/smalltalk/index.html +56 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/smalltalk/smalltalk.js +122 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/sparql/index.html +41 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/sparql/sparql.js +143 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/stex/index.html +96 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/stex/stex.js +167 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/velocity/index.html +103 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/velocity/velocity.js +146 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/xml/index.html +42 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/xml/xml.js +231 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/xmlpure/index.html +60 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/xmlpure/xmlpure.js +481 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/yaml/index.html +68 -0
- data/templates/generate/deck.js/extensions/codemirror/mode/yaml/yaml.js +95 -0
- data/templates/generate/deck.js/extensions/codemirror/themes/cobalt.css +17 -0
- data/templates/generate/deck.js/extensions/codemirror/themes/default.css +19 -0
- data/templates/generate/deck.js/extensions/codemirror/themes/elegant.css +9 -0
- data/templates/generate/deck.js/extensions/codemirror/themes/neat.css +8 -0
- data/templates/generate/deck.js/extensions/codemirror/themes/night.css +20 -0
- data/templates/generate/deck.js/extensions/goto/deck.goto.css +41 -0
- data/templates/generate/deck.js/extensions/goto/deck.goto.html +6 -0
- data/templates/generate/deck.js/extensions/goto/deck.goto.js +118 -0
- data/templates/generate/deck.js/extensions/goto/deck.goto.scss +46 -0
- data/templates/generate/deck.js/extensions/hash/deck.hash.css +13 -0
- data/templates/generate/deck.js/extensions/hash/deck.hash.html +2 -0
- data/templates/generate/deck.js/extensions/hash/deck.hash.js +125 -0
- data/templates/generate/deck.js/extensions/hash/deck.hash.scss +15 -0
- data/templates/generate/deck.js/extensions/menu/deck.menu.css +24 -0
- data/templates/generate/deck.js/extensions/menu/deck.menu.js +127 -0
- data/templates/generate/deck.js/extensions/menu/deck.menu.scss +29 -0
- data/templates/generate/deck.js/extensions/navigation/deck.navigation.css +43 -0
- data/templates/generate/deck.js/extensions/navigation/deck.navigation.html +3 -0
- data/templates/generate/deck.js/extensions/navigation/deck.navigation.js +83 -0
- data/templates/generate/deck.js/extensions/navigation/deck.navigation.scss +56 -0
- data/templates/generate/deck.js/extensions/scale/deck.scale.css +16 -0
- data/templates/generate/deck.js/extensions/scale/deck.scale.js +155 -0
- data/templates/generate/deck.js/extensions/scale/deck.scale.scss +17 -0
- data/templates/generate/deck.js/extensions/status/deck.status.css +14 -0
- data/templates/generate/deck.js/extensions/status/deck.status.html +6 -0
- data/templates/generate/deck.js/extensions/status/deck.status.js +42 -0
- data/templates/generate/deck.js/extensions/status/deck.status.scss +16 -0
- data/templates/generate/deck.js/support/jquery.1.6.4.min.js +4 -0
- data/templates/generate/deck.js/support/modernizr.custom.js +4 -0
- data/templates/generate/deck.js/themes/style/neon.css +114 -0
- data/templates/generate/deck.js/themes/style/neon.scss +139 -0
- data/templates/generate/deck.js/themes/style/swiss.css +75 -0
- data/templates/generate/deck.js/themes/style/swiss.scss +91 -0
- data/templates/generate/deck.js/themes/style/web-2.0.css +187 -0
- data/templates/generate/deck.js/themes/style/web-2.0.scss +214 -0
- data/templates/generate/deck.js/themes/transition/fade.css +44 -0
- data/templates/generate/deck.js/themes/transition/fade.scss +70 -0
- data/templates/generate/deck.js/themes/transition/horizontal-slide.css +79 -0
- data/templates/generate/deck.js/themes/transition/horizontal-slide.scss +94 -0
- data/templates/generate/deck.js/themes/transition/vertical-slide.css +97 -0
- data/templates/generate/deck.js/themes/transition/vertical-slide.scss +116 -0
- data/templates/keydown.css.erb +27 -23
- metadata +171 -32
- data/Gemfile.lock +0 -41
- data/templates/generate/css/rocks.css +0 -392
- data/templates/generate/css/syntax_highlighting.css +0 -135
- data/templates/generate/js/rocks.js +0 -419
- data/templates/rocks/index.rhtml +0 -132
- data/templates/rocks/slide.rhtml +0 -10
@@ -0,0 +1,207 @@
|
|
1
|
+
/**
|
2
|
+
* Author: Hans Engel
|
3
|
+
* Branched from CodeMirror's Scheme mode (by Koh Zi Han, based on implementation by Koh Zi Chun)
|
4
|
+
*/
|
5
|
+
CodeMirror.defineMode("clojure", function (config, mode) {
|
6
|
+
var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", TAG = "tag",
|
7
|
+
ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD="keyword";
|
8
|
+
var INDENT_WORD_SKIP = 2, KEYWORDS_SKIP = 1;
|
9
|
+
|
10
|
+
function makeKeywords(str) {
|
11
|
+
var obj = {}, words = str.split(" ");
|
12
|
+
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
13
|
+
return obj;
|
14
|
+
}
|
15
|
+
|
16
|
+
var atoms = makeKeywords("true false nil");
|
17
|
+
|
18
|
+
var keywords = makeKeywords(
|
19
|
+
// Control structures
|
20
|
+
"defn defn- def def- defonce defmulti defmethod defmacro defstruct deftype defprotocol defrecord deftest slice defalias defhinted defmacro- defn-memo defnk defnk defonce- defunbound defunbound- defvar defvar- let letfn do case cond condp for loop recur when when-not when-let when-first if if-let if-not . .. -> ->> doto and or dosync doseq dotimes dorun doall load import unimport ns in-ns refer try catch finally throw with-open with-local-vars binding gen-class gen-and-load-class gen-and-save-class handler-case handle" +
|
21
|
+
|
22
|
+
// Built-ins
|
23
|
+
"* *1 *2 *3 *agent* *allow-unresolved-vars* *assert *clojure-version* *command-line-args* *compile-files* *compile-path* *e *err* *file* *flush-on-newline* *in* *macro-meta* *math-context* *ns* *out* *print-dup* *print-length* *print-level* *print-meta* *print-readably* *read-eval* *source-path* *use-context-classloader* *warn-on-reflection* + - / < <= = == > >= accessor aclone agent agent-errors aget alength alias all-ns alter alter-meta! alter-var-root amap ancestors and apply areduce array-map aset aset-boolean aset-byte aset-char aset-double aset-float aset-int aset-long aset-short assert assoc assoc! assoc-in associative? atom await await-for await1 bases bean bigdec bigint binding bit-and bit-and-not bit-clear bit-flip bit-not bit-or bit-set bit-shift-left bit-shift-right bit-test bit-xor boolean boolean-array booleans bound-fn bound-fn* butlast byte byte-array bytes case cast char char-array char-escape-string char-name-string char? chars chunk chunk-append chunk-buffer chunk-cons chunk-first chunk-next chunk-rest chunked-seq? class class? clear-agent-errors clojure-version coll? comment commute comp comparator compare compare-and-set! compile complement concat cond condp conj conj! cons constantly construct-proxy contains? count counted? create-ns create-struct cycle dec decimal? declare definline defmacro defmethod defmulti defn defn- defonce defstruct delay delay? deliver deref derive descendants destructure disj disj! dissoc dissoc! distinct distinct? doall doc dorun doseq dosync dotimes doto double double-array doubles drop drop-last drop-while empty empty? ensure enumeration-seq eval even? every? extend extend-protocol extend-type extends? extenders false? ffirst file-seq filter find find-doc find-ns find-var first float float-array float? floats flush fn fn? fnext for force format future future-call future-cancel future-cancelled? future-done? future? gen-class gen-interface gensym get get-in get-method get-proxy-class get-thread-bindings get-validator hash hash-map hash-set identical? identity if-let if-not ifn? import in-ns inc init-proxy instance? int int-array integer? interleave intern interpose into into-array ints io! isa? iterate iterator-seq juxt key keys keyword keyword? last lazy-cat lazy-seq let letfn line-seq list list* list? load load-file load-reader load-string loaded-libs locking long long-array longs loop macroexpand macroexpand-1 make-array make-hierarchy map map? mapcat max max-key memfn memoize merge merge-with meta method-sig methods min min-key mod name namespace neg? newline next nfirst nil? nnext not not-any? not-empty not-every? not= ns ns-aliases ns-imports ns-interns ns-map ns-name ns-publics ns-refers ns-resolve ns-unalias ns-unmap nth nthnext num number? odd? or parents partial partition pcalls peek persistent! pmap pop pop! pop-thread-bindings pos? pr pr-str prefer-method prefers primitives-classnames print print-ctor print-doc print-dup print-method print-namespace-doc print-simple print-special-doc print-str printf println println-str prn prn-str promise proxy proxy-call-with-super proxy-mappings proxy-name proxy-super push-thread-bindings pvalues quot rand rand-int range ratio? rational? rationalize re-find re-groups re-matcher re-matches re-pattern re-seq read read-line read-string reify reduce ref ref-history-count ref-max-history ref-min-history ref-set refer refer-clojure release-pending-sends rem remove remove-method remove-ns repeat repeatedly replace replicate require reset! reset-meta! resolve rest resultset-seq reverse reversible? rseq rsubseq satisfies? second select-keys send send-off seq seq? seque sequence sequential? set set-validator! set? short short-array shorts shutdown-agents slurp some sort sort-by sorted-map sorted-map-by sorted-set sorted-set-by sorted? special-form-anchor special-symbol? split-at split-with str stream? string? struct struct-map subs subseq subvec supers swap! symbol symbol? sync syntax-symbol-anchor take take-last take-nth take-while test the-ns time to-array to-array-2d trampoline transient tree-seq true? type unchecked-add unchecked-dec unchecked-divide unchecked-inc unchecked-multiply unchecked-negate unchecked-remainder unchecked-subtract underive unquote unquote-splicing update-in update-proxy use val vals var-get var-set var? vary-meta vec vector vector? when when-first when-let when-not while with-bindings with-bindings* with-in-str with-loading-context with-local-vars with-meta with-open with-out-str with-precision xml-seq");
|
24
|
+
|
25
|
+
var indentKeys = makeKeywords(
|
26
|
+
// Built-ins
|
27
|
+
"ns fn def defn defmethod bound-fn if if-not case condp when while when-not when-first do future comment doto locking proxy with-open with-precision reify deftype defrecord defprotocol extend extend-protocol extend-type try catch" +
|
28
|
+
|
29
|
+
// Binding forms
|
30
|
+
"let letfn binding loop for doseq dotimes when-let if-let" +
|
31
|
+
|
32
|
+
// Data structures
|
33
|
+
"defstruct struct-map assoc" +
|
34
|
+
|
35
|
+
// clojure.test
|
36
|
+
"testing deftest" +
|
37
|
+
|
38
|
+
// contrib
|
39
|
+
"handler-case handle dotrace deftrace");
|
40
|
+
|
41
|
+
var tests = {
|
42
|
+
digit: /\d/,
|
43
|
+
digit_or_colon: /[\d:]/,
|
44
|
+
hex: /[0-9a-fA-F]/,
|
45
|
+
sign: /[+-]/,
|
46
|
+
exponent: /[eE]/,
|
47
|
+
keyword_char: /[^\s\(\[\;\)\]]/,
|
48
|
+
basic: /[\w\$_\-]/,
|
49
|
+
lang_keyword: /[\w*+!\-_?:\/]/
|
50
|
+
};
|
51
|
+
|
52
|
+
function stateStack(indent, type, prev) { // represents a state stack object
|
53
|
+
this.indent = indent;
|
54
|
+
this.type = type;
|
55
|
+
this.prev = prev;
|
56
|
+
}
|
57
|
+
|
58
|
+
function pushStack(state, indent, type) {
|
59
|
+
state.indentStack = new stateStack(indent, type, state.indentStack);
|
60
|
+
}
|
61
|
+
|
62
|
+
function popStack(state) {
|
63
|
+
state.indentStack = state.indentStack.prev;
|
64
|
+
}
|
65
|
+
|
66
|
+
function isNumber(ch, stream){
|
67
|
+
// hex
|
68
|
+
if ( ch === '0' && 'x' == stream.peek().toLowerCase() ) {
|
69
|
+
stream.eat('x');
|
70
|
+
stream.eatWhile(tests.hex);
|
71
|
+
return true;
|
72
|
+
}
|
73
|
+
|
74
|
+
// leading sign
|
75
|
+
if ( ch == '+' || ch == '-' ) {
|
76
|
+
stream.eat(tests.sign);
|
77
|
+
ch = stream.next();
|
78
|
+
}
|
79
|
+
|
80
|
+
if ( tests.digit.test(ch) ) {
|
81
|
+
stream.eat(ch);
|
82
|
+
stream.eatWhile(tests.digit);
|
83
|
+
|
84
|
+
if ( '.' == stream.peek() ) {
|
85
|
+
stream.eat('.');
|
86
|
+
stream.eatWhile(tests.digit);
|
87
|
+
}
|
88
|
+
|
89
|
+
if ( 'e' == stream.peek().toLowerCase() ) {
|
90
|
+
stream.eat(tests.exponent);
|
91
|
+
stream.eat(tests.sign);
|
92
|
+
stream.eatWhile(tests.digit);
|
93
|
+
}
|
94
|
+
|
95
|
+
return true;
|
96
|
+
}
|
97
|
+
|
98
|
+
return false;
|
99
|
+
}
|
100
|
+
|
101
|
+
return {
|
102
|
+
startState: function () {
|
103
|
+
return {
|
104
|
+
indentStack: null,
|
105
|
+
indentation: 0,
|
106
|
+
mode: false,
|
107
|
+
};
|
108
|
+
},
|
109
|
+
|
110
|
+
token: function (stream, state) {
|
111
|
+
if (state.indentStack == null && stream.sol()) {
|
112
|
+
// update indentation, but only if indentStack is empty
|
113
|
+
state.indentation = stream.indentation();
|
114
|
+
}
|
115
|
+
|
116
|
+
// skip spaces
|
117
|
+
if (stream.eatSpace()) {
|
118
|
+
return null;
|
119
|
+
}
|
120
|
+
var returnType = null;
|
121
|
+
|
122
|
+
switch(state.mode){
|
123
|
+
case "string": // multi-line string parsing mode
|
124
|
+
var next, escaped = false;
|
125
|
+
while ((next = stream.next()) != null) {
|
126
|
+
if (next == "\"" && !escaped) {
|
127
|
+
|
128
|
+
state.mode = false;
|
129
|
+
break;
|
130
|
+
}
|
131
|
+
escaped = !escaped && next == "\\";
|
132
|
+
}
|
133
|
+
returnType = STRING; // continue on in string mode
|
134
|
+
break;
|
135
|
+
default: // default parsing mode
|
136
|
+
var ch = stream.next();
|
137
|
+
|
138
|
+
if (ch == "\"") {
|
139
|
+
state.mode = "string";
|
140
|
+
returnType = STRING;
|
141
|
+
} else if (ch == "'" && !( tests.digit_or_colon.test(stream.peek()) )) {
|
142
|
+
returnType = ATOM;
|
143
|
+
} else if (ch == ";") { // comment
|
144
|
+
stream.skipToEnd(); // rest of the line is a comment
|
145
|
+
returnType = COMMENT;
|
146
|
+
} else if (isNumber(ch,stream)){
|
147
|
+
returnType = NUMBER;
|
148
|
+
} else if (ch == "(" || ch == "[") {
|
149
|
+
var keyWord = ''; var indentTemp = stream.column();
|
150
|
+
/**
|
151
|
+
Either
|
152
|
+
(indent-word ..
|
153
|
+
(non-indent-word ..
|
154
|
+
(;something else, bracket, etc.
|
155
|
+
*/
|
156
|
+
|
157
|
+
while ((letter = stream.eat(tests.keyword_char)) != null) {
|
158
|
+
keyWord += letter;
|
159
|
+
}
|
160
|
+
|
161
|
+
if (keyWord.length > 0 && indentKeys.propertyIsEnumerable(keyWord)) { // indent-word
|
162
|
+
|
163
|
+
pushStack(state, indentTemp + INDENT_WORD_SKIP, ch);
|
164
|
+
} else { // non-indent word
|
165
|
+
// we continue eating the spaces
|
166
|
+
stream.eatSpace();
|
167
|
+
if (stream.eol() || stream.peek() == ";") {
|
168
|
+
// nothing significant after
|
169
|
+
// we restart indentation 1 space after
|
170
|
+
pushStack(state, indentTemp + 1, ch);
|
171
|
+
} else {
|
172
|
+
pushStack(state, indentTemp + stream.current().length, ch); // else we match
|
173
|
+
}
|
174
|
+
}
|
175
|
+
stream.backUp(stream.current().length - 1); // undo all the eating
|
176
|
+
|
177
|
+
returnType = BRACKET;
|
178
|
+
} else if (ch == ")" || ch == "]") {
|
179
|
+
returnType = BRACKET;
|
180
|
+
if (state.indentStack != null && state.indentStack.type == (ch == ")" ? "(" : "[")) {
|
181
|
+
popStack(state);
|
182
|
+
}
|
183
|
+
} else if ( ch == ":" ) {
|
184
|
+
stream.eatWhile(tests.lang_keyword);
|
185
|
+
return TAG;
|
186
|
+
} else {
|
187
|
+
stream.eatWhile(tests.basic);
|
188
|
+
|
189
|
+
if (keywords && keywords.propertyIsEnumerable(stream.current())) {
|
190
|
+
returnType = BUILTIN;
|
191
|
+
} else if ( atoms && atoms.propertyIsEnumerable(stream.current()) ) {
|
192
|
+
returnType = ATOM;
|
193
|
+
} else returnType = null;
|
194
|
+
}
|
195
|
+
}
|
196
|
+
|
197
|
+
return returnType;
|
198
|
+
},
|
199
|
+
|
200
|
+
indent: function (state, textAfter) {
|
201
|
+
if (state.indentStack == null) return state.indentation;
|
202
|
+
return state.indentStack.indent;
|
203
|
+
}
|
204
|
+
};
|
205
|
+
});
|
206
|
+
|
207
|
+
CodeMirror.defineMIME("text/x-clojure", "clojure");
|
@@ -0,0 +1,85 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>CodeMirror 2: Clojure mode</title>
|
5
|
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
6
|
+
<script src="../../lib/codemirror.js"></script>
|
7
|
+
<script src="clojure.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: Clojure mode</h1>
|
14
|
+
<form><textarea id="code" name="code">
|
15
|
+
; Conway's Game of Life, from http://rosettacode.org/wiki/Conway%27s_Game_of_Life#Clojure
|
16
|
+
(defstruct grid :w :h :cells)
|
17
|
+
|
18
|
+
(defn get-cell
|
19
|
+
"Returns the value at x,y. The grid is treated as a torus, such that both x and
|
20
|
+
y coordinates will wrap around if greater than width and height respectively."
|
21
|
+
[grid x y]
|
22
|
+
(let [x (mod x (:w grid))
|
23
|
+
y (mod y (:h grid))]
|
24
|
+
(-> grid :cells (nth y) (nth x))))
|
25
|
+
|
26
|
+
(defn neighbors
|
27
|
+
"Returns a lazy sequence of all neighbors of the specified cell."
|
28
|
+
[grid x y]
|
29
|
+
(for [j [(dec y) y (inc y)]
|
30
|
+
i [(dec x) x (inc x)]
|
31
|
+
:when (not (and (= i x) (= j y)))]
|
32
|
+
(get-cell grid i j)))
|
33
|
+
|
34
|
+
(defn evolve-cell
|
35
|
+
"Returns the new state of the specifed cell."
|
36
|
+
[grid x y]
|
37
|
+
(let [c (get-cell grid x y)
|
38
|
+
n (reduce + (neighbors grid x y))]
|
39
|
+
(if (or (and (zero? c) (= 3 n))
|
40
|
+
(and (= 1 c) (or (= 2 n) (= 3 n))))
|
41
|
+
1 0)))
|
42
|
+
|
43
|
+
(defn evolve-grid
|
44
|
+
"Returns a new grid whose cells have all been evolved."
|
45
|
+
[grid]
|
46
|
+
(assoc grid :cells
|
47
|
+
(vec (for [y (range (:h grid))]
|
48
|
+
(vec (for [x (range (:w grid))]
|
49
|
+
(evolve-cell grid x y)))))))
|
50
|
+
|
51
|
+
(defn generations [grid]
|
52
|
+
"Returns a lazy sequence of the grid, and all subsequent generations."
|
53
|
+
(iterate evolve-grid grid))
|
54
|
+
|
55
|
+
(defn make-grid [w h & row-patterns]
|
56
|
+
(let [cells (vec (for [rp row-patterns]
|
57
|
+
(vec (mapcat #(take %1 (repeat %2)) rp (cycle [0 1])))))]
|
58
|
+
(if (and (= h (count cells))
|
59
|
+
(every? #(= w (count %)) cells))
|
60
|
+
(struct grid w h cells)
|
61
|
+
(throw (IllegalArgumentException. "Resulting cells do not match expected width/height.")))))
|
62
|
+
|
63
|
+
(defn display-row [row]
|
64
|
+
(do (dorun (map print (map #(if (zero? %) " . " "[X]") row))) (println)))
|
65
|
+
|
66
|
+
(defn display-grid [grid]
|
67
|
+
(dorun (map display-row (:cells grid))))
|
68
|
+
|
69
|
+
(defn display-grids [grids]
|
70
|
+
(dorun
|
71
|
+
(interleave
|
72
|
+
(repeatedly println)
|
73
|
+
(map display-grid grids))))
|
74
|
+
|
75
|
+
(def blinker (make-grid 5 5 [5] [5] [1 3 1] [5] [5]))
|
76
|
+
(display-grids (take 3 (generations blinker)))
|
77
|
+
</textarea></form>
|
78
|
+
<script>
|
79
|
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
|
80
|
+
</script>
|
81
|
+
|
82
|
+
<p><strong>MIME types defined:</strong> <code>text/x-clojure</code>.</p>
|
83
|
+
|
84
|
+
</body>
|
85
|
+
</html>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2011 Jeff Pickhardt
|
4
|
+
Modified from the Python CodeMirror mode, Copyright (c) 2010 Timothy Farrell
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
14
|
+
all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
THE SOFTWARE.
|
@@ -0,0 +1,325 @@
|
|
1
|
+
/**
|
2
|
+
* Link to the project's GitHub page:
|
3
|
+
* https://github.com/pickhardt/coffeescript-codemirror-mode
|
4
|
+
*/
|
5
|
+
CodeMirror.defineMode('coffeescript', function(conf) {
|
6
|
+
var ERRORCLASS = 'error';
|
7
|
+
|
8
|
+
function wordRegexp(words) {
|
9
|
+
return new RegExp("^((" + words.join(")|(") + "))\\b");
|
10
|
+
}
|
11
|
+
|
12
|
+
var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!\?]");
|
13
|
+
var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]');
|
14
|
+
var doubleOperators = new RegExp("^((\->)|(\=>)|(\\+\\+)|(\\+\\=)|(\\-\\-)|(\\-\\=)|(\\*\\*)|(\\*\\=)|(\\/\\/)|(\\/\\=)|(==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//))");
|
15
|
+
var doubleDelimiters = new RegExp("^((\\.\\.)|(\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))");
|
16
|
+
var tripleDelimiters = new RegExp("^((\\.\\.\\.)|(//=)|(>>=)|(<<=)|(\\*\\*=))");
|
17
|
+
var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");
|
18
|
+
|
19
|
+
var wordOperators = wordRegexp(['and', 'or', 'not',
|
20
|
+
'is', 'isnt', 'in',
|
21
|
+
'instanceof', 'typeof']);
|
22
|
+
var indentKeywords = ['for', 'while', 'loop', 'if', 'unless', 'else',
|
23
|
+
'switch', 'try', 'catch', 'finally', 'class'];
|
24
|
+
var commonKeywords = ['break', 'by', 'continue', 'debugger', 'delete',
|
25
|
+
'do', 'in', 'of', 'new', 'return', 'then',
|
26
|
+
'this', 'throw', 'when', 'until'];
|
27
|
+
|
28
|
+
var keywords = wordRegexp(indentKeywords.concat(commonKeywords));
|
29
|
+
|
30
|
+
indentKeywords = wordRegexp(indentKeywords);
|
31
|
+
|
32
|
+
|
33
|
+
var stringPrefixes = new RegExp("^('{3}|\"{3}|['\"])");
|
34
|
+
var regexPrefixes = new RegExp("^(/{3}|/)");
|
35
|
+
var commonConstants = ['Infinity', 'NaN', 'undefined', 'true', 'false', 'on', 'off', 'yes', 'no'];
|
36
|
+
var constants = wordRegexp(commonConstants);
|
37
|
+
|
38
|
+
// Tokenizers
|
39
|
+
function tokenBase(stream, state) {
|
40
|
+
// Handle scope changes
|
41
|
+
if (stream.sol()) {
|
42
|
+
var scopeOffset = state.scopes[0].offset;
|
43
|
+
if (stream.eatSpace()) {
|
44
|
+
var lineOffset = stream.indentation();
|
45
|
+
if (lineOffset > scopeOffset) {
|
46
|
+
return 'indent';
|
47
|
+
} else if (lineOffset < scopeOffset) {
|
48
|
+
return 'dedent';
|
49
|
+
}
|
50
|
+
return null;
|
51
|
+
} else {
|
52
|
+
if (scopeOffset > 0) {
|
53
|
+
dedent(stream, state);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
if (stream.eatSpace()) {
|
58
|
+
return null;
|
59
|
+
}
|
60
|
+
|
61
|
+
var ch = stream.peek();
|
62
|
+
|
63
|
+
// Handle comments
|
64
|
+
if (ch === '#') {
|
65
|
+
stream.skipToEnd();
|
66
|
+
return 'comment';
|
67
|
+
}
|
68
|
+
|
69
|
+
// Handle number literals
|
70
|
+
if (stream.match(/^-?[0-9\.]/, false)) {
|
71
|
+
var floatLiteral = false;
|
72
|
+
// Floats
|
73
|
+
if (stream.match(/^-?\d*\.\d+(e[\+\-]?\d+)?/i)) {
|
74
|
+
floatLiteral = true;
|
75
|
+
}
|
76
|
+
if (stream.match(/^-?\d+\.\d*/)) {
|
77
|
+
floatLiteral = true;
|
78
|
+
}
|
79
|
+
if (stream.match(/^-?\.\d+/)) {
|
80
|
+
floatLiteral = true;
|
81
|
+
}
|
82
|
+
if (floatLiteral) {
|
83
|
+
return 'number';
|
84
|
+
}
|
85
|
+
// Integers
|
86
|
+
var intLiteral = false;
|
87
|
+
// Hex
|
88
|
+
if (stream.match(/^-?0x[0-9a-f]+/i)) {
|
89
|
+
intLiteral = true;
|
90
|
+
}
|
91
|
+
// Decimal
|
92
|
+
if (stream.match(/^-?[1-9]\d*(e[\+\-]?\d+)?/)) {
|
93
|
+
intLiteral = true;
|
94
|
+
}
|
95
|
+
// Zero by itself with no other piece of number.
|
96
|
+
if (stream.match(/^-?0(?![\dx])/i)) {
|
97
|
+
intLiteral = true;
|
98
|
+
}
|
99
|
+
if (intLiteral) {
|
100
|
+
return 'number';
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
// Handle strings
|
105
|
+
if (stream.match(stringPrefixes)) {
|
106
|
+
state.tokenize = tokenFactory(stream.current(), 'string');
|
107
|
+
return state.tokenize(stream, state);
|
108
|
+
}
|
109
|
+
// Handle regex literals
|
110
|
+
if (stream.match(regexPrefixes)) {
|
111
|
+
if (stream.current() != '/' || stream.match(/^.*\//, false)) { // prevent highlight of division
|
112
|
+
state.tokenize = tokenFactory(stream.current(), 'string-2');
|
113
|
+
return state.tokenize(stream, state);
|
114
|
+
} else {
|
115
|
+
stream.backUp(1);
|
116
|
+
}
|
117
|
+
}
|
118
|
+
|
119
|
+
// Handle operators and delimiters
|
120
|
+
if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) {
|
121
|
+
return 'punctuation';
|
122
|
+
}
|
123
|
+
if (stream.match(doubleOperators)
|
124
|
+
|| stream.match(singleOperators)
|
125
|
+
|| stream.match(wordOperators)) {
|
126
|
+
return 'operator';
|
127
|
+
}
|
128
|
+
if (stream.match(singleDelimiters)) {
|
129
|
+
return 'punctuation';
|
130
|
+
}
|
131
|
+
|
132
|
+
if (stream.match(constants)) {
|
133
|
+
return 'atom';
|
134
|
+
}
|
135
|
+
|
136
|
+
if (stream.match(keywords)) {
|
137
|
+
return 'keyword';
|
138
|
+
}
|
139
|
+
|
140
|
+
if (stream.match(identifiers)) {
|
141
|
+
return 'variable';
|
142
|
+
}
|
143
|
+
|
144
|
+
// Handle non-detected items
|
145
|
+
stream.next();
|
146
|
+
return ERRORCLASS;
|
147
|
+
}
|
148
|
+
|
149
|
+
function tokenFactory(delimiter, outclass) {
|
150
|
+
var delim_re = new RegExp(delimiter);
|
151
|
+
var singleline = delimiter.length == 1;
|
152
|
+
|
153
|
+
return function tokenString(stream, state) {
|
154
|
+
while (!stream.eol()) {
|
155
|
+
stream.eatWhile(/[^'"\/\\]/);
|
156
|
+
if (stream.eat('\\')) {
|
157
|
+
stream.next();
|
158
|
+
if (singleline && stream.eol()) {
|
159
|
+
return outclass;
|
160
|
+
}
|
161
|
+
} else if (stream.match(delim_re)) {
|
162
|
+
state.tokenize = tokenBase;
|
163
|
+
return outclass;
|
164
|
+
} else {
|
165
|
+
stream.eat(/['"\/]/);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
if (singleline) {
|
169
|
+
if (conf.mode.singleLineStringErrors) {
|
170
|
+
outclass = ERRORCLASS
|
171
|
+
} else {
|
172
|
+
state.tokenize = tokenBase;
|
173
|
+
}
|
174
|
+
}
|
175
|
+
return outclass;
|
176
|
+
};
|
177
|
+
}
|
178
|
+
|
179
|
+
function indent(stream, state, type) {
|
180
|
+
type = type || 'coffee';
|
181
|
+
var indentUnit = 0;
|
182
|
+
if (type === 'coffee') {
|
183
|
+
for (var i = 0; i < state.scopes.length; i++) {
|
184
|
+
if (state.scopes[i].type === 'coffee') {
|
185
|
+
indentUnit = state.scopes[i].offset + conf.indentUnit;
|
186
|
+
break;
|
187
|
+
}
|
188
|
+
}
|
189
|
+
} else {
|
190
|
+
indentUnit = stream.column() + stream.current().length;
|
191
|
+
}
|
192
|
+
state.scopes.unshift({
|
193
|
+
offset: indentUnit,
|
194
|
+
type: type
|
195
|
+
});
|
196
|
+
}
|
197
|
+
|
198
|
+
function dedent(stream, state) {
|
199
|
+
if (state.scopes.length == 1) return;
|
200
|
+
if (state.scopes[0].type === 'coffee') {
|
201
|
+
var _indent = stream.indentation();
|
202
|
+
var _indent_index = -1;
|
203
|
+
for (var i = 0; i < state.scopes.length; ++i) {
|
204
|
+
if (_indent === state.scopes[i].offset) {
|
205
|
+
_indent_index = i;
|
206
|
+
break;
|
207
|
+
}
|
208
|
+
}
|
209
|
+
if (_indent_index === -1) {
|
210
|
+
return true;
|
211
|
+
}
|
212
|
+
while (state.scopes[0].offset !== _indent) {
|
213
|
+
state.scopes.shift();
|
214
|
+
}
|
215
|
+
return false
|
216
|
+
} else {
|
217
|
+
state.scopes.shift();
|
218
|
+
return false;
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
function tokenLexer(stream, state) {
|
223
|
+
var style = state.tokenize(stream, state);
|
224
|
+
var current = stream.current();
|
225
|
+
|
226
|
+
// Handle '.' connected identifiers
|
227
|
+
if (current === '.') {
|
228
|
+
style = state.tokenize(stream, state);
|
229
|
+
current = stream.current();
|
230
|
+
if (style === 'variable') {
|
231
|
+
return 'variable';
|
232
|
+
} else {
|
233
|
+
return ERRORCLASS;
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
// Handle properties
|
238
|
+
if (current === '@') {
|
239
|
+
style = state.tokenize(stream, state);
|
240
|
+
current = stream.current();
|
241
|
+
if (style === 'variable') {
|
242
|
+
return 'variable-2';
|
243
|
+
} else {
|
244
|
+
return ERRORCLASS;
|
245
|
+
}
|
246
|
+
}
|
247
|
+
|
248
|
+
// Handle scope changes.
|
249
|
+
if (current === 'return') {
|
250
|
+
state.dedent += 1;
|
251
|
+
}
|
252
|
+
if (((current === '->' || current === '=>') &&
|
253
|
+
!state.lambda &&
|
254
|
+
state.scopes[0].type == 'coffee' &&
|
255
|
+
stream.peek() === '')
|
256
|
+
|| style === 'indent') {
|
257
|
+
indent(stream, state);
|
258
|
+
}
|
259
|
+
var delimiter_index = '[({'.indexOf(current);
|
260
|
+
if (delimiter_index !== -1) {
|
261
|
+
indent(stream, state, '])}'.slice(delimiter_index, delimiter_index+1));
|
262
|
+
}
|
263
|
+
if (indentKeywords.exec(current)){
|
264
|
+
indent(stream, state);
|
265
|
+
}
|
266
|
+
if (current == 'then'){
|
267
|
+
dedent(stream, state);
|
268
|
+
}
|
269
|
+
|
270
|
+
|
271
|
+
if (style === 'dedent') {
|
272
|
+
if (dedent(stream, state)) {
|
273
|
+
return ERRORCLASS;
|
274
|
+
}
|
275
|
+
}
|
276
|
+
delimiter_index = '])}'.indexOf(current);
|
277
|
+
if (delimiter_index !== -1) {
|
278
|
+
if (dedent(stream, state)) {
|
279
|
+
return ERRORCLASS;
|
280
|
+
}
|
281
|
+
}
|
282
|
+
if (state.dedent > 0 && stream.eol() && state.scopes[0].type == 'coffee') {
|
283
|
+
if (state.scopes.length > 1) state.scopes.shift();
|
284
|
+
state.dedent -= 1;
|
285
|
+
}
|
286
|
+
|
287
|
+
return style;
|
288
|
+
}
|
289
|
+
|
290
|
+
var external = {
|
291
|
+
startState: function(basecolumn) {
|
292
|
+
return {
|
293
|
+
tokenize: tokenBase,
|
294
|
+
scopes: [{offset:basecolumn || 0, type:'coffee'}],
|
295
|
+
lastToken: null,
|
296
|
+
lambda: false,
|
297
|
+
dedent: 0
|
298
|
+
};
|
299
|
+
},
|
300
|
+
|
301
|
+
token: function(stream, state) {
|
302
|
+
var style = tokenLexer(stream, state);
|
303
|
+
|
304
|
+
state.lastToken = {style:style, content: stream.current()};
|
305
|
+
|
306
|
+
if (stream.eol() && stream.lambda) {
|
307
|
+
state.lambda = false;
|
308
|
+
}
|
309
|
+
|
310
|
+
return style;
|
311
|
+
},
|
312
|
+
|
313
|
+
indent: function(state, textAfter) {
|
314
|
+
if (state.tokenize != tokenBase) {
|
315
|
+
return 0;
|
316
|
+
}
|
317
|
+
|
318
|
+
return state.scopes[0].offset;
|
319
|
+
}
|
320
|
+
|
321
|
+
};
|
322
|
+
return external;
|
323
|
+
});
|
324
|
+
|
325
|
+
CodeMirror.defineMIME('text/x-coffeescript', 'coffeescript');
|