diff --git a/doc/compress.html b/doc/compress.html index c729cc6ed878f4ab7926ed63d6456c3a1544fe90..eb8b007d47473d122a1f8008bdefd570856b6ae8 100644 --- a/doc/compress.html +++ b/doc/compress.html @@ -165,6 +165,8 @@ <option value="http://codemirror.net/mode/smalltalk/smalltalk.js">smalltalk.js</option> <option value="http://codemirror.net/mode/smarty/smarty.js">smarty.js</option> <option value="http://codemirror.net/mode/smartymixed/smartymixed.js">smartymixed.js</option> + <option value="http://codemirror.net/mode/solr/solr.js">solr.js</option> + <option value="http://codemirror.net/mode/soy/soy.js">soy.js</option> <option value="http://codemirror.net/mode/sql/sql.js">sql.js</option> <option value="http://codemirror.net/mode/sparql/sparql.js">sparql.js</option> <option value="http://codemirror.net/mode/stex/stex.js">stex.js</option> diff --git a/mode/index.html b/mode/index.html index 14a3f10ea45b17defdd1746a4eb76d00ac5854d0..cccd3b48b9fea32787a7ba2e969a71cfe794117d 100644 --- a/mode/index.html +++ b/mode/index.html @@ -106,6 +106,7 @@ option.</p> <li><a href="smarty/index.html">Smarty</a></li> <li><a href="smartymixed/index.html">Smarty/HTML mixed</a></li> <li><a href="solr/index.html">Solr</a></li> + <li><a href="soy/index.html">Soy</a></li> <li><a href="sql/index.html">SQL</a> (several dialects)</li> <li><a href="sparql/index.html">SPARQL</a></li> <li><a href="stex/index.html">sTeX, LaTeX</a></li> diff --git a/mode/meta.js b/mode/meta.js index 12332002c057b3373ca46e7f7576f53e74ca13f8..507b0cc55b5b438038ed9945bfa193d5d43d3d92 100644 --- a/mode/meta.js +++ b/mode/meta.js @@ -105,6 +105,7 @@ {name: "Smarty", mime: "text/x-smarty", mode: "smarty", ext: ["tpl"]}, {name: "SmartyMixed", mime: "text/x-smarty", mode: "smartymixed"}, {name: "Solr", mime: "text/x-solr", mode: "solr"}, + {name: "Soy", mime: "text/x-soy", mode: "soy", ext: ["soy"], alias: ["closure template"]}, {name: "SPARQL", mime: "application/sparql-query", mode: "sparql", ext: ["rq", "sparql"], alias: ["sparul"]}, {name: "SQL", mime: "text/x-sql", mode: "sql", ext: ["sql"]}, {name: "MariaDB", mime: "text/x-mariadb", mode: "sql"}, diff --git a/mode/soy/soy.js b/mode/soy/soy.js index 2973971d2096231c2a9f707cc6b6e63d0a68fc00..025d1e3a1db1d2e0165687913322cd83a06f7e39 100644 --- a/mode/soy/soy.js +++ b/mode/soy/soy.js @@ -11,7 +11,7 @@ })(function(CodeMirror) { "use strict"; - CodeMirror.defineMode("soy", function(config, parserConfig) { + CodeMirror.defineMode("soy", function(config) { var textMode = CodeMirror.getMode(config, "text/plain"); var modes = { html: CodeMirror.getMode(config, "text/html"), @@ -22,7 +22,9 @@ js: CodeMirror.getMode(config, "text/javascript") }; - var indentingTags = ["template", "literal", "msg", "fallbackmsg", "let", "if", "elseif", "else", "switch", "case", "default", "foreach", "ifempty", "for", "call", "param", "log"]; + var indentingTags = ["template", "literal", "msg", "fallbackmsg", "let", "if", "elseif", + "else", "switch", "case", "default", "foreach", "ifempty", "for", + "call", "param", "log"]; function last(array) { return array[array.length - 1]; @@ -117,7 +119,6 @@ stream.skipToEnd(); } return "string"; - } if (stream.match(/^\/\*/)) { @@ -133,7 +134,7 @@ state.indent = stream.indentation() + config.indentUnit; state.soyState.push("literal"); return "keyword"; - } else if (match = stream.match(/^\{([/@\\]?\w*)/i)) { + } else if (match = stream.match(/^\{([\/@\\]?\w*)/i)) { state.indent = stream.indentation() + 2 * config.indentUnit; state.tag = match[1]; if (state.tag == "/" + last(state.kindTag)) { @@ -151,16 +152,20 @@ }, indent: function(state, textAfter) { - if (/^\{(\/|fallbackmsg|elseif|else|ifempty)\b/.test(textAfter)) { + if (/^\{(\/|(fallbackmsg|elseif|else|ifempty)\b)/.test(textAfter)) return state.indent - config.indentUnit; - } + // TODO: Defer to inner modes. return state.indent; }, - // We don't define innerMode because electricInput works only for inner modes and we need it to work for Soy. + innerMode: function(state) { + var ctx = last(state.soyState); + if (ctx == "comment" || ctx == "variable" || ctx == "tag") return null; + else return {state: state.localState, mode: state.localMode}; + }, - electricInput: /(}|<\/[\s\w:]+>)$/, // This covers Soy, JS, CSS and HTML. + electricInput: /^\s*(}|{\/)$/, lineComment: "//", blockCommentStart: "/*", blockCommentEnd: "*/", @@ -169,7 +174,10 @@ }; }, "htmlmixed"); - CodeMirror.registerHelper("hintWords", "soy", "delpackage namespace alias template param literal print msg fallbackmsg let if elseif else switch case default foreach ifempty for call param deltemplate delcall css log debugger".split(" ")); + CodeMirror.registerHelper(("hintWords", "soy", "delpackage namespace alias template param " + + "literal print msg fallbackmsg let if elseif else switch case " + + "default foreach ifempty for call param deltemplate delcall css " + + "log debugger").split(" ")); CodeMirror.defineMIME("text/x-soy", "soy"); });