Skip to content

Commit f6c5def

Browse files
abdelouahabbmarijnh
authored andcommitted
[tornado mode] Add
1 parent 0f35444 commit f6c5def

File tree

5 files changed

+136
-0
lines changed

5 files changed

+136
-0
lines changed

doc/compress.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ <h2>Script compression helper</h2>
167167
<option value="http://codemirror.net/mode/tiddlywiki/tiddlywiki.js">tiddlywiki.js</option>
168168
<option value="http://codemirror.net/mode/tiki/tiki.js">tiki.js</option>
169169
<option value="http://codemirror.net/mode/toml/toml.js">toml.js</option>
170+
<option value="http://codemirror.net/mode/tornado/tornado.js">tornado.js</option>
170171
<option value="http://codemirror.net/mode/turtle/turtle.js">turtle.js</option>
171172
<option value="http://codemirror.net/mode/vb/vb.js">vb.js</option>
172173
<option value="http://codemirror.net/mode/vbscript/vbscript.js">vbscript.js</option>

mode/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ <h2>Language modes</h2>
109109
<li><a href="tiddlywiki/index.html">Tiddlywiki</a></li>
110110
<li><a href="tiki/index.html">Tiki wiki</a></li>
111111
<li><a href="toml/index.html">TOML</a></li>
112+
<li><a href="tornado/index.html">Tornado</a> (templating language)</li>
112113
<li><a href="turtle/index.html">Turtle</a></li>
113114
<li><a href="vb/index.html">VB.NET</a></li>
114115
<li><a href="vbscript/index.html">VBScript</a></li>

mode/meta.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
{name: "TiddlyWiki ", mime: "text/x-tiddlywiki", mode: "tiddlywiki"},
108108
{name: "Tiki wiki", mime: "text/tiki", mode: "tiki"},
109109
{name: "TOML", mime: "text/x-toml", mode: "toml"},
110+
{name: "Tornado", mime: "text/x-tornado", mode: "tornado"},
110111
{name: "Turtle", mime: "text/turtle", mode: "turtle", ext: ["ttl"]},
111112
{name: "TypeScript", mime: "application/typescript", mode: "javascript", ext: ["ts"]},
112113
{name: "VB.NET", mime: "text/x-vb", mode: "vb", ext: ["vb"]},

mode/tornado/index.html

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<!doctype html>
2+
3+
<title>CodeMirror: Tornado template mode</title>
4+
<meta charset="utf-8"/>
5+
<link rel=stylesheet href="../../doc/docs.css">
6+
7+
<link rel="stylesheet" href="../../lib/codemirror.css">
8+
<script src="../../lib/codemirror.js"></script>
9+
<script src="../../addon/mode/overlay.js"></script>
10+
<script src="../xml/xml.js"></script>
11+
<script src="../htmlmixed/htmlmixed.js"></script>
12+
<script src="tornado.js"></script>
13+
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
14+
<div id=nav>
15+
<a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a>
16+
17+
<ul>
18+
<li><a href="../../index.html">Home</a>
19+
<li><a href="../../doc/manual.html">Manual</a>
20+
<li><a href="https://github.com/marijnh/codemirror">Code</a>
21+
</ul>
22+
<ul>
23+
<li><a href="../index.html">Language modes</a>
24+
<li><a class=active href="#">Tornado</a>
25+
</ul>
26+
</div>
27+
28+
<article>
29+
<h2>Tornado template mode</h2>
30+
<form><textarea id="code" name="code">
31+
<!doctype html>
32+
<html>
33+
<head>
34+
<title>My Tornado web application</title>
35+
</head>
36+
<body>
37+
<h1>
38+
{{ title }}
39+
</h1>
40+
<ul class="my-list">
41+
{% for item in items %}
42+
<li>{% item.name %}</li>
43+
{% empty %}
44+
<li>You have no items in your list.</li>
45+
{% endfor %}
46+
</ul>
47+
</body>
48+
</html>
49+
</textarea></form>
50+
51+
<script>
52+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
53+
lineNumbers: true,
54+
mode: "tornado",
55+
indentUnit: 4,
56+
indentWithTabs: true
57+
});
58+
</script>
59+
60+
<p>Mode for HTML with embedded Tornado template markup.</p>
61+
62+
<p><strong>MIME types defined:</strong> <code>text/x-tornado</code></p>
63+
</article>

mode/tornado/tornado.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2+
// Distributed under an MIT license: http://codemirror.net/LICENSE
3+
4+
(function(mod) {
5+
if (typeof exports == "object" && typeof module == "object") // CommonJS
6+
mod(require("../../lib/codemirror"), require("../htmlmixed/htmlmixed"),
7+
require("../../addon/mode/overlay"));
8+
else if (typeof define == "function" && define.amd) // AMD
9+
define(["../../lib/codemirror", "../htmlmixed/htmlmixed",
10+
"../../addon/mode/overlay"], mod);
11+
else // Plain browser env
12+
mod(CodeMirror);
13+
})(function(CodeMirror) {
14+
"use strict";
15+
16+
CodeMirror.defineMode("tornado:inner", function() {
17+
var keywords = ["block", "for", "in", "true", "false",
18+
"none", "self", "super", "if", "end", "as", "not", "and",
19+
"else", "import", "with", "without", "context",
20+
"try", "except", "put", "escape", "xhtml_escape", "url_escape",
21+
"json_encode", "squeeze", "linkify", "datetime",
22+
"extends", "include", "load", "length", "comment",
23+
"pass", "while", "set", "import", "from",
24+
"autoescape", "raw", "module"];
25+
keywords = new RegExp("^((" + keywords.join(")|(") + "))\\b");
26+
27+
function tokenBase (stream, state) {
28+
stream.eatWhile(/[^\{]/);
29+
var ch = stream.next();
30+
if (ch == "{") {
31+
if (ch = stream.eat(/\{|%|#/)) {
32+
state.tokenize = inTag(ch);
33+
return "tag";
34+
}
35+
}
36+
}
37+
function inTag (close) {
38+
if (close == "{") {
39+
close = "}";
40+
}
41+
return function (stream, state) {
42+
var ch = stream.next();
43+
if ((ch == close) && stream.eat("}")) {
44+
state.tokenize = tokenBase;
45+
return "tag";
46+
}
47+
if (stream.match(keywords)) {
48+
return "keyword";
49+
}
50+
return close == "#" ? "comment" : "string";
51+
};
52+
}
53+
return {
54+
startState: function () {
55+
return {tokenize: tokenBase};
56+
},
57+
token: function (stream, state) {
58+
return state.tokenize(stream, state);
59+
}
60+
};
61+
});
62+
63+
CodeMirror.defineMode("tornado", function(config) {
64+
var htmlBase = CodeMirror.getMode(config, "text/html");
65+
var tornadoInner = CodeMirror.getMode(config, "tornado:inner");
66+
return CodeMirror.overlayMode(htmlBase, tornadoInner);
67+
});
68+
69+
CodeMirror.defineMIME("text/x-tornado", "tornado");
70+
});

0 commit comments

Comments
 (0)