From 83e0a6b80b9cf2d4e251ae4b8fb24b1a6c9a3b2a Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Tue, 24 Jul 2012 10:39:09 -0700 Subject: [PATCH] Initial commit --- demo/kitchen-sink/demo.js | 6 +- demo/kitchen-sink/docs/jade.jade | 17 ++++ lib/ace/mode/jade.js | 66 ++++++++++++++ lib/ace/mode/jade_highlight_rules.js | 131 +++++++++++++++++++++++++++ 4 files changed, 218 insertions(+), 2 deletions(-) create mode 100644 demo/kitchen-sink/docs/jade.jade create mode 100644 lib/ace/mode/jade.js create mode 100644 lib/ace/mode/jade_highlight_rules.js diff --git a/demo/kitchen-sink/demo.js b/demo/kitchen-sink/demo.js index 4e5da13e..48f0c74d 100644 --- a/demo/kitchen-sink/demo.js +++ b/demo/kitchen-sink/demo.js @@ -3,7 +3,7 @@ * * Copyright (c) 2010, Ajax.org B.V. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ * * Neither the name of Ajax.org B.V. nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -96,6 +96,7 @@ var modesByName = { html: ["HTML" , "htm|html|xhtml"], c_cpp: ["C/C++" , "c|cc|cpp|cxx|h|hh|hpp"], clojure: ["Clojure" , "clj"], + jade: ["Jade" , "jade"], java: ["Java" , "java"], javascript: ["JavaScript" , "js"], json: ["JSON" , "json"], @@ -176,6 +177,7 @@ var docs = { "docs/groovy.groovy": "Groovy", "docs/Haxe.hx": "haXe", "docs/html.html": "HTML", + "docs/jade.jade": "Jade", "docs/java.java": "Java", "docs/json.json": "JSON", "docs/jsx.jsx": "JSX", diff --git a/demo/kitchen-sink/docs/jade.jade b/demo/kitchen-sink/docs/jade.jade new file mode 100644 index 00000000..1198c416 --- /dev/null +++ b/demo/kitchen-sink/docs/jade.jade @@ -0,0 +1,17 @@ +doctype 5 +html(lang="en") + head + title= pageTitle + script(type='text/javascript') + if (foo) { + bar() + } + body + h1 Jade - node template engine + #container + if youAreUsingJade + p You are #{awesome} + else + p Get on it! + + mixin dialog-title-desc(title, desc) \ No newline at end of file diff --git a/lib/ace/mode/jade.js b/lib/ace/mode/jade.js new file mode 100644 index 00000000..3886179d --- /dev/null +++ b/lib/ace/mode/jade.js @@ -0,0 +1,66 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ajax.org Code Editor (ACE). + * + * The Initial Developer of the Original Code is + * Ajax.org B.V. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Garen J. Torikian + * Alexander Hanhikoski + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var TextMode = require("./text").Mode; +var Tokenizer = require("../tokenizer").Tokenizer; +var JadeHighlightRules = require("./jade_highlight_rules").JadeHighlightRules; +// var JavascriptMode = require("ace/mode/javascript").Mode; +// var CssMode = require("ace/mode/css").Mode; + +var Mode = function() { + var highlighter = new JadeHighlightRules(); + + this.$tokenizer = new Tokenizer(highlighter.getRules()); + // this.$embeds = highlighter.getEmbeds(); + // this.createModeDelegates({ + // "js-": JavascriptMode + // "css-": CssMode + // }); +}; +oop.inherits(Mode, TextMode); + +(function() { + // Extra logic goes here. (see below) +}).call(Mode.prototype); + +exports.Mode = Mode; +}); \ No newline at end of file diff --git a/lib/ace/mode/jade_highlight_rules.js b/lib/ace/mode/jade_highlight_rules.js new file mode 100644 index 00000000..781b85f5 --- /dev/null +++ b/lib/ace/mode/jade_highlight_rules.js @@ -0,0 +1,131 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ajax.org Code Editor (ACE). + * + * The Initial Developer of the Original Code is + * Ajax.org B.V. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Garen J. Torikian + * Alexander Hanhikoski + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + +// var JavaScriptHighlightRules = require("ace/mode/javascript_highlight_rules").JavaScriptHighlightRules; +// var CssHighlightRules = require("ace/mode/css_highlight_rules").CssHighlightRules; + +var JadeHighlightRules = function() { + + this.$rules = { + start: [ + { + token : ["keyword.control.import.include.jade"], + regex : "(?:^\\s*\\b)(include)(?:\\b)" + }, + { + token : "keyword.other.doctype.jade", + regex : "^(?:!!!)(?:\\s*[a-zA-Z0-9-_]+)?" + }, + { + token : "comment", + regex : "\\/\\/.*$" + }, + // match stuff like: mixin dialog-title-desc(title, desc) + { + token : ["storage.type.function.jade", "text", "entity.name.function.jade", "punctuation.definition.parameters.begin.jade", "variable.parameter.function.jade", "punctuation.definition.parameters.end.jade"], + regex : "(mixin)( )([\\w\\-]+)\\s*(\\()(.*?)(\\))" + }, + // match stuff like: mixin dialog-title-desc + { + token : ["storage.type.function.jade", "text", "entity.name.function.jade"], + regex : "(mixin)( )(\\w\\-]+)" + }, + // Jade's iteration: 'each foo in foos' + { + token : ["keyword", "text", "variable", "text", "keyword", "text", "variable"], + regex : "(each|for)(\\s+)([\\w-]+)(\\s+)(in)(\\s+)([\\w-]+)" + }, + // Jade's iteration: 'each foo, bar in foos' + { + token : ["keyword", "text", "variable", "text", "variable", "text", "keyword", "text", "variable"], + regex : "(each|for)(\\s+)([\\w-]+)(\\s*,\\s*)([\\w-]+)(\\s+)(in)(\\s+)([\\w-]+)" + }, + { + token : "string.interpolated.jade", + regex : "[#!]\\{[^\\}]+\\}" + }, + { + token : ["text", "meta.tag.any.jade", "meta.tag.any.jade"], + regex : "(^\\s*)(?:(([\w]+))|(?=\.|#))" + }, + { + token : "text", + regex : "\\|.*$" + } + ], + parentheses: [ + { + token : "meta.tag.attribute.class.jade", + regex : "\\.[\\w-]+<" + }, + { + token : "meta.tag.attribute.id.jade", + regex : "#[\\w-]+<" + }, + { + token : "text", + regex : "$", + next : "start" + } + ] + } + + // this.embedRules(JavaScriptHighlightRules, "js-", { + // start: [{ + // token: "string", + // regex: "^$" + // }] + // }); + + // this.embedRules(CssHighlightRules, "css-", [{ + // token: "keyword", + // regex: "style", + // next: "start" + // }]); +}; + +oop.inherits(JadeHighlightRules, TextHighlightRules); + +exports.JadeHighlightRules = JadeHighlightRules; +}); \ No newline at end of file