| 5 |
lars |
1 |
<!doctype html>
|
|
|
2 |
<title>CodeMirror: Groovy mode</title>
|
|
|
3 |
<meta charset="utf-8" />
|
|
|
4 |
<link rel=stylesheet href="../../doc/docs.css">
|
|
|
5 |
<link rel="stylesheet" href="../../lib/codemirror.css">
|
|
|
6 |
<script src="../../lib/codemirror.js"></script>
|
|
|
7 |
<script src="../../addon/edit/matchbrackets.js"></script>
|
|
|
8 |
<script src="groovy.js"></script>
|
|
|
9 |
<style>
|
|
|
10 |
.CodeMirror {
|
|
|
11 |
border-top: 1px solid #500;
|
|
|
12 |
border-bottom: 1px solid #500;
|
|
|
13 |
}
|
|
|
14 |
</style>
|
|
|
15 |
<div id=nav>
|
|
|
16 |
<a href="http://codemirror.net">
|
|
|
17 |
<h1>CodeMirror</h1>
|
|
|
18 |
<img id=logo src="../../doc/logo.png">
|
|
|
19 |
</a>
|
|
|
20 |
<ul>
|
|
|
21 |
<li>
|
|
|
22 |
<a href="../../index.html">Home</a>
|
|
|
23 |
<li>
|
|
|
24 |
<a href="../../doc/manual.html">Manual</a>
|
|
|
25 |
<li>
|
|
|
26 |
<a href="https://github.com/codemirror/codemirror">Code</a>
|
|
|
27 |
</ul>
|
|
|
28 |
<ul>
|
|
|
29 |
<li>
|
|
|
30 |
<a href="../index.html">Language modes</a>
|
|
|
31 |
<li>
|
|
|
32 |
<a class=active href="#">Groovy</a>
|
|
|
33 |
</ul>
|
|
|
34 |
</div>
|
|
|
35 |
<article>
|
|
|
36 |
<h2>Groovy mode</h2>
|
|
|
37 |
<form>
|
|
|
38 |
<textarea id="code" name="code"> //Pattern for groovy script def p = ~/.*\.groovy/ new File( 'd:\\scripts' ).eachFileMatch(p) {f -> // imports list def imports = [] f.eachLine { // condition to detect an import instruction ln -> if ( ln =~ '^import .*' ) { imports
|
|
|
39 |
<<
|
|
|
40 |
"${ln - 'import '}" } } // print thmen if ( ! imports.empty ) { println f imports.each{ println " $it" } } } /* Coin changer demo code from http://groovy.codehaus.org */ enum UsCoin { quarter(25), dime(10), nickel(5), penny(1) UsCoin(v) { value=v } final
|
|
|
41 |
value } enum OzzieCoin { fifty(50), twenty(20), ten(10), five(5) OzzieCoin(v) { value=v } final value } def plural(word, count) { if (count==1 ) return word word[-1]=='y' ? word[0..-2] + "ies" : word + "s" } def change(currency, amount) {
|
|
|
42 |
currency.values().inject([]){ list, coin -> int count = amount / coin.value amount = amount % coin.value list += "$count ${plural(coin.toString(), count)}" } } </textarea>
|
|
|
43 |
</form>
|
|
|
44 |
<script>
|
|
|
45 |
var editor = CodeMirror.fromTextArea(document.getElementById("code"),
|
|
|
46 |
{
|
|
|
47 |
lineNumbers: true,
|
|
|
48 |
matchBrackets: true,
|
|
|
49 |
mode: "text/x-groovy"
|
|
|
50 |
});
|
|
|
51 |
</script>
|
|
|
52 |
<p>
|
|
|
53 |
<strong>MIME types defined:</strong> <code>text/x-groovy</code></p>
|
|
|
54 |
</article>
|