summaryrefslogtreecommitdiff
path: root/codemirror_ui/lib/CodeMirror-2.3/mode/velocity
diff options
context:
space:
mode:
Diffstat (limited to 'codemirror_ui/lib/CodeMirror-2.3/mode/velocity')
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/mode/velocity/index.html103
-rw-r--r--codemirror_ui/lib/CodeMirror-2.3/mode/velocity/velocity.js146
2 files changed, 249 insertions, 0 deletions
diff --git a/codemirror_ui/lib/CodeMirror-2.3/mode/velocity/index.html b/codemirror_ui/lib/CodeMirror-2.3/mode/velocity/index.html
new file mode 100644
index 0000000..49dba38
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/mode/velocity/index.html
@@ -0,0 +1,103 @@
+<!doctype html>
+<html>
+ <head>
+ <title>CodeMirror: Velocity mode</title>
+ <link rel="stylesheet" href="../../lib/codemirror.css">
+ <script src="../../lib/codemirror.js"></script>
+ <script src="velocity.js"></script>
+ <link rel="stylesheet" href="../../theme/night.css">
+ <style>.CodeMirror {border: 1px solid black;}</style>
+ <link rel="stylesheet" href="../../doc/docs.css">
+ </head>
+ <body>
+ <h1>CodeMirror: Velocity mode</h1>
+ <form><textarea id="code" name="code">
+## Velocity Code Demo
+#*
+ based on PL/SQL mode by Peter Raganitsch, adapted to Velocity by Steve O'Hara ( http://www.pivotal-solutions.co.uk )
+ August 2011
+*#
+
+#*
+ This is a multiline comment.
+ This is the second line
+*#
+
+#[[ hello steve
+ This has invalid syntax that would normally need "poor man's escaping" like:
+
+ #define()
+
+ ${blah
+]]#
+
+#include( "disclaimer.txt" "opinion.txt" )
+#include( $foo $bar )
+
+#parse( "lecorbusier.vm" )
+#parse( $foo )
+
+#evaluate( 'string with VTL #if(true)will be displayed#end' )
+
+#define( $hello ) Hello $who #end #set( $who = "World!") $hello ## displays Hello World!
+
+#foreach( $customer in $customerList )
+
+ $foreach.count $customer.Name
+
+ #if( $foo == ${bar})
+ it's true!
+ #break
+ #{else}
+ it's not!
+ #stop
+ #end
+
+ #if ($foreach.parent.hasNext)
+ $velocityCount
+ #end
+#end
+
+$someObject.getValues("this is a string split
+ across lines")
+
+#macro( tablerows $color $somelist )
+ #foreach( $something in $somelist )
+ <tr><td bgcolor=$color>$something</td></tr>
+ #end
+#end
+
+#tablerows("red" ["dadsdf","dsa"])
+
+ Variable reference: #set( $monkey = $bill )
+ String literal: #set( $monkey.Friend = 'monica' )
+ Property reference: #set( $monkey.Blame = $whitehouse.Leak )
+ Method reference: #set( $monkey.Plan = $spindoctor.weave($web) )
+ Number literal: #set( $monkey.Number = 123 )
+ Range operator: #set( $monkey.Numbers = [1..3] )
+ Object list: #set( $monkey.Say = ["Not", $my, "fault"] )
+ Object map: #set( $monkey.Map = {"banana" : "good", "roast beef" : "bad"})
+
+The RHS can also be a simple arithmetic expression, such as:
+Addition: #set( $value = $foo + 1 )
+ Subtraction: #set( $value = $bar - 1 )
+ Multiplication: #set( $value = $foo * $bar )
+ Division: #set( $value = $foo / $bar )
+ Remainder: #set( $value = $foo % $bar )
+
+</textarea></form>
+ <script>
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
+ tabMode: "indent",
+ matchBrackets: true,
+ theme: "night",
+ lineNumbers: true,
+ indentUnit: 4,
+ mode: "text/velocity"
+ });
+ </script>
+
+ <p><strong>MIME types defined:</strong> <code>text/velocity</code>.</p>
+
+ </body>
+</html>
diff --git a/codemirror_ui/lib/CodeMirror-2.3/mode/velocity/velocity.js b/codemirror_ui/lib/CodeMirror-2.3/mode/velocity/velocity.js
new file mode 100644
index 0000000..0b80c75
--- /dev/null
+++ b/codemirror_ui/lib/CodeMirror-2.3/mode/velocity/velocity.js
@@ -0,0 +1,146 @@
+CodeMirror.defineMode("velocity", function(config) {
+ function parseWords(str) {
+ var obj = {}, words = str.split(" ");
+ for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
+ return obj;
+ }
+
+ var indentUnit = config.indentUnit
+ var keywords = parseWords("#end #else #break #stop #[[ #]] " +
+ "#{end} #{else} #{break} #{stop}");
+ var functions = parseWords("#if #elseif #foreach #set #include #parse #macro #define #evaluate " +
+ "#{if} #{elseif} #{foreach} #{set} #{include} #{parse} #{macro} #{define} #{evaluate}");
+ var specials = parseWords("$foreach.count $foreach.hasNext $foreach.first $foreach.last $foreach.topmost $foreach.parent $velocityCount");
+ var isOperatorChar = /[+\-*&%=<>!?:\/|]/;
+ var multiLineStrings =true;
+
+ function chain(stream, state, f) {
+ state.tokenize = f;
+ return f(stream, state);
+ }
+ function tokenBase(stream, state) {
+ var beforeParams = state.beforeParams;
+ state.beforeParams = false;
+ var ch = stream.next();
+ // start of string?
+ if ((ch == '"' || ch == "'") && state.inParams)
+ return chain(stream, state, tokenString(ch));
+ // is it one of the special signs []{}().,;? Seperator?
+ else if (/[\[\]{}\(\),;\.]/.test(ch)) {
+ if (ch == "(" && beforeParams) state.inParams = true;
+ else if (ch == ")") state.inParams = false;
+ return null;
+ }
+ // start of a number value?
+ else if (/\d/.test(ch)) {
+ stream.eatWhile(/[\w\.]/);
+ return "number";
+ }
+ // multi line comment?
+ else if (ch == "#" && stream.eat("*")) {
+ return chain(stream, state, tokenComment);
+ }
+ // unparsed content?
+ else if (ch == "#" && stream.match(/ *\[ *\[/)) {
+ return chain(stream, state, tokenUnparsed);
+ }
+ // single line comment?
+ else if (ch == "#" && stream.eat("#")) {
+ stream.skipToEnd();
+ return "comment";
+ }
+ // variable?
+ else if (ch == "$") {
+ stream.eatWhile(/[\w\d\$_\.{}]/);
+ // is it one of the specials?
+ if (specials && specials.propertyIsEnumerable(stream.current().toLowerCase())) {
+ return "keyword";
+ }
+ else {
+ state.beforeParams = true;
+ return "builtin";
+ }
+ }
+ // is it a operator?
+ else if (isOperatorChar.test(ch)) {
+ stream.eatWhile(isOperatorChar);
+ return "operator";
+ }
+ else {
+ // get the whole word
+ stream.eatWhile(/[\w\$_{}]/);
+ var word = stream.current().toLowerCase();
+ // is it one of the listed keywords?
+ if (keywords && keywords.propertyIsEnumerable(word))
+ return "keyword";
+ // is it one of the listed functions?
+ if (functions && functions.propertyIsEnumerable(word) ||
+ stream.current().match(/^#[a-z0-9_]+ *$/i) && stream.peek()=="(") {
+ state.beforeParams = true;
+ return "keyword";
+ }
+ // default: just a "word"
+ return null;
+ }
+ }
+
+ function tokenString(quote) {
+ return function(stream, state) {
+ var escaped = false, next, end = false;
+ while ((next = stream.next()) != null) {
+ if (next == quote && !escaped) {
+ end = true;
+ break;
+ }
+ escaped = !escaped && next == "\\";
+ }
+ if (end) state.tokenize = tokenBase;
+ return "string";
+ };
+ }
+
+ function tokenComment(stream, state) {
+ var maybeEnd = false, ch;
+ while (ch = stream.next()) {
+ if (ch == "#" && maybeEnd) {
+ state.tokenize = tokenBase;
+ break;
+ }
+ maybeEnd = (ch == "*");
+ }
+ return "comment";
+ }
+
+ function tokenUnparsed(stream, state) {
+ var maybeEnd = 0, ch;
+ while (ch = stream.next()) {
+ if (ch == "#" && maybeEnd == 2) {
+ state.tokenize = tokenBase;
+ break;
+ }
+ if (ch == "]")
+ maybeEnd++;
+ else if (ch != " ")
+ maybeEnd = 0;
+ }
+ return "meta";
+ }
+ // Interface
+
+ return {
+ startState: function(basecolumn) {
+ return {
+ tokenize: tokenBase,
+ beforeParams: false,
+ inParams: false
+ };
+ },
+
+ token: function(stream, state) {
+ if (stream.eatSpace()) return null;
+ return state.tokenize(stream, state);
+ }
+ };
+});
+
+CodeMirror.defineMIME("text/velocity", "velocity");