Spike optional doc: key for command

This isn't working yet.
This commit is contained in:
John Barnette
2013-03-13 19:40:35 -07:00
parent 2b35eaa414
commit 460577d9ae
2 changed files with 32 additions and 9 deletions

View File

@@ -59,7 +59,12 @@ $.fn.trueHeight = ->
$.fn.trueWidth = ->
this[0].getBoundingClientRect().width
$.fn.document = (eventDescriptions) ->
$.fn.document = (eventDescriptions, optionalDoc) ->
if optionalDoc
eventName = eventDescriptions
eventDescriptions = {}
eventDescriptions[eventName] = optionalDoc
@data('documentation', {}) unless @data('documentation')
_.extend(@data('documentation'), eventDescriptions)
@@ -75,12 +80,26 @@ $.fn.events = ->
else
events
$.fn.command = (args...) ->
eventName = args[0]
documentation = {}
documentation[eventName] = _.humanizeEventName(eventName)
@document(documentation)
@on(args...)
# Valid calling styles:
# command(eventName, handler)
# command(eventName, selector, handler)
# command(eventName, options, handler)
# command(eventName, selector, options, handler)
$.fn.command = (eventName, selector, options, handler) ->
if not options? and not handler?
handler = selector
selector = null
else if not handler?
handler = options
options = null
if selector? and typeof(selector) is 'object'
handler = options
options = selector
selector = null
@document(eventName, _.humanizeEventName(eventName, options?["xxx"]))
@on(eventName, selector, options?['data'], handler)
$.fn.iconSize = (size) ->
@width(size).height(size).css('font-size', size)

View File

@@ -52,10 +52,14 @@ _.mixin
regex = RegExp('[' + specials.join('\\') + ']', 'g')
string.replace(regex, "\\$&");
humanizeEventName: (eventName) ->
humanizeEventName: (eventName, optionalDocString) ->
return "GitHub" if eventName.toLowerCase() is "github"
if /:/.test(eventName)
[namespace, name] = eventName.split(':')
return "#{@humanizeEventName(namespace)}: #{@humanizeEventName(name)}"
return "#{@humanizeEventName(namespace)}: #{@humanizeEventName(name, optionalDocString)}"
return optionalDocString if not _.isEmpty(optionalDocString)
words = eventName.split('-')
words.map(_.capitalize).join(' ')