1
0

entry.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. const Cls = (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)) { this.text = [this.text]; }
  74. this.text.push(Array.isArray(text) ? text[1] : text);
  75. }
  76. fullPath() {
  77. return this.doc.fullPath(this.isIndex() ? '' : this.path);
  78. }
  79. dbPath() {
  80. return this.path.replace(/#.*/, '');
  81. }
  82. filePath() {
  83. return this.doc.fullPath(this._filePath());
  84. }
  85. fileUrl() {
  86. return this.doc.fileUrl(this._filePath());
  87. }
  88. _filePath() {
  89. let result = this.path.replace(/#.*/, '');
  90. if (result.slice(-5) !== '.html') { result += '.html'; }
  91. return result;
  92. }
  93. isIndex() {
  94. return this.path === 'index';
  95. }
  96. getType() {
  97. return this.doc.types.findBy('name', this.type);
  98. }
  99. loadFile(onSuccess, onError) {
  100. return app.db.load(this, onSuccess, onError);
  101. }
  102. });
  103. Cls.initClass();
  104. return Cls;
  105. })();