diff options
Diffstat (limited to 'codemirror_ui/lib/CodeMirror-2.3/mode/smarty')
-rw-r--r-- | codemirror_ui/lib/CodeMirror-2.3/mode/smarty/index.html | 82 | ||||
-rw-r--r-- | codemirror_ui/lib/CodeMirror-2.3/mode/smarty/smarty.js | 148 |
2 files changed, 230 insertions, 0 deletions
diff --git a/codemirror_ui/lib/CodeMirror-2.3/mode/smarty/index.html b/codemirror_ui/lib/CodeMirror-2.3/mode/smarty/index.html new file mode 100644 index 0000000..ad4dccf --- /dev/null +++ b/codemirror_ui/lib/CodeMirror-2.3/mode/smarty/index.html @@ -0,0 +1,82 @@ +<!doctype html> +<html> + <head> + <title>CodeMirror: Smarty mode</title> + <link rel="stylesheet" href="../../lib/codemirror.css"> + <script src="../../lib/codemirror.js"></script> + <script src="smarty.js"></script> + <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> + <link rel="stylesheet" href="../../doc/docs.css"> + </head> + <body> + <h1>CodeMirror: Smarty mode</h1> + + <form><textarea id="code" name="code"> +{extends file="parent.tpl"} +{include file="template.tpl"} + +{* some example Smarty content *} +{if isset($name) && $name == 'Blog'} + This is a {$var}. + {$integer = 451}, {$array[] = "a"}, {$stringvar = "string"} + {assign var='bob' value=$var.prop} +{elseif $name == $foo} + {function name=menu level=0} + {foreach $data as $entry} + {if is_array($entry)} + - {$entry@key} + {menu data=$entry level=$level+1} + {else} + {$entry} + {/if} + {/foreach} + {/function} +{/if}</textarea></form> + + <script> + var editor = CodeMirror.fromTextArea(document.getElementById("code"), { + lineNumbers: true, + mode: "smarty" + }); + </script> + + <br /> + + <form><textarea id="code2" name="code2"> +{--extends file="parent.tpl"--} +{--include file="template.tpl"--} + +{--* some example Smarty content *--} +{--if isset($name) && $name == 'Blog'--} + This is a {--$var--}. + {--$integer = 451--}, {--$array[] = "a"--}, {--$stringvar = "string"--} + {--assign var='bob' value=$var.prop--} +{--elseif $name == $foo--} + {--function name=menu level=0--} + {--foreach $data as $entry--} + {--if is_array($entry)--} + - {--$entry@key--} + {--menu data=$entry level=$level+1--} + {--else--} + {--$entry--} + {--/if--} + {--/foreach--} + {--/function--} +{--/if--}</textarea></form> + + <script> + var editor = CodeMirror.fromTextArea(document.getElementById("code2"), { + lineNumbers: true, + mode: { + name: "smarty", + leftDelimiter: "{--", + rightDelimiter: "--}" + } + }); + </script> + + <p>A plain text/Smarty mode which allows for custom delimiter tags (defaults to <b>{</b> and <b>}</b>).</p> + + <p><strong>MIME types defined:</strong> <code>text/x-smarty</code></p> + </body> +</html> diff --git a/codemirror_ui/lib/CodeMirror-2.3/mode/smarty/smarty.js b/codemirror_ui/lib/CodeMirror-2.3/mode/smarty/smarty.js new file mode 100644 index 0000000..9da7da6 --- /dev/null +++ b/codemirror_ui/lib/CodeMirror-2.3/mode/smarty/smarty.js @@ -0,0 +1,148 @@ +CodeMirror.defineMode("smarty", function(config, parserConfig) { + var keyFuncs = ["debug", "extends", "function", "include", "literal"]; + var last; + var regs = { + operatorChars: /[+\-*&%=<>!?]/, + validIdentifier: /[a-zA-Z0-9\_]/, + stringChar: /[\'\"]/ + } + var leftDelim = (typeof config.mode.leftDelimiter != 'undefined') ? config.mode.leftDelimiter : "{"; + var rightDelim = (typeof config.mode.rightDelimiter != 'undefined') ? config.mode.rightDelimiter : "}"; + function ret(style, lst) { last = lst; return style; } + + + function tokenizer(stream, state) { + function chain(parser) { + state.tokenize = parser; + return parser(stream, state); + } + + if (stream.match(leftDelim, true)) { + if (stream.eat("*")) { + return chain(inBlock("comment", "*" + rightDelim)); + } + else { + state.tokenize = inSmarty; + return "tag"; + } + } + else { + // I'd like to do an eatWhile() here, but I can't get it to eat only up to the rightDelim string/char + stream.next(); + return null; + } + } + + function inSmarty(stream, state) { + if (stream.match(rightDelim, true)) { + state.tokenize = tokenizer; + return ret("tag", null); + } + + var ch = stream.next(); + if (ch == "$") { + stream.eatWhile(regs.validIdentifier); + return ret("variable-2", "variable"); + } + else if (ch == ".") { + return ret("operator", "property"); + } + else if (regs.stringChar.test(ch)) { + state.tokenize = inAttribute(ch); + return ret("string", "string"); + } + else if (regs.operatorChars.test(ch)) { + stream.eatWhile(regs.operatorChars); + return ret("operator", "operator"); + } + else if (ch == "[" || ch == "]") { + return ret("bracket", "bracket"); + } + else if (/\d/.test(ch)) { + stream.eatWhile(/\d/); + return ret("number", "number"); + } + else { + if (state.last == "variable") { + if (ch == "@") { + stream.eatWhile(regs.validIdentifier); + return ret("property", "property"); + } + else if (ch == "|") { + stream.eatWhile(regs.validIdentifier); + return ret("qualifier", "modifier"); + } + } + else if (state.last == "whitespace") { + stream.eatWhile(regs.validIdentifier); + return ret("attribute", "modifier"); + } + else if (state.last == "property") { + stream.eatWhile(regs.validIdentifier); + return ret("property", null); + } + else if (/\s/.test(ch)) { + last = "whitespace"; + return null; + } + + var str = ""; + if (ch != "/") { + str += ch; + } + var c = ""; + while ((c = stream.eat(regs.validIdentifier))) { + str += c; + } + var i, j; + for (i=0, j=keyFuncs.length; i<j; i++) { + if (keyFuncs[i] == str) { + return ret("keyword", "keyword"); + } + } + if (/\s/.test(ch)) { + return null; + } + return ret("tag", "tag"); + } + } + + function inAttribute(quote) { + return function(stream, state) { + while (!stream.eol()) { + if (stream.next() == quote) { + state.tokenize = inSmarty; + break; + } + } + return "string"; + }; + } + + function inBlock(style, terminator) { + return function(stream, state) { + while (!stream.eol()) { + if (stream.match(terminator)) { + state.tokenize = tokenizer; + break; + } + stream.next(); + } + return style; + }; + } + + return { + startState: function() { + return { tokenize: tokenizer, mode: "smarty", last: null }; + }, + token: function(stream, state) { + var style = state.tokenize(stream, state); + state.last = last; + return style; + }, + electricChars: "" + } +}); + +CodeMirror.defineMIME("text/x-smarty", "smarty");
\ No newline at end of file |