Lanes.emptyFn = -> Lanes.fatal = (args...)-> Lanes.warn(args...) throw new Error(args...) Lanes.warn = (msg...)-> return unless console if msg[0] instanceof Error console.warn(msg[0].stack) else console.warn(msg...) null Lanes.log = (msg...)-> return unless console if msg[0] instanceof Error console.warn(msg[0].stack) else console.log(msg...) null distillTypes = (type, ns)-> _.reduce( type.split( '.' ), ( ( memo, val )-> return if memo then memo[ val ] else null ), ns ) Lanes.u = { objectPath: (FILE)-> FILE.path path: (FILE)-> FILE.path.join("/") dirname: (FILE)-> FILE.path[0...FILE.path.length-1].join("/") findObject:(name, subPath, file=FILE) -> if _.isObject(name) name else file.namespace[subPath]?[name] || Lanes[subPath]?[name] || Lanes.u.getPath(name) # Can be called one of two ways: # With ns being a string, which will attempt to deref it then deref name inside it # or with ns being an object, which will dref name inside it getPath: ( name, ns='Lanes' ) -> return name unless _.isString(name) ns = "Lanes.#{ns}" if _.isString(ns) && !ns.match("Lanes") distillTypes(name, window) || distillTypes(name, if _.isObject(ns) then ns else distillTypes(ns, window) ) # Like underscore's results but allows passing # arguments to the function if it's called resultsFor:( scope, method, args... )-> if _.isString(method) if _.isFunction(scope[method]) scope[method].apply(scope,args) else scope[method] else if _.isFunction(method) method.apply(scope,args) else method } # Can be called one of two ways: # With ns being a string, which will attempt to deref it then deref name inside it # or with ns being an object, which will dref name inside it # Lanes.getPath = ( name, ns='Lanes' ) -> # return name unless _.isString(name) # ns = "Lanes.#{ns}" if _.isString(ns) && !ns.match("Lanes") # distillTypes(name, window) || distillTypes(name, if _.isObject(ns) then ns else distillTypes(ns, window) ) # Lanes.findObject = (name, subPath, file=FILE) -> # if _.isObject(name) # name # else # file.namespace[subPath]?[name] || Lanes[subPath]?[name] || Lanes.getPath(name) lcDash = (char, match, index)-> return ( if index == 0 then '' else '_' ) + char.toLowerCase() _.mixin({ dasherize: (str)-> _.trim(str).replace(/([A-Z])/g,lcDash).replace(/[-_\s]+/g, '-').toLowerCase(); toSentence: (words=[], comma=', ', nd=' and ')-> last = words.pop() if last if words.length [words.join(comma),last].join(nd) else last else '' })