mirror of
https://github.com/documize/community.git
synced 2025-08-02 20:15:26 +02:00
moved emberjs to gui folder
This commit is contained in:
parent
6a18d18f91
commit
dc49dbbeff
999 changed files with 677 additions and 651 deletions
68
gui/public/codemirror/mode/soy/index.html
vendored
Executable file
68
gui/public/codemirror/mode/soy/index.html
vendored
Executable file
|
@ -0,0 +1,68 @@
|
|||
<!doctype html>
|
||||
|
||||
<title>CodeMirror: Soy (Closure Template) mode</title>
|
||||
<meta charset="utf-8"/>
|
||||
<link rel=stylesheet href="../../doc/docs.css">
|
||||
|
||||
<link rel="stylesheet" href="../../lib/codemirror.css">
|
||||
<script src="../../lib/codemirror.js"></script>
|
||||
<script src="../../addon/edit/matchbrackets.js"></script>
|
||||
<script src="../htmlmixed/htmlmixed.js"></script>
|
||||
<script src="../xml/xml.js"></script>
|
||||
<script src="../javascript/javascript.js"></script>
|
||||
<script src="../css/css.js"></script>
|
||||
<script src="soy.js"></script>
|
||||
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
||||
<div id=nav>
|
||||
<a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
|
||||
|
||||
<ul>
|
||||
<li><a href="../../index.html">Home</a>
|
||||
<li><a href="../../doc/manual.html">Manual</a>
|
||||
<li><a href="https://github.com/codemirror/codemirror">Code</a>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a href="../index.html">Language modes</a>
|
||||
<li><a class=active href="#">Soy (Closure Template)</a>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<article>
|
||||
<h2>Soy (Closure Template) mode</h2>
|
||||
<form><textarea id="code" name="code">
|
||||
{namespace example}
|
||||
|
||||
/**
|
||||
* Says hello to the world.
|
||||
*/
|
||||
{template .helloWorld}
|
||||
{@param name: string}
|
||||
{@param? score: number}
|
||||
Hello <b>{$name}</b>!
|
||||
<div>
|
||||
{if $score}
|
||||
<em>{$score} points</em>
|
||||
{else}
|
||||
no score
|
||||
{/if}
|
||||
</div>
|
||||
{/template}
|
||||
|
||||
{template .alertHelloWorld kind="js"}
|
||||
alert('Hello World');
|
||||
{/template}
|
||||
</textarea></form>
|
||||
|
||||
<script>
|
||||
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
||||
lineNumbers: true,
|
||||
matchBrackets: true,
|
||||
mode: "text/x-soy",
|
||||
indentUnit: 2,
|
||||
indentWithTabs: false
|
||||
});
|
||||
</script>
|
||||
|
||||
<p>A mode for <a href="https://developers.google.com/closure/templates/">Closure Templates</a> (Soy).</p>
|
||||
<p><strong>MIME type defined:</strong> <code>text/x-soy</code>.</p>
|
||||
</article>
|
304
gui/public/codemirror/mode/soy/soy.js
vendored
Executable file
304
gui/public/codemirror/mode/soy/soy.js
vendored
Executable file
|
@ -0,0 +1,304 @@
|
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
(function(mod) {
|
||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||
mod(require("../../lib/codemirror"), require("../htmlmixed/htmlmixed"));
|
||||
else if (typeof define == "function" && define.amd) // AMD
|
||||
define(["../../lib/codemirror", "../htmlmixed/htmlmixed"], mod);
|
||||
else // Plain browser env
|
||||
mod(CodeMirror);
|
||||
})(function(CodeMirror) {
|
||||
"use strict";
|
||||
|
||||
var indentingTags = ["template", "literal", "msg", "fallbackmsg", "let", "if", "elseif",
|
||||
"else", "switch", "case", "default", "foreach", "ifempty", "for",
|
||||
"call", "param", "deltemplate", "delcall", "log"];
|
||||
|
||||
CodeMirror.defineMode("soy", function(config) {
|
||||
var textMode = CodeMirror.getMode(config, "text/plain");
|
||||
var modes = {
|
||||
html: CodeMirror.getMode(config, {name: "text/html", multilineTagIndentFactor: 2, multilineTagIndentPastTag: false}),
|
||||
attributes: textMode,
|
||||
text: textMode,
|
||||
uri: textMode,
|
||||
css: CodeMirror.getMode(config, "text/css"),
|
||||
js: CodeMirror.getMode(config, {name: "text/javascript", statementIndent: 2 * config.indentUnit})
|
||||
};
|
||||
|
||||
function last(array) {
|
||||
return array[array.length - 1];
|
||||
}
|
||||
|
||||
function tokenUntil(stream, state, untilRegExp) {
|
||||
var oldString = stream.string;
|
||||
var match = untilRegExp.exec(oldString.substr(stream.pos));
|
||||
if (match) {
|
||||
// We don't use backUp because it backs up just the position, not the state.
|
||||
// This uses an undocumented API.
|
||||
stream.string = oldString.substr(0, stream.pos + match.index);
|
||||
}
|
||||
var result = stream.hideFirstChars(state.indent, function() {
|
||||
return state.localMode.token(stream, state.localState);
|
||||
});
|
||||
stream.string = oldString;
|
||||
return result;
|
||||
}
|
||||
|
||||
function contains(list, element) {
|
||||
while (list) {
|
||||
if (list.element === element) return true;
|
||||
list = list.next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function prepend(list, element) {
|
||||
return {
|
||||
element: element,
|
||||
next: list
|
||||
};
|
||||
}
|
||||
|
||||
// Reference a variable `name` in `list`.
|
||||
// Let `loose` be truthy to ignore missing identifiers.
|
||||
function ref(list, name, loose) {
|
||||
return contains(list, name) ? "variable-2" : (loose ? "variable" : "variable-2 error");
|
||||
}
|
||||
|
||||
function popscope(state) {
|
||||
if (state.scopes) {
|
||||
state.variables = state.scopes.element;
|
||||
state.scopes = state.scopes.next;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
startState: function() {
|
||||
return {
|
||||
kind: [],
|
||||
kindTag: [],
|
||||
soyState: [],
|
||||
templates: null,
|
||||
variables: null,
|
||||
scopes: null,
|
||||
indent: 0,
|
||||
localMode: modes.html,
|
||||
localState: CodeMirror.startState(modes.html)
|
||||
};
|
||||
},
|
||||
|
||||
copyState: function(state) {
|
||||
return {
|
||||
tag: state.tag, // Last seen Soy tag.
|
||||
kind: state.kind.concat([]), // Values of kind="" attributes.
|
||||
kindTag: state.kindTag.concat([]), // Opened tags with kind="" attributes.
|
||||
soyState: state.soyState.concat([]),
|
||||
templates: state.templates,
|
||||
variables: state.variables,
|
||||
scopes: state.scopes,
|
||||
indent: state.indent, // Indentation of the following line.
|
||||
localMode: state.localMode,
|
||||
localState: CodeMirror.copyState(state.localMode, state.localState)
|
||||
};
|
||||
},
|
||||
|
||||
token: function(stream, state) {
|
||||
var match;
|
||||
|
||||
switch (last(state.soyState)) {
|
||||
case "comment":
|
||||
if (stream.match(/^.*?\*\//)) {
|
||||
state.soyState.pop();
|
||||
} else {
|
||||
stream.skipToEnd();
|
||||
}
|
||||
return "comment";
|
||||
|
||||
case "templ-def":
|
||||
if (match = stream.match(/^\.?([\w]+(?!\.[\w]+)*)/)) {
|
||||
state.templates = prepend(state.templates, match[1]);
|
||||
state.scopes = prepend(state.scopes, state.variables);
|
||||
state.soyState.pop();
|
||||
return "def";
|
||||
}
|
||||
stream.next();
|
||||
return null;
|
||||
|
||||
case "templ-ref":
|
||||
if (match = stream.match(/^\.?([\w]+)/)) {
|
||||
state.soyState.pop();
|
||||
// If the first character is '.', try to match against a local template name.
|
||||
if (match[0][0] == '.') {
|
||||
return ref(state.templates, match[1], true);
|
||||
}
|
||||
// Otherwise
|
||||
return "variable";
|
||||
}
|
||||
stream.next();
|
||||
return null;
|
||||
|
||||
case "param-def":
|
||||
if (match = stream.match(/^([\w]+)(?=:)/)) {
|
||||
state.variables = prepend(state.variables, match[1]);
|
||||
state.soyState.pop();
|
||||
state.soyState.push("param-type");
|
||||
return "def";
|
||||
}
|
||||
stream.next();
|
||||
return null;
|
||||
|
||||
case "param-type":
|
||||
if (stream.peek() == "}") {
|
||||
state.soyState.pop();
|
||||
return null;
|
||||
}
|
||||
if (stream.eatWhile(/^[\w]+/)) {
|
||||
return "variable-3";
|
||||
}
|
||||
stream.next();
|
||||
return null;
|
||||
|
||||
case "var-def":
|
||||
if (match = stream.match(/^\$([\w]+)/)) {
|
||||
state.variables = prepend(state.variables, match[1]);
|
||||
state.soyState.pop();
|
||||
return "def";
|
||||
}
|
||||
stream.next();
|
||||
return null;
|
||||
|
||||
case "tag":
|
||||
if (stream.match(/^\/?}/)) {
|
||||
if (state.tag == "/template" || state.tag == "/deltemplate") {
|
||||
popscope(state);
|
||||
state.indent = 0;
|
||||
} else {
|
||||
if (state.tag == "/for" || state.tag == "/foreach") {
|
||||
popscope(state);
|
||||
}
|
||||
state.indent -= config.indentUnit *
|
||||
(stream.current() == "/}" || indentingTags.indexOf(state.tag) == -1 ? 2 : 1);
|
||||
}
|
||||
state.soyState.pop();
|
||||
return "keyword";
|
||||
} else if (stream.match(/^([\w?]+)(?==)/)) {
|
||||
if (stream.current() == "kind" && (match = stream.match(/^="([^"]+)/, false))) {
|
||||
var kind = match[1];
|
||||
state.kind.push(kind);
|
||||
state.kindTag.push(state.tag);
|
||||
state.localMode = modes[kind] || modes.html;
|
||||
state.localState = CodeMirror.startState(state.localMode);
|
||||
}
|
||||
return "attribute";
|
||||
} else if (stream.match(/^"/)) {
|
||||
state.soyState.push("string");
|
||||
return "string";
|
||||
}
|
||||
if (match = stream.match(/^\$([\w]+)/)) {
|
||||
return ref(state.variables, match[1]);
|
||||
}
|
||||
if (match = stream.match(/^\w+/)) {
|
||||
return /^(?:as|and|or|not|in)$/.test(match[0]) ? "keyword" : null;
|
||||
}
|
||||
stream.next();
|
||||
return null;
|
||||
|
||||
case "literal":
|
||||
if (stream.match(/^(?=\{\/literal})/)) {
|
||||
state.indent -= config.indentUnit;
|
||||
state.soyState.pop();
|
||||
return this.token(stream, state);
|
||||
}
|
||||
return tokenUntil(stream, state, /\{\/literal}/);
|
||||
|
||||
case "string":
|
||||
var match = stream.match(/^.*?("|\\[\s\S])/);
|
||||
if (!match) {
|
||||
stream.skipToEnd();
|
||||
} else if (match[1] == "\"") {
|
||||
state.soyState.pop();
|
||||
}
|
||||
return "string";
|
||||
}
|
||||
|
||||
if (stream.match(/^\/\*/)) {
|
||||
state.soyState.push("comment");
|
||||
return "comment";
|
||||
} else if (stream.match(stream.sol() ? /^\s*\/\/.*/ : /^\s+\/\/.*/)) {
|
||||
return "comment";
|
||||
} else if (stream.match(/^\{literal}/)) {
|
||||
state.indent += config.indentUnit;
|
||||
state.soyState.push("literal");
|
||||
return "keyword";
|
||||
} else if (match = stream.match(/^\{([\/@\\]?[\w?]*)/)) {
|
||||
if (match[1] != "/switch")
|
||||
state.indent += (/^(\/|(else|elseif|ifempty|case|default)$)/.test(match[1]) && state.tag != "switch" ? 1 : 2) * config.indentUnit;
|
||||
state.tag = match[1];
|
||||
if (state.tag == "/" + last(state.kindTag)) {
|
||||
// We found the tag that opened the current kind="".
|
||||
state.kind.pop();
|
||||
state.kindTag.pop();
|
||||
state.localMode = modes[last(state.kind)] || modes.html;
|
||||
state.localState = CodeMirror.startState(state.localMode);
|
||||
}
|
||||
state.soyState.push("tag");
|
||||
if (state.tag == "template" || state.tag == "deltemplate") {
|
||||
state.soyState.push("templ-def");
|
||||
}
|
||||
if (state.tag == "call" || state.tag == "delcall") {
|
||||
state.soyState.push("templ-ref");
|
||||
}
|
||||
if (state.tag == "let") {
|
||||
state.soyState.push("var-def");
|
||||
}
|
||||
if (state.tag == "for" || state.tag == "foreach") {
|
||||
state.scopes = prepend(state.scopes, state.variables);
|
||||
state.soyState.push("var-def");
|
||||
}
|
||||
if (state.tag.match(/^@param\??/)) {
|
||||
state.soyState.push("param-def");
|
||||
}
|
||||
return "keyword";
|
||||
}
|
||||
|
||||
return tokenUntil(stream, state, /\{|\s+\/\/|\/\*/);
|
||||
},
|
||||
|
||||
indent: function(state, textAfter) {
|
||||
var indent = state.indent, top = last(state.soyState);
|
||||
if (top == "comment") return CodeMirror.Pass;
|
||||
|
||||
if (top == "literal") {
|
||||
if (/^\{\/literal}/.test(textAfter)) indent -= config.indentUnit;
|
||||
} else {
|
||||
if (/^\s*\{\/(template|deltemplate)\b/.test(textAfter)) return 0;
|
||||
if (/^\{(\/|(fallbackmsg|elseif|else|ifempty)\b)/.test(textAfter)) indent -= config.indentUnit;
|
||||
if (state.tag != "switch" && /^\{(case|default)\b/.test(textAfter)) indent -= config.indentUnit;
|
||||
if (/^\{\/switch\b/.test(textAfter)) indent -= config.indentUnit;
|
||||
}
|
||||
if (indent && state.localMode.indent)
|
||||
indent += state.localMode.indent(state.localState, textAfter);
|
||||
return indent;
|
||||
},
|
||||
|
||||
innerMode: function(state) {
|
||||
if (state.soyState.length && last(state.soyState) != "literal") return null;
|
||||
else return {state: state.localState, mode: state.localMode};
|
||||
},
|
||||
|
||||
electricInput: /^\s*\{(\/|\/template|\/deltemplate|\/switch|fallbackmsg|elseif|else|case|default|ifempty|\/literal\})$/,
|
||||
lineComment: "//",
|
||||
blockCommentStart: "/*",
|
||||
blockCommentEnd: "*/",
|
||||
blockCommentContinue: " * ",
|
||||
useInnerComments: false,
|
||||
fold: "indent"
|
||||
};
|
||||
}, "htmlmixed");
|
||||
|
||||
CodeMirror.registerHelper("hintWords", "soy", indentingTags.concat(
|
||||
["delpackage", "namespace", "alias", "print", "css", "debugger"]));
|
||||
|
||||
CodeMirror.defineMIME("text/x-soy", "soy");
|
||||
});
|
83
gui/public/codemirror/mode/soy/test.js
vendored
Executable file
83
gui/public/codemirror/mode/soy/test.js
vendored
Executable file
|
@ -0,0 +1,83 @@
|
|||
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||
|
||||
(function() {
|
||||
var mode = CodeMirror.getMode({indentUnit: 2}, "soy");
|
||||
function MT(name) {test.mode(name, mode, Array.prototype.slice.call(arguments, 1));}
|
||||
|
||||
// Test of small keywords and words containing them.
|
||||
MT('keywords-test',
|
||||
'[keyword {] [keyword as] worrying [keyword and] notorious [keyword as]',
|
||||
' the Fandor-alias assassin, [keyword or]',
|
||||
' Corcand cannot fit [keyword in] [keyword }]');
|
||||
|
||||
MT('let-test',
|
||||
'[keyword {template] [def .name][keyword }]',
|
||||
' [keyword {let] [def $name]: [string "world"][keyword /}]',
|
||||
' [tag&bracket <][tag h1][tag&bracket >]',
|
||||
' Hello, [keyword {][variable-2 $name][keyword }]',
|
||||
' [tag&bracket </][tag h1][tag&bracket >]',
|
||||
'[keyword {/template}]',
|
||||
'');
|
||||
|
||||
MT('param-type-test',
|
||||
'[keyword {@param] [def a]: ' +
|
||||
'[variable-3 list]<[[[variable-3 a]: [variable-3 int], ' +
|
||||
'[variable-3 b]: [variable-3 map]<[variable-3 string], ' +
|
||||
'[variable-3 bool]>]]>][keyword }]');
|
||||
|
||||
MT('undefined-var',
|
||||
'[keyword {][variable-2&error $var]');
|
||||
|
||||
MT('param-scope-test',
|
||||
'[keyword {template] [def .a][keyword }]',
|
||||
' [keyword {@param] [def x]: [variable-3 string][keyword }]',
|
||||
' [keyword {][variable-2 $x][keyword }]',
|
||||
'[keyword {/template}]',
|
||||
'',
|
||||
'[keyword {template] [def .b][keyword }]',
|
||||
' [keyword {][variable-2&error $x][keyword }]',
|
||||
'[keyword {/template}]',
|
||||
'');
|
||||
|
||||
MT('if-variable-test',
|
||||
'[keyword {if] [variable-2&error $showThing][keyword }]',
|
||||
' Yo!',
|
||||
'[keyword {/if}]',
|
||||
'');
|
||||
|
||||
MT('defined-if-variable-test',
|
||||
'[keyword {template] [def .foo][keyword }]',
|
||||
' [keyword {@param?] [def showThing]: [variable-3 bool][keyword }]',
|
||||
' [keyword {if] [variable-2 $showThing][keyword }]',
|
||||
' Yo!',
|
||||
' [keyword {/if}]',
|
||||
'[keyword {/template}]',
|
||||
'');
|
||||
|
||||
MT('template-calls-test',
|
||||
'[keyword {template] [def .foo][keyword }]',
|
||||
' Yo!',
|
||||
'[keyword {/template}]',
|
||||
'[keyword {call] [variable-2 .foo][keyword /}]',
|
||||
'[keyword {call] [variable foo][keyword /}]',
|
||||
'[keyword {call] [variable .bar][keyword /}]',
|
||||
'[keyword {call] [variable bar][keyword /}]',
|
||||
'');
|
||||
|
||||
MT('foreach-scope-test',
|
||||
'[keyword {@param] [def bar]: [variable-3 string][keyword }]',
|
||||
'[keyword {foreach] [def $foo] [keyword in] [variable-2&error $foos][keyword }]',
|
||||
' [keyword {][variable-2 $foo][keyword }]',
|
||||
'[keyword {/foreach}]',
|
||||
'[keyword {][variable-2&error $foo][keyword }]',
|
||||
'[keyword {][variable-2 $bar][keyword }]');
|
||||
|
||||
MT('foreach-ifempty-indent-test',
|
||||
'[keyword {foreach] [def $foo] [keyword in] [variable-2&error $foos][keyword }]',
|
||||
' something',
|
||||
'[keyword {ifempty}]',
|
||||
' nothing',
|
||||
'[keyword {/foreach}]',
|
||||
'');
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue