5 <title>CodeMirror: Groovy mode</title>
6 <link rel="stylesheet" href="../../lib/codemirror.css">
7 <script src="../../lib/codemirror.js"></script>
8 <script src="../../addon/edit/matchbrackets.js"></script>
9 <script src="groovy.js"></script>
10 <link rel="stylesheet" href="../../doc/docs.css">
11 <style>.CodeMirror {border-top: 1px solid #500; border-bottom: 1px solid #500;}</style>
14 <h1>CodeMirror: Groovy mode</h1>
16 <form><textarea id="code" name="code">
17 //Pattern for groovy script
19 new File( 'd:\\scripts' ).eachFileMatch(p) {f ->
23 // condition to detect an import instruction
24 ln -> if ( ln =~ '^import .*' ) {
25 imports << "${ln - 'import '}"
29 if ( ! imports.empty ) {
31 imports.each{ println " $it" }
35 /* Coin changer demo code from http://groovy.codehaus.org */
38 quarter(25), dime(10), nickel(5), penny(1)
39 UsCoin(v) { value = v }
44 fifty(50), twenty(20), ten(10), five(5)
45 OzzieCoin(v) { value = v }
49 def plural(word, count) {
50 if (count == 1) return word
51 word[-1] == 'y' ? word[0..-2] + "ies" : word + "s"
54 def change(currency, amount) {
55 currency.values().inject([]){ list, coin ->
56 int count = amount / coin.value
57 amount = amount % coin.value
58 list += "$count ${plural(coin.toString(), count)}"
64 var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
71 <p><strong>MIME types defined:</strong> <code>text/x-groovy</code></p>