summaryrefslogtreecommitdiffstats
path: root/afb-client/bower_components/foundation-apps/bin/gulp-dynamic-routing.js
diff options
context:
space:
mode:
authorStephane Desneux <stephane.desneux@iot.bzh>2016-05-31 18:16:48 +0200
committerStephane Desneux <stephane.desneux@iot.bzh>2016-05-31 18:16:48 +0200
commit5b1e6cc132f44262a873fa8296a2a3e1017b0278 (patch)
tree43b2cd54e2e300b399ff3f2af4458a2c4ed8a144 /afb-client/bower_components/foundation-apps/bin/gulp-dynamic-routing.js
parentf7d2f9ac4168ee5064580c666d508667a73cefc0 (diff)
parent85ace9c1ce9a98e9b8a22f045c7dd752b38d9129 (diff)
Merge afb-client
Diffstat (limited to 'afb-client/bower_components/foundation-apps/bin/gulp-dynamic-routing.js')
-rw-r--r--afb-client/bower_components/foundation-apps/bin/gulp-dynamic-routing.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/afb-client/bower_components/foundation-apps/bin/gulp-dynamic-routing.js b/afb-client/bower_components/foundation-apps/bin/gulp-dynamic-routing.js
new file mode 100644
index 0000000..3dc5350
--- /dev/null
+++ b/afb-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);
+};