fix makefile mode detection in demo

This commit is contained in:
nightwing 2012-11-10 13:15:21 +04:00
commit d98d29a66a

View file

@ -5,8 +5,9 @@ define(function(require, exports, module) {
var modes = []; var modes = [];
function getModeFromPath(path) { function getModeFromPath(path) {
var mode = modesByName.text; var mode = modesByName.text;
var fileName = path.split(/[\/\\]/).pop();
for (var i = 0; i < modes.length; i++) { for (var i = 0; i < modes.length; i++) {
if (modes[i].supportsFile(path)) { if (modes[i].supportsFile(fileName)) {
mode = modes[i]; mode = modes[i];
break; break;
} }
@ -18,7 +19,15 @@ var Mode = function(name, desc, extensions) {
this.name = name; this.name = name;
this.desc = desc; this.desc = desc;
this.mode = "ace/mode/" + name; this.mode = "ace/mode/" + name;
this.extRe = new RegExp("^.*\\.(" + extensions + ")$", "g"); if (/\^/.test(extensions)) {
var re = extensions.replace(/\|(\^)?/g, function(a, b){
return "$|" + (b ? "^" : "^.*\\.");
}) + "$";
} else {
var re = "^.*\\.(" + extensions + ")$";
}
this.extRe = new RegExp(re, "g");
}; };
Mode.prototype.supportsFile = function(filename) { Mode.prototype.supportsFile = function(filename) {
@ -28,7 +37,7 @@ Mode.prototype.supportsFile = function(filename) {
var modesByName = { var modesByName = {
asciidoc: ["AsciiDoc" , "asciidoc"], asciidoc: ["AsciiDoc" , "asciidoc"],
c9search: ["C9Search" , "c9search_results"], c9search: ["C9Search" , "c9search_results"],
coffee: ["CoffeeScript" , "coffee|^Cakefile"], coffee: ["CoffeeScript" , "^Cakefile|coffee|cf"],
coldfusion: ["ColdFusion" , "cfm"], coldfusion: ["ColdFusion" , "cfm"],
csharp: ["C#" , "cs"], csharp: ["C#" , "cs"],
css: ["CSS" , "css"], css: ["CSS" , "css"],
@ -51,7 +60,7 @@ var modesByName = {
liquid: ["Liquid" , "liquid"], liquid: ["Liquid" , "liquid"],
lua: ["Lua" , "lua"], lua: ["Lua" , "lua"],
luapage: ["LuaPage" , "lp"], // http://keplerproject.github.com/cgilua/manual.html#templates luapage: ["LuaPage" , "lp"], // http://keplerproject.github.com/cgilua/manual.html#templates
makefile: ["Makefile" , "GNUmakefile|makefile|Makefile|OCamlMakefile|make"], makefile: ["Makefile" , "^GNUmakefile|^makefile|^Makefile|^OCamlMakefile|make"],
markdown: ["Markdown" , "md|markdown"], markdown: ["Markdown" , "md|markdown"],
ocaml: ["OCaml" , "ml|mli"], ocaml: ["OCaml" , "ml|mli"],
perl: ["Perl" , "pl|pm"], perl: ["Perl" , "pl|pm"],