ledger_web 1.2
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.
- data/.gitignore +10 -0
- data/LICENSE +7 -0
- data/README.md +140 -0
- data/Rakefile +11 -0
- data/bin/ledger_web +14 -0
- data/ledger_web.gemspec +26 -0
- data/lib/ledger_web/app.rb +69 -0
- data/lib/ledger_web/config.rb +87 -0
- data/lib/ledger_web/db/migrate/20111226180900_initial_schema.rb +38 -0
- data/lib/ledger_web/db/migrate/20111231132900_add_views.rb +37 -0
- data/lib/ledger_web/db.rb +54 -0
- data/lib/ledger_web/helpers.rb +62 -0
- data/lib/ledger_web/public/bootstrap-dropdown.js +55 -0
- data/lib/ledger_web/public/bootstrap.min.css +356 -0
- data/lib/ledger_web/public/codemirror/keymap/emacs.js +29 -0
- data/lib/ledger_web/public/codemirror/keymap/vim.js +76 -0
- data/lib/ledger_web/public/codemirror/lib/codemirror.css +104 -0
- data/lib/ledger_web/public/codemirror/lib/codemirror.js +2761 -0
- data/lib/ledger_web/public/codemirror/lib/util/dialog.css +23 -0
- data/lib/ledger_web/public/codemirror/lib/util/dialog.js +63 -0
- data/lib/ledger_web/public/codemirror/lib/util/foldcode.js +66 -0
- data/lib/ledger_web/public/codemirror/lib/util/formatting.js +291 -0
- data/lib/ledger_web/public/codemirror/lib/util/javascript-hint.js +83 -0
- data/lib/ledger_web/public/codemirror/lib/util/overlay.js +51 -0
- data/lib/ledger_web/public/codemirror/lib/util/runmode.js +27 -0
- data/lib/ledger_web/public/codemirror/lib/util/search.js +114 -0
- data/lib/ledger_web/public/codemirror/lib/util/searchcursor.js +117 -0
- data/lib/ledger_web/public/codemirror/lib/util/simple-hint.css +16 -0
- data/lib/ledger_web/public/codemirror/lib/util/simple-hint.js +66 -0
- data/lib/ledger_web/public/codemirror/mode/clike/clike.js +249 -0
- data/lib/ledger_web/public/codemirror/mode/clike/index.html +101 -0
- data/lib/ledger_web/public/codemirror/mode/clojure/clojure.js +207 -0
- data/lib/ledger_web/public/codemirror/mode/clojure/index.html +66 -0
- data/lib/ledger_web/public/codemirror/mode/coffeescript/LICENSE +22 -0
- data/lib/ledger_web/public/codemirror/mode/coffeescript/coffeescript.js +325 -0
- data/lib/ledger_web/public/codemirror/mode/coffeescript/index.html +721 -0
- data/lib/ledger_web/public/codemirror/mode/css/css.js +124 -0
- data/lib/ledger_web/public/codemirror/mode/css/index.html +55 -0
- data/lib/ledger_web/public/codemirror/mode/diff/diff.css +3 -0
- data/lib/ledger_web/public/codemirror/mode/diff/diff.js +13 -0
- data/lib/ledger_web/public/codemirror/mode/diff/index.html +99 -0
- data/lib/ledger_web/public/codemirror/mode/gfm/gfm.js +108 -0
- data/lib/ledger_web/public/codemirror/mode/gfm/index.html +47 -0
- data/lib/ledger_web/public/codemirror/mode/groovy/groovy.js +210 -0
- data/lib/ledger_web/public/codemirror/mode/groovy/index.html +71 -0
- data/lib/ledger_web/public/codemirror/mode/haskell/haskell.js +242 -0
- data/lib/ledger_web/public/codemirror/mode/haskell/index.html +60 -0
- data/lib/ledger_web/public/codemirror/mode/htmlembedded/htmlembedded.js +68 -0
- data/lib/ledger_web/public/codemirror/mode/htmlembedded/index.html +49 -0
- data/lib/ledger_web/public/codemirror/mode/htmlmixed/htmlmixed.js +83 -0
- data/lib/ledger_web/public/codemirror/mode/htmlmixed/index.html +51 -0
- data/lib/ledger_web/public/codemirror/mode/javascript/index.html +77 -0
- data/lib/ledger_web/public/codemirror/mode/javascript/javascript.js +360 -0
- data/lib/ledger_web/public/codemirror/mode/jinja2/index.html +37 -0
- data/lib/ledger_web/public/codemirror/mode/jinja2/jinja2.js +42 -0
- data/lib/ledger_web/public/codemirror/mode/lua/index.html +72 -0
- data/lib/ledger_web/public/codemirror/mode/lua/lua.js +140 -0
- data/lib/ledger_web/public/codemirror/mode/markdown/index.html +339 -0
- data/lib/ledger_web/public/codemirror/mode/markdown/markdown.js +242 -0
- data/lib/ledger_web/public/codemirror/mode/ntriples/index.html +32 -0
- data/lib/ledger_web/public/codemirror/mode/ntriples/ntriples.js +172 -0
- data/lib/ledger_web/public/codemirror/mode/pascal/LICENSE +7 -0
- data/lib/ledger_web/public/codemirror/mode/pascal/index.html +48 -0
- data/lib/ledger_web/public/codemirror/mode/pascal/pascal.js +138 -0
- data/lib/ledger_web/public/codemirror/mode/perl/LICENSE +19 -0
- data/lib/ledger_web/public/codemirror/mode/perl/index.html +62 -0
- data/lib/ledger_web/public/codemirror/mode/perl/perl.js +816 -0
- data/lib/ledger_web/public/codemirror/mode/php/index.html +48 -0
- data/lib/ledger_web/public/codemirror/mode/php/php.js +120 -0
- data/lib/ledger_web/public/codemirror/mode/plsql/index.html +62 -0
- data/lib/ledger_web/public/codemirror/mode/plsql/plsql.js +217 -0
- data/lib/ledger_web/public/codemirror/mode/python/LICENSE.txt +21 -0
- data/lib/ledger_web/public/codemirror/mode/python/index.html +122 -0
- data/lib/ledger_web/public/codemirror/mode/python/python.js +333 -0
- data/lib/ledger_web/public/codemirror/mode/r/LICENSE +24 -0
- data/lib/ledger_web/public/codemirror/mode/r/index.html +73 -0
- data/lib/ledger_web/public/codemirror/mode/r/r.js +141 -0
- data/lib/ledger_web/public/codemirror/mode/rpm/changes/changes.js +19 -0
- data/lib/ledger_web/public/codemirror/mode/rpm/changes/index.html +53 -0
- data/lib/ledger_web/public/codemirror/mode/rpm/spec/index.html +99 -0
- data/lib/ledger_web/public/codemirror/mode/rpm/spec/spec.css +5 -0
- data/lib/ledger_web/public/codemirror/mode/rpm/spec/spec.js +66 -0
- data/lib/ledger_web/public/codemirror/mode/rst/index.html +525 -0
- data/lib/ledger_web/public/codemirror/mode/rst/rst.js +326 -0
- data/lib/ledger_web/public/codemirror/mode/ruby/LICENSE +24 -0
- data/lib/ledger_web/public/codemirror/mode/ruby/index.html +171 -0
- data/lib/ledger_web/public/codemirror/mode/ruby/ruby.js +195 -0
- data/lib/ledger_web/public/codemirror/mode/rust/index.html +48 -0
- data/lib/ledger_web/public/codemirror/mode/rust/rust.js +411 -0
- data/lib/ledger_web/public/codemirror/mode/scheme/index.html +64 -0
- data/lib/ledger_web/public/codemirror/mode/scheme/scheme.js +202 -0
- data/lib/ledger_web/public/codemirror/mode/smalltalk/index.html +55 -0
- data/lib/ledger_web/public/codemirror/mode/smalltalk/smalltalk.js +139 -0
- data/lib/ledger_web/public/codemirror/mode/sparql/index.html +40 -0
- data/lib/ledger_web/public/codemirror/mode/sparql/sparql.js +143 -0
- data/lib/ledger_web/public/codemirror/mode/stex/index.html +95 -0
- data/lib/ledger_web/public/codemirror/mode/stex/stex.js +167 -0
- data/lib/ledger_web/public/codemirror/mode/tiddlywiki/index.html +183 -0
- data/lib/ledger_web/public/codemirror/mode/tiddlywiki/tiddlywiki.css +21 -0
- data/lib/ledger_web/public/codemirror/mode/tiddlywiki/tiddlywiki.js +374 -0
- data/lib/ledger_web/public/codemirror/mode/velocity/index.html +103 -0
- data/lib/ledger_web/public/codemirror/mode/velocity/velocity.js +146 -0
- data/lib/ledger_web/public/codemirror/mode/xml/index.html +44 -0
- data/lib/ledger_web/public/codemirror/mode/xml/xml.js +252 -0
- data/lib/ledger_web/public/codemirror/mode/xmlpure/index.html +59 -0
- data/lib/ledger_web/public/codemirror/mode/xmlpure/xmlpure.js +485 -0
- data/lib/ledger_web/public/codemirror/mode/yaml/index.html +67 -0
- data/lib/ledger_web/public/codemirror/mode/yaml/yaml.js +95 -0
- data/lib/ledger_web/public/codemirror/theme/cobalt.css +18 -0
- data/lib/ledger_web/public/codemirror/theme/eclipse.css +25 -0
- data/lib/ledger_web/public/codemirror/theme/elegant.css +10 -0
- data/lib/ledger_web/public/codemirror/theme/monokai.css +28 -0
- data/lib/ledger_web/public/codemirror/theme/neat.css +9 -0
- data/lib/ledger_web/public/codemirror/theme/night.css +21 -0
- data/lib/ledger_web/public/codemirror/theme/rubyblue.css +21 -0
- data/lib/ledger_web/public/jquery-1.7.1.min.js +4 -0
- data/lib/ledger_web/public/jquery.tablesorter.min.js +4 -0
- data/lib/ledger_web/public/ledger.css +14 -0
- data/lib/ledger_web/report.rb +187 -0
- data/lib/ledger_web/reports/savings_rate.erb +49 -0
- data/lib/ledger_web/version.rb +3 -0
- data/lib/ledger_web/views/error.erb +5 -0
- data/lib/ledger_web/views/help.erb +6 -0
- data/lib/ledger_web/views/layout.erb +44 -0
- data/lib/ledger_web/views/table.erb +31 -0
- data/lib/ledger_web/watcher.rb +37 -0
- data/lib/ledger_web.rb +20 -0
- metadata +229 -0
@@ -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,66 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>CodeMirror: 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
|
+
<style>.CodeMirror {background: #f8f8f8;}</style>
|
9
|
+
<link rel="stylesheet" href="../../doc/docs.css">
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
<h1>CodeMirror: Clojure mode</h1>
|
13
|
+
<form><textarea id="code" name="code">
|
14
|
+
; Conway's Game of Life, based on the work of:
|
15
|
+
;; Laurent Petit https://gist.github.com/1200343
|
16
|
+
;; Christophe Grand http://clj-me.cgrand.net/2011/08/19/conways-game-of-life
|
17
|
+
|
18
|
+
(ns ^{:doc "Conway's Game of Life."}
|
19
|
+
game-of-life)
|
20
|
+
|
21
|
+
;; Core game of life's algorithm functions
|
22
|
+
|
23
|
+
(defn neighbours
|
24
|
+
"Given a cell's coordinates, returns the coordinates of its neighbours."
|
25
|
+
[[x y]]
|
26
|
+
(for [dx [-1 0 1] dy (if (zero? dx) [-1 1] [-1 0 1])]
|
27
|
+
[(+ dx x) (+ dy y)]))
|
28
|
+
|
29
|
+
(defn step
|
30
|
+
"Given a set of living cells, computes the new set of living cells."
|
31
|
+
[cells]
|
32
|
+
(set (for [[cell n] (frequencies (mapcat neighbours cells))
|
33
|
+
:when (or (= n 3) (and (= n 2) (cells cell)))]
|
34
|
+
cell)))
|
35
|
+
|
36
|
+
;; Utility methods for displaying game on a text terminal
|
37
|
+
|
38
|
+
(defn print-board
|
39
|
+
"Prints a board on *out*, representing a step in the game."
|
40
|
+
[board w h]
|
41
|
+
(doseq [x (range (inc w)) y (range (inc h))]
|
42
|
+
(if (= y 0) (print "\n"))
|
43
|
+
(print (if (board [x y]) "[X]" " . "))))
|
44
|
+
|
45
|
+
(defn display-grids
|
46
|
+
"Prints a squence of boards on *out*, representing several steps."
|
47
|
+
[grids w h]
|
48
|
+
(doseq [board grids]
|
49
|
+
(print-board board w h)
|
50
|
+
(print "\n")))
|
51
|
+
|
52
|
+
;; Launches an example board
|
53
|
+
|
54
|
+
(def
|
55
|
+
^{:doc "board represents the initial set of living cells"}
|
56
|
+
board #{[2 1] [2 2] [2 3]})
|
57
|
+
|
58
|
+
(display-grids (take 3 (iterate step board)) 5 5) </textarea></form>
|
59
|
+
<script>
|
60
|
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
|
61
|
+
</script>
|
62
|
+
|
63
|
+
<p><strong>MIME types defined:</strong> <code>text/x-clojure</code>.</p>
|
64
|
+
|
65
|
+
</body>
|
66
|
+
</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', 'null', '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');
|