summaryrefslogtreecommitdiffstats
path: root/afm-client/bower_components/foundation-apps/bin
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2016-01-28 16:30:12 +0100
committerFulup Ar Foll <fulup@iot.bzh>2016-01-28 16:30:12 +0100
commitbe83a8f382cf2fea98161bfd6d51719aacbf9aa9 (patch)
tree3fb02337f8d7d308ef7ca7818ecc3d3a6ee05d88 /afm-client/bower_components/foundation-apps/bin
parent1a4ed39bf86b2115eb0f1387d1e988462b492776 (diff)
Update JSON API
Diffstat (limited to 'afm-client/bower_components/foundation-apps/bin')
-rw-r--r--afm-client/bower_components/foundation-apps/bin/gulp-dynamic-routing.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/afm-client/bower_components/foundation-apps/bin/gulp-dynamic-routing.js b/afm-client/bower_components/foundation-apps/bin/gulp-dynamic-routing.js
new file mode 100644
index 0000000..3dc5350
--- /dev/null
+++ b/afm-client/bower_components/foundation-apps/bin/gulp-dynamic-routing.js
@@ -0,0 +1,56 @@
+var through = require('through2');
+var gutil = require('gulp-util');
+var fm = require('front-matter');
+var PluginError = gutil.PluginError;
+var path = require('path');
+var fs = require('fs');
+
+module.exports = function(options) {
+ var configs = [];
+ var directory = options.dir || process.cwd();
+
+ function bufferContents(file, enc, cb) {
+ var config;
+ var content;
+
+ if(file.isNull()) return cb(null, file);
+
+ if(file.isBuffer()) {
+ try {
+ content = fm(String(file.contents));
+ } catch (e) {
+ return cb(new PluginError('Gulp Dynamic Routing', e));
+ }
+
+ if(content.attributes.name) {
+ file.contents = new Buffer(content.body);
+ config = content.attributes;
+ var relativePath = path.relative(directory + path.sep + options.root, file.path);
+ config.path = relativePath.split(path.sep).join('/');
+ configs.push(config);
+ }
+ }
+
+ this.push(file);
+
+ return cb();
+ }
+
+ function endStream(cb) {
+ var self = this;
+ var appPath = options.path;
+
+ configs.sort(function(a, b) {
+ return a.url < b.url;
+ });
+
+
+ fs.writeFile(appPath, 'var foundationRoutes = ' + JSON.stringify(configs) + '; \n', function(err) {
+ if(err) throw err;
+ cb();
+ });
+
+ }
+
+ return through.obj(bufferContents, endStream);
+};