1
0

entry.coffee 986 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. class app.models.Entry extends app.Model
  2. # Attributes: name, type, path
  3. SEPARATORS_REGEXP = /\:?\ |#|::|->/g
  4. PARANTHESES_REGEXP = /\(.*?\)$/
  5. EVENT_REGEXP = /\ event$/
  6. DOT_REGEXP = /\.+/g
  7. constructor: ->
  8. super
  9. @text = @searchValue()
  10. searchValue: ->
  11. @name
  12. .toLowerCase()
  13. .replace '...', ' '
  14. .replace EVENT_REGEXP, ''
  15. .replace SEPARATORS_REGEXP, '.'
  16. .replace DOT_REGEXP, '.'
  17. .replace PARANTHESES_REGEXP, ''
  18. .trim()
  19. fullPath: ->
  20. @doc.fullPath if @isIndex() then '' else @path
  21. filePath: ->
  22. @doc.fullPath @_filePath()
  23. fileUrl: ->
  24. @doc.fileUrl @_filePath()
  25. _filePath: ->
  26. result = @path.replace /#.*/, ''
  27. result += '.html' unless result[-5..-1] is '.html'
  28. result
  29. isIndex: ->
  30. @path is 'index'
  31. getType: ->
  32. @doc.types.findBy 'name', @type
  33. loadFile: (onSuccess, onError) ->
  34. ajax
  35. url: @fileUrl()
  36. dataType: 'html'
  37. success: onSuccess
  38. error: onError