entry.coffee 1.4 KB

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