You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
devdocs/assets/javascripts/models/entry.coffee

78 lines
1.7 KiB

#= require app/searcher
11 years ago
class app.models.Entry extends app.Model
# Attributes: name, type, path
constructor: ->
super
@text = applyAliases(app.Searcher.normalizeString(@name))
addAlias: (name) ->
text = applyAliases(app.Searcher.normalizeString(name))
@text = [@text] unless Array.isArray(@text)
@text.push(if Array.isArray(text) then text[1] else text)
return
11 years ago
fullPath: ->
@doc.fullPath if @isIndex() then '' else @path
dbPath: ->
@path.replace /#.*/, ''
11 years ago
filePath: ->
@doc.fullPath @_filePath()
fileUrl: ->
@doc.fileUrl @_filePath()
_filePath: ->
result = @path.replace /#.*/, ''
result += '.html' unless result[-5..-1] is '.html'
result
isIndex: ->
@path is 'index'
getType: ->
@doc.types.findBy 'name', @type
loadFile: (onSuccess, onError) ->
app.db.load(@, onSuccess, onError)
applyAliases = (string) ->
if ALIASES.hasOwnProperty(string)
return [string, ALIASES[string]]
else
words = string.split('.')
for word, i in words when ALIASES.hasOwnProperty(word)
words[i] = ALIASES[word]
return [string, words.join('.')]
return string
@ALIASES = ALIASES =
'angular': 'ng'
'angular.js': 'ng'
'backbone.js': 'bb'
'c++': 'cpp'
'coffeescript': 'cs'
'elixir': 'ex'
'javascript': 'js'
'jquery': '$'
'knockout.js': 'ko'
'less': 'ls'
'lodash': '_'
'marionette': 'mn'
'markdown': 'md'
'modernizr': 'mdr'
'moment.js': 'mt'
'nginx': 'ngx'
'numpy': 'np'
'postgresql': 'pg'
'python': 'py'
'ruby.on.rails': 'ror'
'ruby': 'rb'
'sass': 'scss'
'tensorflow': 'tf'
'typescript': 'ts'
'underscore.js': '_'