modelist.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. define(function(require, exports, module) {
  2. "use strict";
  3. var modes = [];
  4. /**
  5. * Suggests a mode based on the file extension present in the given path
  6. * @param {string} path The path to the file
  7. * @returns {object} Returns an object containing information about the
  8. * suggested mode.
  9. */
  10. function getModeForPath(path) {
  11. var mode = modesByName.text;
  12. var fileName = path.split(/[\/\\]/).pop();
  13. for (var i = 0; i < modes.length; i++) {
  14. if (modes[i].supportsFile(fileName)) {
  15. mode = modes[i];
  16. break;
  17. }
  18. }
  19. return mode;
  20. }
  21. var Mode = function(name, caption, extensions) {
  22. this.name = name;
  23. this.caption = caption;
  24. this.mode = "ace/mode/" + name;
  25. this.extensions = extensions;
  26. if (/\^/.test(extensions)) {
  27. var re = extensions.replace(/\|(\^)?/g, function(a, b){
  28. return "$|" + (b ? "^" : "^.*\\.");
  29. }) + "$";
  30. } else {
  31. var re = "^.*\\.(" + extensions + ")$";
  32. }
  33. this.extRe = new RegExp(re, "gi");
  34. };
  35. Mode.prototype.supportsFile = function(filename) {
  36. return filename.match(this.extRe);
  37. };
  38. // todo firstlinematch
  39. var supportedModes = {
  40. ABAP: ["abap"],
  41. ActionScript:["as"],
  42. ADA: ["ada|adb"],
  43. Apache_Conf: ["^htaccess|^htgroups|^htpasswd|^conf|htaccess|htgroups|htpasswd"],
  44. AsciiDoc: ["asciidoc"],
  45. Assembly_x86:["asm"],
  46. AutoHotKey: ["ahk"],
  47. BatchFile: ["bat|cmd"],
  48. C9Search: ["c9search_results"],
  49. C_Cpp: ["cpp|c|cc|cxx|h|hh|hpp"],
  50. Clojure: ["clj"],
  51. Cobol: ["CBL|COB"],
  52. coffee: ["coffee|cf|cson|^Cakefile"],
  53. ColdFusion: ["cfm"],
  54. CSharp: ["cs"],
  55. CSS: ["css"],
  56. Curly: ["curly"],
  57. D: ["d|di"],
  58. Dart: ["dart"],
  59. Diff: ["diff|patch"],
  60. Dot: ["dot"],
  61. Erlang: ["erl|hrl"],
  62. EJS: ["ejs"],
  63. Forth: ["frt|fs|ldr"],
  64. FTL: ["ftl"],
  65. Glsl: ["glsl|frag|vert"],
  66. golang: ["go"],
  67. Groovy: ["groovy"],
  68. HAML: ["haml"],
  69. Handlebars: ["hbs|handlebars|tpl|mustache"],
  70. Haskell: ["hs"],
  71. haXe: ["hx"],
  72. HTML: ["html|htm|xhtml"],
  73. HTML_Ruby: ["erb|rhtml|html.erb"],
  74. INI: ["ini|conf|cfg|prefs"],
  75. Jack: ["jack"],
  76. Jade: ["jade"],
  77. Java: ["java"],
  78. JavaScript: ["js|jsm"],
  79. JSON: ["json"],
  80. JSONiq: ["jq"],
  81. JSP: ["jsp"],
  82. JSX: ["jsx"],
  83. Julia: ["jl"],
  84. LaTeX: ["tex|latex|ltx|bib"],
  85. LESS: ["less"],
  86. Liquid: ["liquid"],
  87. Lisp: ["lisp"],
  88. LiveScript: ["ls"],
  89. LogiQL: ["logic|lql"],
  90. LSL: ["lsl"],
  91. Lua: ["lua"],
  92. LuaPage: ["lp"],
  93. Lucene: ["lucene"],
  94. Makefile: ["^Makefile|^GNUmakefile|^makefile|^OCamlMakefile|make"],
  95. MATLAB: ["matlab"],
  96. Markdown: ["md|markdown"],
  97. MySQL: ["mysql"],
  98. MUSHCode: ["mc|mush"],
  99. Nix: ["nix"],
  100. ObjectiveC: ["m|mm"],
  101. OCaml: ["ml|mli"],
  102. Pascal: ["pas|p"],
  103. Perl: ["pl|pm"],
  104. pgSQL: ["pgsql"],
  105. PHP: ["php|phtml"],
  106. Powershell: ["ps1"],
  107. Prolog: ["plg|prolog"],
  108. Properties: ["properties"],
  109. Protobuf: ["proto"],
  110. Python: ["py"],
  111. R: ["r"],
  112. RDoc: ["Rd"],
  113. RHTML: ["Rhtml"],
  114. Ruby: ["rb|ru|gemspec|rake|^Guardfile|^Rakefile|^Gemfile"],
  115. Rust: ["rs"],
  116. SASS: ["sass"],
  117. SCAD: ["scad"],
  118. Scala: ["scala"],
  119. Scheme: ["scm|rkt"],
  120. SCSS: ["scss"],
  121. SH: ["sh|bash|^.bashrc"],
  122. SJS: ["sjs"],
  123. Space: ["space"],
  124. snippets: ["snippets"],
  125. Soy_Template:["soy"],
  126. SQL: ["sql"],
  127. Stylus: ["styl|stylus"],
  128. SVG: ["svg"],
  129. Tcl: ["tcl"],
  130. Tex: ["tex"],
  131. Text: ["txt"],
  132. Textile: ["textile"],
  133. Toml: ["toml"],
  134. Twig: ["twig"],
  135. Typescript: ["ts|typescript|str"],
  136. VBScript: ["vbs"],
  137. Velocity: ["vm"],
  138. Verilog: ["v|vh|sv|svh"],
  139. XML: ["xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl"],
  140. XQuery: ["xq"],
  141. YAML: ["yaml|yml"]
  142. };
  143. var nameOverrides = {
  144. ObjectiveC: "Objective-C",
  145. CSharp: "C#",
  146. golang: "Go",
  147. C_Cpp: "C/C++",
  148. coffee: "CoffeeScript",
  149. HTML_Ruby: "HTML (Ruby)",
  150. FTL: "FreeMarker"
  151. };
  152. var modesByName = {};
  153. for (var name in supportedModes) {
  154. var data = supportedModes[name];
  155. var displayName = (nameOverrides[name] || name).replace(/_/g, " ");
  156. var filename = name.toLowerCase();
  157. var mode = new Mode(filename, displayName, data[0]);
  158. modesByName[filename] = mode;
  159. modes.push(mode);
  160. }
  161. module.exports = {
  162. getModeForPath: getModeForPath,
  163. modes: modes,
  164. modesByName: modesByName
  165. };
  166. });