diff --git a/demo/kitchen-sink/doclist.js b/demo/kitchen-sink/doclist.js index 5c4a528d..de77b359 100644 --- a/demo/kitchen-sink/doclist.js +++ b/demo/kitchen-sink/doclist.js @@ -85,6 +85,7 @@ var docs = { "docs/haml.haml": "Haml", "docs/Haxe.hx": "haXe", "docs/html.html": "HTML", + "docs/html_ruby.erb": "HTML (Ruby)", "docs/jade.jade": "Jade", "docs/java.java": "Java", "docs/jsp.jsp": "JSP", diff --git a/demo/kitchen-sink/docs/html_ruby.erb b/demo/kitchen-sink/docs/html_ruby.erb new file mode 100644 index 00000000..4ece6c8b --- /dev/null +++ b/demo/kitchen-sink/docs/html_ruby.erb @@ -0,0 +1,25 @@ +

Listing Books

+ + + + + + + + + + +<% @books.each do |book| %> + + + + + + + +<% end %> +
TitleSummary
<%= book.title %><%= book.content %><%= link_to 'Show', book %><%= link_to 'Edit', edit_book_path(book) %><%= link_to 'Remove', book, :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to 'New book', new_book_path %> \ No newline at end of file diff --git a/lib/ace/ext/modelist.js b/lib/ace/ext/modelist.js index 536d9430..2414688c 100644 --- a/lib/ace/ext/modelist.js +++ b/lib/ace/ext/modelist.js @@ -68,6 +68,7 @@ var supportedModes = { Haskell: ["hs"], haXe: ["hx"], HTML: ["htm|html|xhtml"], + HTML_Ruby: ["erb|rhtml|html.erb"], Ini: ["Ini|conf"], Jade: ["jade"], Java: ["java"], @@ -133,7 +134,8 @@ var nameOverrides = { CSharp: "C#", golang: "Go", C_Cpp: "C/C++", - coffee: "CoffeeScript" + coffee: "CoffeeScript", + HTML_Ruby: "HTML (Ruby)" }; var modesByName = {}; for (var name in supportedModes) { diff --git a/lib/ace/mode/html_highlight_rules.js b/lib/ace/mode/html_highlight_rules.js index d072a933..b7e73805 100644 --- a/lib/ace/mode/html_highlight_rules.js +++ b/lib/ace/mode/html_highlight_rules.js @@ -86,7 +86,7 @@ var HtmlHighlightRules = function() { next : "style" }, { token : "meta.tag", // opening tag - regex : "<\\/?", + regex : "<\\/?(?=\\w)", next : "tag" }, { token : "text", diff --git a/lib/ace/mode/html_ruby.js b/lib/ace/mode/html_ruby.js new file mode 100644 index 00000000..5fed54c1 --- /dev/null +++ b/lib/ace/mode/html_ruby.js @@ -0,0 +1,61 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2012, 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 + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * 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 + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var Tokenizer = require("../tokenizer").Tokenizer; +var HtmlRubyHighlightRules = require("./html_ruby_highlight_rules").HtmlRubyHighlightRules; +var HtmlMode = require("./html").Mode; +var JavaScriptMode = require("./javascript").Mode; +var CssMode = require("./css").Mode; +var RubyMode = require("./ruby").Mode; + +var Mode = function() { + HtmlMode.call(this); + var highlighter = new HtmlRubyHighlightRules(); + this.$tokenizer = new Tokenizer(highlighter.getRules()); + this.$embeds = highlighter.getEmbeds(); + this.createModeDelegates({ + "js-": JavaScriptMode, + "css-": CssMode, + "ruby-": RubyMode + }); +}; +oop.inherits(Mode, HtmlMode); + +(function() { + +}).call(Mode.prototype); + +exports.Mode = Mode; +}); \ No newline at end of file diff --git a/lib/ace/mode/html_ruby_highlight_rules.js b/lib/ace/mode/html_ruby_highlight_rules.js new file mode 100644 index 00000000..bcfbf1c4 --- /dev/null +++ b/lib/ace/mode/html_ruby_highlight_rules.js @@ -0,0 +1,74 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2012, 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 + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * 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 + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { + "use strict"; + + var oop = require("../lib/oop"); + var HtmlHighlightRules = require("./html_highlight_rules").HtmlHighlightRules; + var RubyHighlightRules = require("./ruby_highlight_rules").RubyHighlightRules; + + var HtmlRubyHighlightRules = function() { + HtmlHighlightRules.call(this); + + for (var i in this.$rules) { + this.$rules[i].unshift({ + regex: "<%%|%%>", + token: "constant.language.escape" + }, { + token : "comment.start.erb", + regex : "<%#", + push : [{regex: "%>", next: "pop"}] + }, { + token : "support.ruby_tag", + regex : "<%+(?!>)[-=]?", + push : "ruby-start" + }); + } + + this.embedRules(RubyHighlightRules, "ruby-"); + + this.$rules["ruby-start"].unshift({ + token : "support.ruby_tag", + regex : "%>", + next : "pop" + }, { + token: "comment", + regex: /#(?:[^%]|%[^>])*/ + }); + + this.normalizeRules(); + }; + + + oop.inherits(HtmlRubyHighlightRules, HtmlHighlightRules); + + exports.HtmlRubyHighlightRules = HtmlRubyHighlightRules; +}); \ No newline at end of file