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('
/g, ''); return text.replace(/