mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Hack to use hero instead of self/this in SpellPalette docs (#3552)
Hack to change SpellPalette docs to use hero instead of self/this
This commit is contained in:
parent
ecf6cd7054
commit
b90f1fb18f
3 changed files with 23 additions and 6 deletions
|
@ -51,10 +51,10 @@ module.exports = class DocFormatter
|
||||||
else
|
else
|
||||||
@doc.owner ?= 'this'
|
@doc.owner ?= 'this'
|
||||||
ownerName = @doc.ownerName = if @doc.owner isnt 'this' then @doc.owner else switch @options.language
|
ownerName = @doc.ownerName = if @doc.owner isnt 'this' then @doc.owner else switch @options.language
|
||||||
when 'python', 'lua' then 'self'
|
when 'python', 'lua' then (if @options.useHero then 'hero' else 'self')
|
||||||
when 'java' then 'hero'
|
when 'java' then 'hero'
|
||||||
when 'coffeescript' then '@'
|
when 'coffeescript' then '@'
|
||||||
else 'this'
|
else (if @options.useHero then 'hero' else 'this')
|
||||||
if @doc.type is 'function'
|
if @doc.type is 'function'
|
||||||
[docName, args] = @getDocNameAndArguments()
|
[docName, args] = @getDocNameAndArguments()
|
||||||
sep = {clojure: ' '}[@options.language] ? ', '
|
sep = {clojure: ' '}[@options.language] ? ', '
|
||||||
|
@ -82,9 +82,9 @@ module.exports = class DocFormatter
|
||||||
if @options.language is 'javascript'
|
if @options.language is 'javascript'
|
||||||
@doc.shorterName = @doc.shortName.replace ';', ''
|
@doc.shorterName = @doc.shortName.replace ';', ''
|
||||||
if @doc.owner is 'this' or @options.tabbify
|
if @doc.owner is 'this' or @options.tabbify
|
||||||
@doc.shorterName = @doc.shorterName.replace /^this\./, ''
|
@doc.shorterName = @doc.shorterName.replace /^(this|hero)\./, ''
|
||||||
else if (@options.language in ['python', 'lua']) and (@doc.owner is 'this' or @options.tabbify)
|
else if (@options.language in ['python', 'lua']) and (@doc.owner is 'this' or @options.tabbify)
|
||||||
@doc.shorterName = @doc.shortName.replace /^self[:.]/, ''
|
@doc.shorterName = @doc.shortName.replace /^(self|hero)[:.]/, ''
|
||||||
@doc.title = if @options.shortenize then @doc.shorterName else @doc.shortName
|
@doc.title = if @options.shortenize then @doc.shorterName else @doc.shortName
|
||||||
|
|
||||||
# Grab the language-specific documentation for some sub-properties, if we have it.
|
# Grab the language-specific documentation for some sub-properties, if we have it.
|
||||||
|
@ -125,6 +125,21 @@ module.exports = class DocFormatter
|
||||||
console.error "Couldn't create docs template of", val, "\nwith context", context, "\nError:", 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.
|
obj[prop] = @replaceSpriteName obj[prop] # Do this before using the template, otherwise marked might get us first.
|
||||||
|
|
||||||
|
# Temporary hack to replace self|this with hero until we can update the docs
|
||||||
|
if @options.useHero
|
||||||
|
thisToken =
|
||||||
|
'python': /self/g,
|
||||||
|
'javascript': /this/g,
|
||||||
|
'lua': /self/g
|
||||||
|
|
||||||
|
if thisToken[@options.language]
|
||||||
|
if @doc.example
|
||||||
|
@doc.example = @doc.example.replace thisToken[@options.language], 'hero'
|
||||||
|
if @doc.snippets?[@options.language]?.code
|
||||||
|
@doc.snippets[@options.language].code.replace thisToken[@options.language], 'hero'
|
||||||
|
if @doc.args
|
||||||
|
arg.example = arg.example.replace thisToken[@options.language], 'hero' for arg in @doc.args when arg.example
|
||||||
|
|
||||||
if @doc.shortName is 'loop' and @options.level.get('type', true) in ['course', 'course-ladder']
|
if @doc.shortName is 'loop' and @options.level.get('type', true) in ['course', 'course-ladder']
|
||||||
@replaceSimpleLoops()
|
@replaceSimpleLoops()
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ module.exports = class SpellPaletteView extends CocoView
|
||||||
@session = options.session
|
@session = options.session
|
||||||
@supermodel = options.supermodel
|
@supermodel = options.supermodel
|
||||||
@thang = options.thang
|
@thang = options.thang
|
||||||
|
@useHero = options.useHero
|
||||||
docs = @options.level.get('documentation') ? {}
|
docs = @options.level.get('documentation') ? {}
|
||||||
@showsHelp = docs.specificArticles?.length or docs.generalArticles?.length
|
@showsHelp = docs.specificArticles?.length or docs.generalArticles?.length
|
||||||
@createPalette()
|
@createPalette()
|
||||||
|
@ -297,7 +298,7 @@ module.exports = class SpellPaletteView extends CocoView
|
||||||
|
|
||||||
addEntry: (doc, shortenize, isSnippet=false, item=null, showImage=false) ->
|
addEntry: (doc, shortenize, isSnippet=false, item=null, showImage=false) ->
|
||||||
writable = (if _.isString(doc) then doc else doc.name) in (@thang.apiUserProperties ? [])
|
writable = (if _.isString(doc) then doc else doc.name) in (@thang.apiUserProperties ? [])
|
||||||
new SpellPaletteEntryView doc: doc, thang: @thang, shortenize: shortenize, isSnippet: isSnippet, language: @options.language, writable: writable, level: @options.level, item: item, showImage: showImage
|
new SpellPaletteEntryView doc: doc, thang: @thang, shortenize: shortenize, isSnippet: isSnippet, language: @options.language, writable: writable, level: @options.level, item: item, showImage: showImage, useHero: @useHero
|
||||||
|
|
||||||
onDisableControls: (e) -> @toggleControls e, false
|
onDisableControls: (e) -> @toggleControls e, false
|
||||||
onEnableControls: (e) -> @toggleControls e, true
|
onEnableControls: (e) -> @toggleControls e, true
|
||||||
|
|
|
@ -218,7 +218,8 @@ module.exports = class TomeView extends CocoView
|
||||||
|
|
||||||
updateSpellPalette: (thang, spell) ->
|
updateSpellPalette: (thang, spell) ->
|
||||||
return unless thang and @spellPaletteView?.thang isnt thang and thang.programmableProperties or thang.apiProperties
|
return unless thang and @spellPaletteView?.thang isnt thang and thang.programmableProperties or thang.apiProperties
|
||||||
@spellPaletteView = @insertSubView new SpellPaletteView thang: thang, supermodel: @supermodel, programmable: spell?.canRead(), language: spell?.language ? @options.session.get('codeLanguage'), session: @options.session, level: @options.level, courseID: @options.courseID, courseInstanceID: @options.courseInstanceID
|
useHero = /hero/.test(spell.getSource())
|
||||||
|
@spellPaletteView = @insertSubView new SpellPaletteView thang: thang, supermodel: @supermodel, programmable: spell?.canRead(), language: spell?.language ? @options.session.get('codeLanguage'), session: @options.session, level: @options.level, courseID: @options.courseID, courseInstanceID: @options.courseInstanceID, useHero: useHero
|
||||||
@spellPaletteView.toggleControls {}, spell.view.controlsEnabled if spell?.view # TODO: know when palette should have been disabled but didn't exist
|
@spellPaletteView.toggleControls {}, spell.view.controlsEnabled if spell?.view # TODO: know when palette should have been disabled but didn't exist
|
||||||
|
|
||||||
spellFor: (thang, spellName) ->
|
spellFor: (thang, spellName) ->
|
||||||
|
|
Loading…
Reference in a new issue