entry.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //= require app/searcher
  2. app.models.Entry = class Entry extends app.Model {
  3. static applyAliases(string) {
  4. if (Entry.ALIASES.hasOwnProperty(string)) {
  5. return [string, Entry.ALIASES[string]];
  6. } else {
  7. const words = string.split(".");
  8. for (let i = 0; i < words.length; i++) {
  9. var word = words[i];
  10. if (Entry.ALIASES.hasOwnProperty(word)) {
  11. words[i] = Entry.ALIASES[word];
  12. return [string, words.join(".")];
  13. }
  14. }
  15. }
  16. return string;
  17. }
  18. static ALIASES = {
  19. angular: "ng",
  20. "angular.js": "ng",
  21. "backbone.js": "bb",
  22. "c++": "cpp",
  23. coffeescript: "cs",
  24. crystal: "cr",
  25. elixir: "ex",
  26. javascript: "js",
  27. julia: "jl",
  28. jquery: "$",
  29. "knockout.js": "ko",
  30. kubernetes: "k8s",
  31. less: "ls",
  32. lodash: "_",
  33. löve: "love",
  34. marionette: "mn",
  35. markdown: "md",
  36. matplotlib: "mpl",
  37. modernizr: "mdr",
  38. "moment.js": "mt",
  39. openjdk: "java",
  40. nginx: "ngx",
  41. numpy: "np",
  42. pandas: "pd",
  43. postgresql: "pg",
  44. python: "py",
  45. "ruby.on.rails": "ror",
  46. ruby: "rb",
  47. rust: "rs",
  48. sass: "scss",
  49. tensorflow: "tf",
  50. typescript: "ts",
  51. "underscore.js": "_",
  52. };
  53. // Attributes: name, type, path
  54. constructor() {
  55. super(...arguments);
  56. this.text = Entry.applyAliases(app.Searcher.normalizeString(this.name));
  57. }
  58. addAlias(name) {
  59. const text = Entry.applyAliases(app.Searcher.normalizeString(name));
  60. if (!Array.isArray(this.text)) {
  61. this.text = [this.text];
  62. }
  63. this.text.push(Array.isArray(text) ? text[1] : text);
  64. }
  65. fullPath() {
  66. return this.doc.fullPath(this.isIndex() ? "" : this.path);
  67. }
  68. dbPath() {
  69. return this.path.replace(/#.*/, "");
  70. }
  71. filePath() {
  72. return this.doc.fullPath(this._filePath());
  73. }
  74. fileUrl() {
  75. return this.doc.fileUrl(this._filePath());
  76. }
  77. _filePath() {
  78. let result = this.path.replace(/#.*/, "");
  79. if (result.slice(-5) !== ".html") {
  80. result += ".html";
  81. }
  82. return result;
  83. }
  84. isIndex() {
  85. return this.path === "index";
  86. }
  87. getType() {
  88. return this.doc.types.findBy("name", this.type);
  89. }
  90. loadFile(onSuccess, onError) {
  91. return app.db.load(this, onSuccess, onError);
  92. }
  93. };