entry.coffee 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #= require app/searcher
  2. class app.models.Entry extends app.Model
  3. # Attributes: name, type, path
  4. constructor: ->
  5. super
  6. @text = applyAliases(app.Searcher.normalizeString(@name))
  7. addAlias: (name) ->
  8. text = applyAliases(app.Searcher.normalizeString(name))
  9. @text = [@text] unless Array.isArray(@text)
  10. @text.push(if Array.isArray(text) then text[1] else text)
  11. return
  12. fullPath: ->
  13. @doc.fullPath if @isIndex() then '' else @path
  14. dbPath: ->
  15. @path.replace /#.*/, ''
  16. filePath: ->
  17. @doc.fullPath @_filePath()
  18. fileUrl: ->
  19. @doc.fileUrl @_filePath()
  20. _filePath: ->
  21. result = @path.replace /#.*/, ''
  22. result += '.html' unless result[-5..-1] is '.html'
  23. result
  24. isIndex: ->
  25. @path is 'index'
  26. getType: ->
  27. @doc.types.findBy 'name', @type
  28. loadFile: (onSuccess, onError) ->
  29. app.db.load(@, onSuccess, onError)
  30. applyAliases = (string) ->
  31. if ALIASES.hasOwnProperty(string)
  32. return [string, ALIASES[string]]
  33. else
  34. words = string.split('.')
  35. for word, i in words when ALIASES.hasOwnProperty(word)
  36. words[i] = ALIASES[word]
  37. return [string, words.join('.')]
  38. return string
  39. @ALIASES = ALIASES =
  40. 'angular': 'ng'
  41. 'angular.js': 'ng'
  42. 'backbone.js': 'bb'
  43. 'c++': 'cpp'
  44. 'coffeescript': 'cs'
  45. 'elixir': 'ex'
  46. 'javascript': 'js'
  47. 'jquery': '$'
  48. 'knockout.js': 'ko'
  49. 'less': 'ls'
  50. 'lodash': '_'
  51. 'marionette': 'mn'
  52. 'markdown': 'md'
  53. 'modernizr': 'mdr'
  54. 'moment.js': 'mt'
  55. 'nginx': 'ngx'
  56. 'numpy': 'np'
  57. 'pandas': 'pd'
  58. 'postgresql': 'pg'
  59. 'python': 'py'
  60. 'ruby.on.rails': 'ror'
  61. 'ruby': 'rb'
  62. 'sass': 'scss'
  63. 'tensorflow': 'tf'
  64. 'typescript': 'ts'
  65. 'underscore.js': '_'