More fixes to documentation popovers.

This commit is contained in:
Nick Winter 2014-07-15 19:25:53 -07:00
parent 906ab3ac2b
commit 6e9091fdf0
5 changed files with 37 additions and 30 deletions

View file

@ -3,30 +3,34 @@ h4
| - | -
code.prop-type= doc.type == 'function' && doc.owner == 'this' ? 'method' : doc.type code.prop-type= doc.type == 'function' && doc.owner == 'this' ? 'method' : doc.type
if doc.type != 'function' if doc.type != 'function'
| (read-only) if writable
| (writable)
else
| (read-only)
.description!= marked(doc.description || 'Still undocumented, sorry.') .description!= marked(doc.description || 'Still undocumented, sorry.')
if doc.example if !selectedMethod
p.example if doc.example
strong Example: p.example
div!= marked("```\n" + doc.example + "```") strong Example:
else if doc.type == 'function' && argumentExamples.length div!= marked("```\n" + doc.example + "```")
p.example else if doc.type == 'function' && argumentExamples.length
strong Example: p.example
div strong Example:
if language == 'javascript' div
code= doc.owner + '.' + doc.name + '(' + argumentExamples.join(', ') + ');' if language == 'javascript'
else if language == 'coffeescript' code= doc.owner + '.' + doc.name + '(' + argumentExamples.join(', ') + ');'
code= doc.ownerName + (doc.ownerName == '@' ? '' : '.') + doc.name + ' ' + argumentExamples.join(', ') else if language == 'coffeescript'
else if language == 'python' code= doc.ownerName + (doc.ownerName == '@' ? '' : '.') + doc.name + ' ' + argumentExamples.join(', ')
code= doc.ownerName + '.' + doc.name + '(' + argumentExamples.join(', ') + ')' else if language == 'python'
else if language == 'clojure' code= doc.ownerName + '.' + doc.name + '(' + argumentExamples.join(', ') + ')'
code= '(.' + doc.name + ' ' + doc.ownerName + ' ' + argumentExamples.join(', ') + ')' else if language == 'clojure'
else if language == 'lua' code= '(.' + doc.name + ' ' + doc.ownerName + ' ' + argumentExamples.join(', ') + ')'
code= doc.ownerName + ':' + doc.name + '(' + argumentExamples.join(', ') + ')' else if language == 'lua'
else if language == 'io' code= doc.ownerName + ':' + doc.name + '(' + argumentExamples.join(', ') + ')'
code= (doc.ownerName == 'this' ? '' : doc.ownerName + ' ') + doc.name + '(' + argumentExamples.join(', ') + ')' else if language == 'io'
code= (doc.ownerName == 'this' ? '' : doc.ownerName + ' ') + doc.name + '(' + argumentExamples.join(', ') + ')'
if (doc.type != 'function' && doc.type != 'snippet') || doc.name == 'now' if (doc.type != 'function' && doc.type != 'snippet') || doc.name == 'now'
p.value p.value
@ -64,3 +68,7 @@ if doc.returns
| ) | )
if doc.returns.description if doc.returns.description
div!= marked(doc.returns.description) div!= marked(doc.returns.description)
if selectedMethod
p
em Write the body of this method below.

View file

@ -93,7 +93,7 @@ module.exports = class DocFormatter
obj[prop] = null obj[prop] = null
formatPopover: -> formatPopover: ->
content = popoverTemplate doc: @doc, language: @options.language, value: @formatValue(), marked: marked, argumentExamples: (arg.example or arg.default or arg.name for arg in @doc.args ? []) content = popoverTemplate doc: @doc, language: @options.language, value: @formatValue(), marked: marked, argumentExamples: (arg.example or arg.default or arg.name for arg in @doc.args ? []), writable: @options.writable, selectedMethod: @options.selectedMethod
owner = if @doc.owner is 'this' then @options.thang else window[@doc.owner] owner = if @doc.owner is 'this' then @options.thang else window[@doc.owner]
content = content.replace /#{spriteName}/g, @options.thang.type ? @options.thang.spriteName # Prefer type, and excluded the quotes we'd get with @formatValue content = content.replace /#{spriteName}/g, @options.thang.type ? @options.thang.spriteName # Prefer type, and excluded the quotes we'd get with @formatValue
content.replace /\#\{(.*?)\}/g, (s, properties) => @formatValue downTheChain(owner, properties.split('.')) content.replace /\#\{(.*?)\}/g, (s, properties) => @formatValue downTheChain(owner, properties.split('.'))

View file

@ -61,7 +61,7 @@ module.exports = class SpellListTabEntryView extends SpellListEntryView
found = true found = true
break break
return unless found return unless found
docFormatter = new DocFormatter doc: doc, thang: @thang, language: @options.language docFormatter = new DocFormatter doc: doc, thang: @thang, language: @options.language, selectedMethod: true
@$el.find('code').popover( @$el.find('code').popover(
animation: true animation: true
html: true html: true

View file

@ -59,7 +59,7 @@ module.exports = class SpellPaletteView extends View
for lc in lcs for lc in lcs
for doc in (lc.get('propertyDocumentation') ? []) for doc in (lc.get('propertyDocumentation') ? [])
if doc.codeLanguages and not (@options.language in doc.codeLanguages) if doc.codeLanguages and not (@options.language in doc.codeLanguages)
excludedDocs[doc.name] = doc excludedDocs['__' + doc.name] = doc
continue continue
allDocs['__' + doc.name] ?= [] allDocs['__' + doc.name] ?= []
allDocs['__' + doc.name].push doc allDocs['__' + doc.name].push doc
@ -103,8 +103,8 @@ module.exports = class SpellPaletteView extends View
doc = _.find (allDocs['__' + prop] ? []), (doc) -> doc = _.find (allDocs['__' + prop] ? []), (doc) ->
return true if doc.owner is owner return true if doc.owner is owner
return (owner is 'this' or owner is 'more') and (not doc.owner? or doc.owner is 'this') return (owner is 'this' or owner is 'more') and (not doc.owner? or doc.owner is 'this')
if not doc and not excludedDocs[prop] if not doc and not excludedDocs['__' + prop]
console.log 'could not find doc for', prop, 'from', allDocs['__' + prop], 'for', owner, 'of', propGroups unless doc console.log 'could not find doc for', prop, 'from', allDocs['__' + prop], 'for', owner, 'of', propGroups
doc ?= prop doc ?= prop
if doc if doc
@entries.push @addEntry(doc, shortenize, tabbify, owner is 'snippets') @entries.push @addEntry(doc, shortenize, tabbify, owner is 'snippets')
@ -135,7 +135,8 @@ module.exports = class SpellPaletteView extends View
null null
addEntry: (doc, shortenize, tabbify, isSnippet=false) -> addEntry: (doc, shortenize, tabbify, isSnippet=false) ->
new SpellPaletteEntryView doc: doc, thang: @thang, shortenize: shortenize, tabbify: tabbify, isSnippet: isSnippet, language: @options.language writable = (if _.isString(doc) then doc else doc.name) in (@thang.apiUserProperties ? [])
new SpellPaletteEntryView doc: doc, thang: @thang, shortenize: shortenize, tabbify: tabbify, isSnippet: isSnippet, language: @options.language, writable: writable
onDisableControls: (e) -> @toggleControls e, false onDisableControls: (e) -> @toggleControls e, false
onEnableControls: (e) -> @toggleControls e, true onEnableControls: (e) -> @toggleControls e, true

View file

@ -179,9 +179,7 @@ module.exports = class SpellView extends View
doc = _.find (e.allDocs['__' + prop] ? []), (doc) -> doc = _.find (e.allDocs['__' + prop] ? []), (doc) ->
return true if doc.owner is owner return true if doc.owner is owner
return (owner is 'this' or owner is 'more') and (not doc.owner? or doc.owner is 'this') return (owner is 'this' or owner is 'more') and (not doc.owner? or doc.owner is 'this')
console.log 'could not find doc for', prop, 'from', e.allDocs['__' + prop], 'for', owner, 'of', e.propGroups unless doc if doc?.snippets?[e.language]
doc ?= prop
if doc.snippets?[e.language]
entry = entry =
content: doc.snippets[e.language].code content: doc.snippets[e.language].code
name: doc.name name: doc.name