diff --git a/README.md b/README.md index 05f8fd227..9caa755fc 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Environment | Install Script | Repo --- | --- | --- | CSS Only | `npm install semantic-ui-css` | [CSS Repo](https://github.com/Semantic-Org/Semantic-UI-CSS) [LESS](https://github.com/less/less.js/) Only | `npm install semantic-ui-less` | [LESS Repo](https://github.com/Semantic-Org/Semantic-UI-LESS) +[LESS](https://github.com/less/less.js/) plugin | `npm install less-plugin-semantic-ui` | [LESS Plugin Repo](https://github.com/bassjobsen/less-plugin-semantic-ui/) [EmberJS](http://emberjs.com/) | `ember install:addon semantic-ui-ember` | [Ember Repo](https://github.com/Semantic-Org/Semantic-UI-Ember) |[Meteor](https://www.meteor.com/) - [LESS](https://github.com/less/less.js/) | `meteor add semantic:ui` | [LESS Repo](https://github.com/Semantic-Org/Semantic-UI-LESS) | |[Meteor](https://www.meteor.com/) - CSS | `meteor add semantic:ui-css` | [CSS Repo](https://github.com/Semantic-Org/Semantic-UI-CSS) | diff --git a/package.json b/package.json index 7e3a6f018..7e955e112 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,8 @@ "jquery": "^2.1.3", "mkdirp": "^0.5.0", "require-dot-file": "^0.4.0", + "map-stream": "^0.1.0", + "yamljs": "^0.2.1", "wrench": "git://github.com/derekslife/wrench-js.git#156eaceed68ed31ffe2a3ecfbcb2be6ed1417fb2" }, "devDependencies": { diff --git a/tasks/config/docs.js b/tasks/config/docs.js index 23e53bec3..f2192a83b 100644 --- a/tasks/config/docs.js +++ b/tasks/config/docs.js @@ -19,6 +19,9 @@ module.exports = { compressed : '../docs/out/dist/components/', themes : '../docs/out/dist/themes/' }, + template: { + eco: '../docs/server/documents/' + }, clean: '../docs/out/dist/' } -}; \ No newline at end of file +}; diff --git a/tasks/docs/build.js b/tasks/docs/build.js index f71a2a740..96eb40fec 100644 --- a/tasks/docs/build.js +++ b/tasks/docs/build.js @@ -8,6 +8,7 @@ var // node dependencies console = require('better-console'), fs = require('fs'), + map = require('map-stream'), // gulp dependencies autoprefixer = require('gulp-autoprefixer'), @@ -32,6 +33,9 @@ var tasks = require('../config/project/tasks'), install = require('../config/project/install'), + // metadata parsing + metadata = require('./metadata'), + // shorthand globs, assets, @@ -64,6 +68,21 @@ module.exports = function(callback) { output = config.paths.output; source = config.paths.source; + /*-------------- + Parse metadata + ---------------*/ + + // parse all *.html.eco in docs repo, data will end up in + // metadata.result object. Note this assumes that the docs + // repository is present and in proper directory location as + // specified by docs.json. + gulp.src(config.paths.template.eco + '**/*.html.eco') + .pipe(map(metadata.parser)) + .on('end', function() { + fs.writeFile(output.less + '/metadata.json', JSON.stringify(metadata.result, null, 2)); + }); + ; + /*-------------- Copy Source ---------------*/ @@ -74,7 +93,6 @@ module.exports = function(callback) { .pipe(print(log.created)) ; - /*-------------- Build ---------------*/ @@ -155,4 +173,4 @@ module.exports = function(callback) { }) ; -}; \ No newline at end of file +}; diff --git a/tasks/docs/metadata.js b/tasks/docs/metadata.js new file mode 100644 index 000000000..ef3b5f3db --- /dev/null +++ b/tasks/docs/metadata.js @@ -0,0 +1,107 @@ +/******************************* + Summarize Docs +*******************************/ + +var + // node dependencies + console = require('better-console'), + fs = require('fs'), + YAML = require('yamljs') +; + +var data = {}; + +/** + * Test for prefix in string. + * @param {string} str + * @param {string} prefix + * @return {boolean} + */ +function startsWith(str, prefix) { + return str.indexOf(prefix) === 0; +}; + +/** + * Parses a file for metadata and stores result in data object. + * @param {File} file - object provided by map-stream. + * @param {function(?,File)} - callback provided by map-stream to + * reply when done. + */ +function parseFile(file, cb) { + + if (file.isNull()) + return cb(null, file); // pass along + if (file.isStream()) + return cb(new Error("Streaming not supported")); + + try { + + var + /** @type {string} */ + text = String(file.contents.toString('utf8')), + lines = text.split('\n'); + + if (!lines) + return; + + var filename = file.path; + filename = filename.substring(0, filename.length - 4); + var key = 'server/documents'; + var position = filename.indexOf(key); + if (position < 0) + return cb(null, file); + filename = filename.substring(position + key.length + 1, filename.length); + + //console.log('Parsing ' + filename); + + var n = lines.length, + active = false, + yaml = [], + line + ; + + var line; + for (var i = 0; i < n; i++) { + line = lines[i]; + + // Wait for metadata block to begin + if (!active) { + if (startsWith(line, '---')) + active = true; + continue; + } + + + // End of metadata block, stop parsing. + if (startsWith(line, '---')) + break; + + yaml.push(line); + } + + // Parse yaml. + var meta = YAML.parse(yaml.join('\n')); + meta.category = meta.type; + meta.filename = filename; + meta._title = meta.title; // preserve original, just in case + meta.title = meta.type + ': ' + meta.title; + // Primary key will by filepath + data[filename] = meta; + + //console.log("Parsed " + filename + ": " + JSON.stringify(meta)); + + } catch(e) { + console.log(e); + } + + cb(null,file); + +} + +/** + * Export function expected by map-stream. + */ +module.exports = { + result: data, + parser: parseFile +};