Properly using the skill docs i18n. Fixed issue with markdown getting to #{spriteName} before our replacer did.

This commit is contained in:
Nick Winter 2014-11-23 13:26:19 -08:00
parent 294a37e2a2
commit 0b97ef5f0b
2 changed files with 9 additions and 2 deletions

View file

@ -116,13 +116,18 @@ module.exports = class DocFormatter
obj[prop] = _.template val, context
catch e
console.error "Couldn't create docs template of", val, "\nwith context", context, "\nError:", e
obj[prop] = @replaceSpriteName obj[prop] # Do this before using the template, otherwise marked might get us first.
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 ? []), writable: @options.writable, selectedMethod: @options.selectedMethod, cooldowns: @inferCooldowns(), item: @options.item
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 = @replaceSpriteName content
content.replace /\#\{(.*?)\}/g, (s, properties) => @formatValue downTheChain(owner, properties.split('.'))
replaceSpriteName: (s) ->
# Prefer type, and excluded the quotes we'd get with @formatValue
s.replace /#{spriteName}/g, @options.thang.type ? @options.thang.spriteName
formatValue: (v) ->
return null if @doc.type is 'snippet'
return @options.thang.now() if @doc.name is 'now'

View file

@ -46,10 +46,12 @@ module.exports = class SpellPaletteEntryView extends CocoView
content: @docFormatter.formatPopover()
container: 'body'
template: @overridePopoverTemplate
).on 'show.bs.popover', =>
).on 'shown.bs.popover', =>
Backbone.Mediator.publish 'tome:palette-hovered', thang: @thang, prop: @doc.name, entry: @
soundIndex = Math.floor(Math.random() * 4)
Backbone.Mediator.publish 'audio-player:play-sound', trigger: "spell-palette-entry-open-#{soundIndex}", volume: 0.75
popover = @$el.data('bs.popover')
popover?.$tip?.i18n()
onMouseEnter: (e) ->
# Make sure the doc has the updated Thang so it can regenerate its prop value