index.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>CodeMirror: Velocity mode</title>
  6. <link rel="stylesheet" href="../../lib/codemirror.css">
  7. <script src="../../lib/codemirror.js"></script>
  8. <script src="velocity.js"></script>
  9. <link rel="stylesheet" href="../../theme/night.css">
  10. <style>.CodeMirror {border: 1px solid black;}</style>
  11. <link rel="stylesheet" href="../../doc/docs.css">
  12. </head>
  13. <body>
  14. <h1>CodeMirror: Velocity mode</h1>
  15. <form><textarea id="code" name="code">
  16. ## Velocity Code Demo
  17. #*
  18. based on PL/SQL mode by Peter Raganitsch, adapted to Velocity by Steve O'Hara ( http://www.pivotal-solutions.co.uk )
  19. August 2011
  20. *#
  21. #*
  22. This is a multiline comment.
  23. This is the second line
  24. *#
  25. #[[ hello steve
  26. This has invalid syntax that would normally need "poor man's escaping" like:
  27. #define()
  28. ${blah
  29. ]]#
  30. #include( "disclaimer.txt" "opinion.txt" )
  31. #include( $foo $bar )
  32. #parse( "lecorbusier.vm" )
  33. #parse( $foo )
  34. #evaluate( 'string with VTL #if(true)will be displayed#end' )
  35. #define( $hello ) Hello $who #end #set( $who = "World!") $hello ## displays Hello World!
  36. #foreach( $customer in $customerList )
  37. $foreach.count $customer.Name
  38. #if( $foo == ${bar})
  39. it's true!
  40. #break
  41. #{else}
  42. it's not!
  43. #stop
  44. #end
  45. #if ($foreach.parent.hasNext)
  46. $velocityCount
  47. #end
  48. #end
  49. $someObject.getValues("this is a string split
  50. across lines")
  51. #macro( tablerows $color $somelist )
  52. #foreach( $something in $somelist )
  53. <tr><td bgcolor=$color>$something</td></tr>
  54. #end
  55. #end
  56. #tablerows("red" ["dadsdf","dsa"])
  57. Variable reference: #set( $monkey = $bill )
  58. String literal: #set( $monkey.Friend = 'monica' )
  59. Property reference: #set( $monkey.Blame = $whitehouse.Leak )
  60. Method reference: #set( $monkey.Plan = $spindoctor.weave($web) )
  61. Number literal: #set( $monkey.Number = 123 )
  62. Range operator: #set( $monkey.Numbers = [1..3] )
  63. Object list: #set( $monkey.Say = ["Not", $my, "fault"] )
  64. Object map: #set( $monkey.Map = {"banana" : "good", "roast beef" : "bad"})
  65. The RHS can also be a simple arithmetic expression, such as:
  66. Addition: #set( $value = $foo + 1 )
  67. Subtraction: #set( $value = $bar - 1 )
  68. Multiplication: #set( $value = $foo * $bar )
  69. Division: #set( $value = $foo / $bar )
  70. Remainder: #set( $value = $foo % $bar )
  71. </textarea></form>
  72. <script>
  73. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  74. tabMode: "indent",
  75. theme: "night",
  76. lineNumbers: true,
  77. indentUnit: 4,
  78. mode: "text/velocity"
  79. });
  80. </script>
  81. <p><strong>MIME types defined:</strong> <code>text/velocity</code>.</p>
  82. </body>
  83. </html>