Skip to content

Commit

Permalink
Pushed g11n further so it did work with non-EN (credits + updated wor…
Browse files Browse the repository at this point in the history
…kshopper modules)
  • Loading branch information
tdd committed Feb 26, 2015
1 parent 8bae816 commit d7291e5
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 32 deletions.
33 changes: 22 additions & 11 deletions credits.js
@@ -1,15 +1,26 @@
var fs = require('fs');
var path = require('path');
var colors = require('colors-tmpl');
const fs = require('fs')
, path = require('path')
, colorsTmpl = require('colors-tmpl')
, combinedStream = require('combined-stream')

function read (file) {
return fs.createReadStream(path.join(__dirname, file), {encoding: 'utf8'})
}

function credits () {
fs.readFile(path.join(__dirname, './credits.txt'), 'utf8', function (err, data) {
if (err) {
throw err;
}
console.log(colors(data));
});
function credits (workshopper) {
combinedStream
.create()
.append(read ('./i18n/credits/' + workshopper.lang + '.header.txt'))
.append(read ('./credits.txt'))
.append(read ('./i18n/credits/' + workshopper.lang + '.footer.txt'))
.on("error", function (err) {
console.log(err)
throw err
})
.on("data", function (data) {
console.log(colorsTmpl(data))
})
.resume()
}

module.exports = credits;
module.exports = credits
13 changes: 4 additions & 9 deletions credits.txt
@@ -1,9 +1,4 @@
{yellow}{bold}You can learn generators due to this people:{/bold}{/yellow}

{bold}Name GitHub Twitter{/bold}
--------------------------------------------
Ruslan Ismagilov @isRuslan @is_ruslan
Ilia Akhmadullin @i_akhmadullin @i_akhmadullin
Max Ogden @maxogden @maxogden

{yellow}{bold}Rod Vagg (@rvagg){/yellow}{/bold} made this workshopper framework (⌐■_■)
Ruslan Ismagilov @isRuslan @is_ruslan
Ilia Akhmadullin @i_akhmadullin @i_akhmadullin
Max Ogden @maxogden @maxogden
Christophe Porteneuve @tdd @porteneuve
12 changes: 6 additions & 6 deletions exercise.js
Expand Up @@ -12,7 +12,7 @@ exercise = filecheck(exercise);

// execute the solution and submission in parallel with spawn()
exercise = execute(exercise);

exercise = comparestdout(exercise)

exercise = wrappedexec(exercise);
Expand All @@ -26,10 +26,10 @@ function rndport() {
exercise.addSetup(function (mode, callback) {
this.submissionPort = rndport();
this.solutionPort = this.submissionPort + 1;

this.submissionArgs.unshift(this.submissionPort);
this.solutionArgs.unshift(this.solutionPort);

this.submissionCommand = [ '--harmony', this.submission ].concat(this.submissionArgs);
this.solutionCommand = [ '--harmony', this.solution ].concat(this.solutionArgs);

Expand All @@ -39,9 +39,9 @@ exercise.addSetup(function (mode, callback) {
// check generators using
exercise.addVerifyProcessor(function (callback) {
var usedGenerators = exercise.wrapData.usedGenerators;
!usedGenerators && this.emit('fail', 'Seems like you haven\'t used generators (ಠ_ಠ)');

!usedGenerators && this.emit('fail', exercise.__('fail.didnt_use_generators'));

callback(null, usedGenerators);
})

Expand Down
2 changes: 2 additions & 0 deletions i18n/credits/en.footer.txt
@@ -0,0 +1,2 @@

{yellow}{bold}Rod Vagg (@rvagg){/yellow}{/bold} made this workshopper framework (⌐■_■)
4 changes: 4 additions & 0 deletions i18n/credits/en.header.txt
@@ -0,0 +1,4 @@
{yellow}{bold}You can learn generators due to this people:{/bold}{/yellow}

{bold}Name GitHub Twitter{/bold}
-----------------------------------------------------
2 changes: 2 additions & 0 deletions i18n/credits/fr.footer.txt
@@ -0,0 +1,2 @@

{yellow}{bold}Rod Vagg (@rvagg){/yellow}{/bold} a réalisé le framework d’ateliers (⌐■_■)
4 changes: 4 additions & 0 deletions i18n/credits/fr.header.txt
@@ -0,0 +1,4 @@
{yellow}{bold}Vous pouvez apprenre les générateurs grâce à ces personnes :{/bold}{/yellow}

{bold}Nom GitHub Twitter{/bold}
-----------------------------------------------------
1 change: 1 addition & 0 deletions i18n/en.json
Expand Up @@ -5,6 +5,7 @@
"credits": "CREDITS"
},
"error": {
"didnt_use_generators": "Seems like you haven't used generators (ಠ_ಠ)",
"has_generators": "{red}You need nodejs >= 0.11.x or iojs >= 1.0.x to work with generators.{/red}\n\nYou may find this useful:\n {bold}nvm{/bold} https://github.com/creationix/nvm\n {bold}n{/bold} https://github.com/tj/n"
}
}
19 changes: 19 additions & 0 deletions i18n/fr.json
@@ -0,0 +1,19 @@
{
"title": "Apprenez les Générateurs",
"subtitle": "Une intro aux générateurs ES6 via des exercices autonomes.",
"menu": {
"credits": "CRÉDITS"
},
"error": {
"didnt_use_generators": "On dirait que vous n’avez pas utilisé les générateurs (ಠ_ಠ)",
"has_generators": "{red}Vous avez besoin de Node.js >= 0.11.x ou io.js >= 1.0.x pour utiliser les générateurs.{/red}\n\nCeci peut vous être utile :\n {bold}nvm{/bold} https://github.com/creationix/nvm\n {bold}n{/bold} https://github.com/tj/n"
},
"exercise": {
"RUN STOP RUN": "DÉPART ARRÊT DÉPART",
"GENERATOR ITERATOR": "ITÉRATEUR GÉNÉRATEUR",
"DELEGATING GENERATORS": "DÉLÉGATION DE GÉNÉRATEURS",
"CATCH ERROR!": "RATTRAPE L'ERREUR !",
"LOOK SYNC. DO ASYNC.": "AIE L'AIR SYNC. RESTE ASYNC.",
"LOOK SYNC. MAKE PROMISE.": "AIE L'AIR SYNC. FAIS UNE PROMESSE."
}
}
2 changes: 1 addition & 1 deletion learn-generators.js
Expand Up @@ -12,7 +12,7 @@ function fpath (f) {
var learnGenerators = workshopper({
name : 'learn-generators',
appDir : __dirname,
languages : ['en'],
languages : ['en', 'fr'],
menuItems : [{
name : 'credits',
handler : credits
Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -24,9 +24,10 @@
],
"dependencies": {
"colors-tmpl": "~1.0.0",
"combined-stream": "0.0.7",
"has-generators": "^1.0.1",
"workshopper": "^2.1.1",
"workshopper-exercise": "^2.1.0",
"workshopper": "^2.3.1",
"workshopper-exercise": "^2.3.0",
"workshopper-wrappedexec": "^0.1.2"
},
"license": "MIT"
Expand Down
6 changes: 3 additions & 3 deletions wrap.js
Expand Up @@ -2,12 +2,12 @@ var fs = require('fs');

function wrap (ctx) {
var submissionContent = fs.readFileSync(ctx.mainProgram, 'utf-8');

// http://upshots.org/javascript/javascript-regexp-to-remove-comments
submissionContent = submissionContent.replace(/(\/\*([\s\S]*?)\*\/)|(\/\/(.*)$)/gm, '');

ctx.usedGenerators = false;

// just check `yield`, sorry
if (/yield/.test(submissionContent)) {
ctx.usedGenerators = true;
Expand Down

0 comments on commit d7291e5

Please sign in to comment.