From 75d719b67f15e4457162c3ef3bd1db2ef62e55e3 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Mon, 15 Feb 2016 20:01:29 +0100 Subject: Support resource templates in language/group/problem descriptions --- js/codeq/problem_list.js | 9 +++++++-- js/codeq/prolog.js | 2 ++ js/codeq/python.js | 2 ++ js/codeq/robot.js | 2 ++ js/codeq/template.js | 10 ++++++++++ 5 files changed, 23 insertions(+), 2 deletions(-) (limited to 'js/codeq') diff --git a/js/codeq/problem_list.js b/js/codeq/problem_list.js index 1384066..e28e672 100644 --- a/js/codeq/problem_list.js +++ b/js/codeq/problem_list.js @@ -221,6 +221,9 @@ along with this program. If not, see . */ baseTabIndex = 200; // tabindex attribute of the first problem link var langDict = convertTranslations(rawTranslations, 'name', 'description'), // this will be the resulting dictionary: multi-level keys that lead up to the lang-dict groupDict, problemDict; + + codeq.template.processDictionary(langDict.description, [languageIdentifier]); + // title: HTML structure for "name" and "desc" html.push('


'); html.push('

'); @@ -228,9 +231,11 @@ along with this program. If not, see . */ for (i = 0; i < Ngroups; i++) { group = groups[i] || {}; groupDict = convertTranslations(group.translations, 'name', 'description'); // the group-level translations, added will + codeq.template.processDictionary(groupDict.description, + [languageIdentifier, group.identifier]); // group content html.push('

'); - html.push('

'); + html.push('
'); html.push('
    '); // problem content problems = group.problems || []; @@ -268,7 +273,7 @@ along with this program. If not, see . */ var language = data.language; jqScreen.html(data.html); codeq.tr.translateDom(jqScreen); - jqScreen.find('a').on('click', function (e) { + jqScreen.find('.group-problems a').on('click', function (e) { var index = +$(this).attr('class').split(' ')[0].split('-')[1], ref = data.refs[index]; e.preventDefault(); diff --git a/js/codeq/prolog.js b/js/codeq/prolog.js index 1d2f92e..a3779d7 100644 --- a/js/codeq/prolog.js +++ b/js/codeq/prolog.js @@ -275,6 +275,8 @@ along with this program. If not, see . */ alert(error); }; + codeq.template.processDictionary(problemDef.translations.description, + [problemDef.language, problemDef.group, problemDef.problem]); codeq.tr.registerDictionary('prolog', problemDef.translations); codeq.tr.translateDom(jqScreen); jqBtnPlan.prop('disabled', !hinter.hasNextPlan()); diff --git a/js/codeq/python.js b/js/codeq/python.js index d688c7c..c28ee53 100644 --- a/js/codeq/python.js +++ b/js/codeq/python.js @@ -239,6 +239,8 @@ along with this program. If not, see . */ alert(error); }; + codeq.template.processDictionary(problemDef.translations.description, + [problemDef.language, problemDef.group, problemDef.problem]); codeq.tr.registerDictionary('python', problemDef.translations); codeq.tr.translateDom(jqScreen); jqBtnPlan.prop('disabled', !hinter.hasNextPlan()); diff --git a/js/codeq/robot.js b/js/codeq/robot.js index 15067b1..7f67025 100644 --- a/js/codeq/robot.js +++ b/js/codeq/robot.js @@ -239,6 +239,8 @@ along with this program. If not, see . */ } }); + codeq.template.processDictionary(problemDef.translations.description, + [problemDef.language, problemDef.group, problemDef.problem]); codeq.tr.registerDictionary('robot', problemDef.translations); codeq.tr.translateDom(jqScreen); jqBtnPlan.prop('disabled', !hinter.hasNextPlan()); diff --git a/js/codeq/template.js b/js/codeq/template.js index 361811b..90b4db3 100644 --- a/js/codeq/template.js +++ b/js/codeq/template.js @@ -276,9 +276,19 @@ along with this program. If not, see . */ resources = newResources; }, + // instantiate a template 'process': function (template, templatePath, args) { var fn = templator(template, templatePath); return fn(args); + }, + + // instantiate templates in a lang→template dictionary + 'processDictionary': function (dict, templatePath, args) { + var lang; + for (lang in dict) { + if (!dict.hasOwnProperty(lang)) continue; + dict[lang] = codeq.template.process(dict[lang], templatePath, args); + } } }; })(); -- cgit v1.2.1