From 6662d9cf2d276a29805ae7cf17f5d6ad0b96f904 Mon Sep 17 00:00:00 2001 From: Naomi Date: Mon, 24 Jun 2013 15:20:52 -0500 Subject: [PATCH 001/170] Add a `.bind` solution for setTimeout examples --- doc/en/function/closures.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/en/function/closures.md b/doc/en/function/closures.md index 76f2d078..69d401b6 100644 --- a/doc/en/function/closures.md +++ b/doc/en/function/closures.md @@ -96,3 +96,10 @@ above. })(i), 1000) } +There's yet another way to accomplish this by using `.bind`, which can bind +a `this` context and arguments to function. It behaves identially to the code +above + + for(var i = 0; i < 10; i++) { + setTimeout(console.log.bind(console, i), 1000); + } From ae291a4002602ad217050fc26032cb81b07b7680 Mon Sep 17 00:00:00 2001 From: Tim Ruffles Date: Thu, 24 Oct 2013 14:59:49 +0100 Subject: [PATCH 002/170] new deploy script, build script OO -> FP, remove some special cases --- .lvimrc | 4 + build.js | 286 ++++++++++++++------------------------------ deploy.sh | 24 ++++ doc/en/index.json | 2 +- doc/es/index.json | 2 +- doc/ja/index.json | 2 +- doc/ko/index.json | 2 +- doc/tr/index.json | 2 +- doc/zhtw/index.json | 2 +- garden.jade | 17 ++- package.json | 21 ++-- server.js | 33 ----- 12 files changed, 146 insertions(+), 251 deletions(-) create mode 100644 .lvimrc create mode 100644 deploy.sh delete mode 100644 server.js diff --git a/.lvimrc b/.lvimrc new file mode 100644 index 00000000..23b445a9 --- /dev/null +++ b/.lvimrc @@ -0,0 +1,4 @@ +set wildignore=node_modules +set tabstop=2 +set shiftwidth=2 +set softtabstop=2 diff --git a/build.js b/build.js index 50e9d0c5..0c7be50a 100644 --- a/build.js +++ b/build.js @@ -1,206 +1,106 @@ -var fs = require('fs'), - path = require('path'), - jade = require('jade'), - md = require('node-markdown'), - Class = require('neko').Class; - -var format = new require('fomatto').Formatter(); - - -// Garden Generator ------------------------------------------------------------- -// ------------------------------------------------------------------------------ -var Garden = Class(function(options) { - var languages = fs.readdirSync(options.dir); - - this.languages = {}; - this.options = options; - this.options.language = this.json([this.options.dir, 'language.json'].join('/')); - - var that = this; - languages.forEach(function(lang) { - if (fs.statSync(that.options.dir + '/' + lang).isDirectory()) { - that.log('Parsing language "{}"...', lang); - that.lang = { - id: lang, - navigation: [], - index: [] - }; - - if (that.loadIndex()) { - that.languages[lang] = that.lang; - that.log(' Done.'); - - } else { - that.log(' Error: Could not find "index.json"!'); - } - } - }); - - delete this.lang; - this.log(''); - this.generateAll(); - -}, { - log: function() { - console.log(format.apply(null, arguments)); - }, - - loadIndex: function() { - var that = this; - this.lang.index = this.json([this.options.dir, - this.lang.id, 'index.json'].join('/')); - - if (this.lang.index === null) { - return false; - } - - that.lang.title = that.lang.index.langTitle; - this.lang.navigation = []; - this.lang.index.sections.forEach(function(section, i) { - that.loadSection(section); - that.lang.navigation.push({ - title: section.title, - link: section.dir, - articles: section.articles, - parsed: section.parsed - }); - }); - return true; - }, - - loadSection: function(section) { - var files = fs.readdirSync(this.folder(section.dir)); - section.parsed = {}; - section.link = section.dir; - - var that = this; - section.articles = section.articles || []; - section.articles.concat('index').forEach(function(article, e) { - if (files.indexOf(article + '.md') !== -1) { - var parsed = that.parseArticle(that.md(section.dir, article)); - section.parsed[article] = parsed; - if (section.articles.indexOf(article) !== -1) { - section.articles[e] = { - id: article, - link: section.link + '.' + article, - title: parsed.title, - parsed: parsed - }; - } - } - }); - }, - - parseArticle: function(text) { - var title = text.substring(0, text.indexOf('\n')); - text = text.substring(title.length); - title = md.Markdown(title.replace(/\#/g, '').trim()); - text = this.toMarkdown(text); - - var parts = text.split('

'); - var subs = []; - for(var i = 0, l = parts.length; i < l; i++) { - var sub = parts[i]; - subs.push((i > 0 ? '

' : '') + sub); - } - - return { - title: title.substring(3, title.length - 4), - text: text, - subs: subs - }; - }, - - toMarkdown: function(text) { - text = md.Markdown(text).replace(/'/g,'''); - text = text.replace(/
/g, ''); - - return text.replace(/