Fix solution template problems breaking course guides, and list those broken solution templates in /artisans/solution-problems

This commit is contained in:
Nick Winter 2016-09-09 14:41:32 -07:00
parent 7bab895dee
commit bbe4a0540d
2 changed files with 22 additions and 3 deletions

View file

@ -53,7 +53,7 @@ module.exports = class SolutionProblemsView extends RootView
excludedLevelSnippets = [
'treasure', 'brawl', 'siege'
]
unloadedCampaigns: 0
campaignLevels: {}
loadedLevels: {}
@ -125,6 +125,7 @@ module.exports = class SolutionProblemsView extends RootView
problems = problems.concat(@findSimulationProblems solution)
problems = problems.concat(@findPass solution)
problems = problems.concat(@findIdenticalToSource solution, plan)
problems = problems.concat(@findTemplateProblems solution, plan)
@problemCount += problems.length
@parsedLevels.push
level: level
@ -138,7 +139,7 @@ module.exports = class SolutionProblemsView extends RootView
if _.findWhere(solutions, (elem) -> return elem.language is lang)
# TODO: Phase the following out:
else if lang not in excludedLanguages
problems.push
problems.push
type: 'Missing solution language'
value: lang
problems
@ -169,3 +170,16 @@ module.exports = class SolutionProblemsView extends RootView
type: 'Solution matches sample code'
value: solution.language
problems
findTemplateProblems: (solution, plan) ->
problems = []
source = if solution.lang is 'javascript' then plan.source else plan.languages[solution.language]
context = plan.context
try
_.template(source, context)
catch error
console.log source, context, error
problems.push
type: 'Solution template syntax error'
value: error.message
problems

View file

@ -45,7 +45,12 @@ module.exports = class TeacherCourseSolutionView extends RootView
if programmableMethod
level.set 'begin', _.template(programmableMethod.languages[@language] or programmableMethod.source)(programmableMethod.context)
solution = programmableMethod.solutions?.find (x) => x.language is @language
level.set 'solution', _.template(solution?.source)(programmableMethod.context)
try
solutionText = _.template(solution?.source)(programmableMethod.context)
catch error
solutionText = solution?.source
console.error "Couldn't create solution template of", solution?.source, "\nwith context", programmableMethod.context, "\nError:", error
level.set 'solution', solutionText
levels = []
for level in @levels?.models when level.get('original')
continue if @language? and level.get('primerLanguage') is @language