src/util.coffee in luca-0.9.4 vs src/util.coffee in luca-0.9.6
- old
+ new
@@ -1,18 +1,30 @@
# Takes an string like "deep.nested.value" and an object like window
# and returns the value of window.deep.nested.value. useful for defining
# references on objects which don't yet exist, as strings, which get
# evaluated at runtime when such references will be available
Luca.util.resolve = (accessor, source_object)->
- source_object ||= (window || global)
- _( accessor.split(/\./) ).inject (obj,key)->
- obj = obj?[key]
- , source_object
+ try
+ source_object ||= (window || global)
+ resolved = _( accessor.split(/\./) ).inject (obj,key)->
+ obj = obj?[key]
+ , source_object
+ catch e
+ console.log "Error resolving", accessor, source_object
+ throw e
+
+ resolved
# A better name for Luca.util.nestedValue
Luca.util.nestedValue = Luca.util.resolve
+Luca.util.argumentsLogger = (prompt)->
+ ()-> console.log prompt, arguments
+
+Luca.util.read = (property, args...)->
+ if _.isFunction(property) then property.apply(@, args) else property
+
# turns a word like form_view into FormView
Luca.util.classify = (string="")->
_.string.camelize( _.string.capitalize( string ) )
# looks up a method on an object by its event trigger
@@ -103,5 +115,6 @@
# valid types are success, warning, important, info, inverse
Luca.util.badge = (contents="", type, baseClass="badge")->
cssClass = baseClass
cssClass += " #{ baseClass }-#{ type }" if type?
Luca.util.make("span",{class:cssClass},contents)
+