index.html 2.1 KB

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