Skip to content

Commit eb798c9

Browse files
committed
Merge the next branch
2 parents 631cbb7 + c204a58 commit eb798c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3136
-805
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
/html/index.html
1+
/site/index.html
22
/build
3+
/html
4+
/site/de

build.js

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
var fs = require('fs'),
2+
path = require('path');
3+
jade = require('jade'),
4+
md = require('node-markdown'),
5+
Class = require('neko').Class;
6+
7+
var format = new require('fomatto').Formatter();
8+
9+
10+
// Garden Generator -------------------------------------------------------------
11+
// ------------------------------------------------------------------------------
12+
var Garden = Class(function(options) {
13+
var languages = fs.readdirSync(options.dir);
14+
15+
this.languages = {};
16+
this.options = options;
17+
this.options.language = this.json([this.options.dir, 'language.json'].join('/'));
18+
19+
var that = this;
20+
languages.forEach(function(lang) {
21+
if (fs.statSync(that.options.dir + '/' + lang).isDirectory()) {
22+
that.log('Parsing language "{}"...', lang);
23+
that.lang = {
24+
id: lang,
25+
navigation: [],
26+
index: []
27+
};
28+
29+
if (that.loadIndex()) {
30+
that.languages[lang] = that.lang;
31+
that.log(' Done.')
32+
33+
} else {
34+
that.log(' Error: Could not find "index.json"!')
35+
}
36+
}
37+
});
38+
39+
delete this.lang;
40+
this.log('');
41+
this.generateAll();
42+
43+
}, {
44+
log: function() {
45+
console.log(format.apply(null, arguments));
46+
},
47+
48+
loadIndex: function() {
49+
var that = this;
50+
this.lang.index = this.json([this.options.dir,
51+
this.lang.id, 'index.json'].join('/'));
52+
53+
if (this.lang.index === null) {
54+
return false;
55+
}
56+
57+
that.lang.title = that.lang.index.langTitle;
58+
this.lang.navigation = [];
59+
this.lang.index.sections.forEach(function(section, i) {
60+
that.loadSection(section);
61+
that.lang.navigation.push({
62+
title: section.title,
63+
link: section.dir,
64+
articles: section.articles,
65+
parsed: section.parsed
66+
});
67+
});
68+
return true;
69+
},
70+
71+
loadSection: function(section) {
72+
var files = fs.readdirSync(this.folder(section.dir));
73+
section.parsed = {};
74+
section.link = section.dir;
75+
76+
var that = this;
77+
section.articles = section.articles || [];
78+
section.articles.concat('index').forEach(function(article, e) {
79+
if (files.indexOf(article + '.md') !== -1) {
80+
var parsed = that.parseArticle(that.md(section.dir, article));
81+
section.parsed[article] = parsed;
82+
if (section.articles.indexOf(article) !== -1) {
83+
section.articles[e] = {
84+
id: article,
85+
link: section.link + '.' + article,
86+
title: parsed.title,
87+
parsed: parsed
88+
};
89+
}
90+
}
91+
});
92+
},
93+
94+
parseArticle: function(text) {
95+
var title = text.substring(0, text.indexOf('\n'));
96+
text = text.substring(title.length);
97+
title = md.Markdown(title.replace(/\#/g, '').trim());
98+
text = this.toMarkdown(text);
99+
100+
var parts = text.split('<h3>');
101+
var subs = [];
102+
for(var i = 0, l = parts.length; i < l; i++) {
103+
var sub = parts[i];
104+
subs.push((i > 0 ? '<h3>' : '') + sub);
105+
}
106+
107+
return {
108+
title: title.substring(3, title.length - 4),
109+
text: text,
110+
subs: subs
111+
};
112+
},
113+
114+
toMarkdown: function(text) {
115+
text = md.Markdown(text).replace(/'/g,'&#39;');
116+
text = text.replace(/<blockquote>/g, '<aside>').
117+
replace(/<\/blockquote>/g, '</aside>');
118+
119+
return text.replace(/<aside>\s+<p><strong>ES5/g,
120+
'<aside class="es5"><p><strong>ES5');
121+
},
122+
123+
json: function(file) {
124+
try {
125+
return JSON.parse(fs.readFileSync(file).toString());
126+
127+
} catch (err) {
128+
return null;
129+
}
130+
},
131+
132+
md: function(section, article) {
133+
var file = [this.folder(section), article].join('/') + '.md';
134+
return fs.readFileSync(file).toString();
135+
},
136+
137+
folder: function(section) {
138+
return [this.options.dir, this.lang.id, section].join('/');
139+
},
140+
141+
render: function(language, template, out) {
142+
var lang = this.languages[language];
143+
if (lang) {
144+
this.log('Rendering "{}" to "{}"...', language, out);
145+
146+
var languages = [];
147+
for(var i in this.languages) {
148+
if (this.languages.hasOwnProperty(i)) {
149+
if (this.options.language.listed.indexOf(i) !== -1) {
150+
languages.push(this.languages[i]);
151+
}
152+
}
153+
}
154+
155+
var options = {
156+
baseLanguage: this.options.language.default,
157+
language: language,
158+
languages: languages,
159+
title: lang.index.title,
160+
description: lang.index.description,
161+
navigation: lang.navigation,
162+
sections: lang.index.sections,
163+
top: lang.navigation[0]
164+
};
165+
166+
jade.renderFile(template, {locals: options}, function(err, html){
167+
if (err) throw err;
168+
fs.writeFileSync(out, html);
169+
});
170+
this.log(' Done.');
171+
}
172+
},
173+
174+
generateAll: function() {
175+
for(var i in this.languages) {
176+
if (this.languages.hasOwnProperty(i)) {
177+
this.generate(i);
178+
}
179+
}
180+
},
181+
182+
generate: function(lang) {
183+
var that = this;
184+
185+
var dir = [this.options.out];
186+
if (lang !== this.options.language.default) {
187+
dir.push(lang);
188+
}
189+
dir = dir.join('/');
190+
191+
path.exists(dir, function(exists) {
192+
if (!exists) {
193+
fs.mkdirSync(dir, '777');
194+
}
195+
that.render(lang, that.options.template, dir + '/index.html');
196+
});
197+
}
198+
});
199+
200+
new Garden({dir: 'doc', template: 'garden.jade', out: 'site'});
201+

doc/de/index.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"title": "JavaScript Garden",
3+
"langTitle": "JavaScript Garden in Deutsch",
4+
"description": "Ein Guide über JavaScript's Ecken und Kanten.",
5+
"sections": [
6+
{
7+
"title": "Einführung",
8+
"dir": "intro",
9+
"articles": [
10+
"authors",
11+
"contributors",
12+
"license"
13+
]
14+
}
15+
]
16+
}

doc/de/intro/authors.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## The Authors
2+
3+
This guide is the work of two lovely Stack Overflow users, [Ivo Wetzel][1]
4+
(Writing) and [Zhang Yi Jiang][2] (Design).
5+
6+
[1]: http://stackoverflow.com/users/170224/ivo-wetzel
7+
[2]: http://stackoverflow.com/users/313758/yi-jiang
8+

doc/de/intro/contributors.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Contributors
2+
3+
- [Caio Romão][1] (Spelling corrections)
4+
- [Andreas Blixt][2] (Language corrections)
5+
6+
[1]: https://github.com/caio
7+
[2]: https://github.com/blixt
8+

doc/de/intro/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Einführung
2+
3+
Demnächst.
4+

doc/de/intro/license.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## License
2+
3+
JavaScript Garden is published under the [MIT license][1] and hosted on
4+
[GitHub][2]. If you find errors or typos please [file an issue][3] or a pull
5+
request on the repository. You can also find us in the [JavaScript room][4] on
6+
Stack Overflow chat.
7+
8+
[1]: https://github.com/BonsaiDen/JavaScript-Garden/blob/next/LICENSE
9+
[2]: https://github.com/BonsaiDen/JavaScript-Garden
10+
[3]: https://github.com/BonsaiDen/JavaScript-Garden/issues
11+
[4]: http://chat.stackoverflow.com/rooms/17/javascript
12+

doc/arrayctor.md renamed to doc/en/array/constructor.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## The `Array` constructor
1+
## The `Array` Constructor
22

33
Since the `Array` constructor is ambiguous in how it deals with its parameters,
44
it is highly recommended to always use the array literals - `[]` notation -

doc/arrays.md renamed to doc/en/array/general.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
## Arrays
1+
## Array Iteration and Properties
22

33
Although arrays in JavaScript are objects, there are no good reasons to use
4-
the [`for in loop`](#forinloop) in for iteration on them. In fact there are a
5-
number of good reasons **against** the use of `for in` on arrays.
4+
the [`for in loop`](#object.forinloop) in for iteration on them. In fact there
5+
are a number of good reasons **against** the use of `for in` on arrays.
66

77
> **Note:** JavaScript arrays are **not** *associative arrays*. JavaScript only
8-
> has [objects](#objects) for mapping keys to values. And while associative
8+
> has [objects](#object.general) for mapping keys to values. And while associative
99
> arrays **preserve** order, objects **do not**.
1010
1111
Since the `for in` loop enumerates all the properties that are on the prototype
1212
chain and the only way to exclude those properties is to use
13-
[`hasOwnProperty`](#hasownproperty), it is already up to **twenty times** slower
14-
than a normal `for` loop.
13+
[`hasOwnProperty`](#object.hasownproperty), it is already up to **twenty times**
14+
slower than a normal `for` loop.
1515

1616
### Iteration
1717

doc/eval.md renamed to doc/en/core/eval.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Reasons against `eval`
1+
## Why not to use `eval`
22

33
The `eval` function will execute a string of JavaScript code in the local scope.
44

@@ -29,9 +29,9 @@ achieved **without** it.
2929

3030
### `eval` in disguise
3131

32-
The [timeout functions](#timeouts) `setTimeout` and `setInterval` can both take a
33-
string as their first argument. This string will **always** get executed in the
34-
global scope since `eval` is not being called directly in that case.
32+
The [timeout functions](#other.timeouts) `setTimeout` and `setInterval` can both
33+
take a string as their first argument. This string will **always** get executed
34+
in the global scope since `eval` is not being called directly in that case.
3535

3636
### Security issues
3737

0 commit comments

Comments
 (0)