entry.js 3.0 KB

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