Replace simple loop docs with while-true docs in course levels

This commit is contained in:
Nick Winter 2015-10-22 10:29:10 -07:00
parent 8d43be2236
commit 4af6162c5c

View file

@ -124,6 +124,28 @@ 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.
if @doc.shortName is 'loop' and @options.level.get('type', true) in ['course', 'course-ladder']
@replaceSimpleLoops()
replaceSimpleLoops: ->
# Temporary hackery to make it look like we meant while True: in our loop: docs until we can update everything
@doc.shortName = @doc.shorterName = @doc.title = @doc.name = switch @options.language
when 'coffeescript' then "loop"
when 'python' then "while True:"
when 'lua' then "while true do"
when 'clojure' then "(while true)"
when 'io' then "while(true)"
else "while (true)"
for field in ['example', 'description']
[simpleLoop, whileLoop] = switch @options.language
when 'coffeescript' then [/loop/g, "loop"]
when 'python' then [/loop:/g, "while True:"]
when 'lua' then [/loop/g, "while true do"]
when 'clojure' then [/\(dotimes( \[n \d+\])?/g, "(while true"]
when 'io' then [/loop\(/g, "while(true,"]
else [/loop/g, "while (true)"]
@doc[field] = @doc[field].replace simpleLoop, whileLoop
formatPopover: -> formatPopover: ->
[docName, args] = @getDocNameAndArguments() [docName, args] = @getDocNameAndArguments()
argumentExamples = (arg.example or arg.default or arg.name for arg in @doc.args ? []) argumentExamples = (arg.example or arg.default or arg.name for arg in @doc.args ? [])