]> git.ipfire.org Git - thirdparty/foundation/foundation-emails.git/commitdiff
Added sourcecode for inky prime task.
authorJeanie Chung <jeanie.chung@gmail.com>
Wed, 28 Jan 2015 22:28:34 +0000 (14:28 -0800)
committerJeanie Chung <jeanie.chung@gmail.com>
Wed, 28 Jan 2015 22:28:34 +0000 (14:28 -0800)
gulpfile.js
output/index.js [new file with mode: 0644]

index a42c195e898c11b901cff1ced0d10176fb1d1fd1..61f087fbb10071cb83e5489b02825e7384cbae0a 100644 (file)
@@ -121,10 +121,8 @@ gulp.task('jquery', function() {
 });
 
 gulp.task('inky-prime', function() {
-  return gulp.src(dirs.js)
-    .pipe(concat('inky-prime.js'))
-    .pipe(gulp.dest(dirs.build + '/js/'))
-    .pipe(connect.reload());  
+  return gulp.src('node_modules/gulp-zurb-foundation-email/index.js')
+    .pipe(gulp.dest('./output'));
 })
 
 gulp.task('js', ['clean:js', 'jquery'], function() {
diff --git a/output/index.js b/output/index.js
new file mode 100644 (file)
index 0000000..9dc1f46
--- /dev/null
@@ -0,0 +1,127 @@
+var es = require('event-stream');
+var gutil = require('gulp-util');
+var Buffer = require('buffer').Buffer;
+
+var cheerio = require('cheerio');
+
+module.exports = function (body) {
+  "use strict";
+
+  var body = function (file) {
+    if (file.isNull()) { return this.emit('data', file); }
+    if (file.isStream()) { return this.emit('error', new Error("gulp-coffee: Streaming not supported")); }
+
+    var str = file.contents.toString('utf8');
+    var $ = cheerio.load(str);
+
+    var insertComponents = function(element, type) {
+      var output     = '';
+      var component  = $(element);
+      var inner      = $(element).html();
+      var compClass  = '';
+
+      if ($(component).attr('class')) {
+        compClass = $(component).attr('class');
+      };
+
+      if (type === "panel") {
+        output += '<td class="panel ' + compClass +'">' + inner + '</td>';
+      }
+      else if (type === "button") {
+        output += '<td><table class="button ' + compClass +'"><tbody><tr><td>' + inner + '</td></tr></tbody></table></td>'
+      }
+      else {
+        output += '<td>' + inner + '</td>';
+      }
+
+      return output;
+    };
+
+    var createCol = function(obj) {
+      var output   = '';
+
+      // create tables with column class for each nested element
+      var colElements = function(elements, colSize) {
+        var colHTML = '';
+        $(elements).each(function(i, el) {
+          // get included tags of each element in the column
+          var element  = $(el)[0];
+          var elType   = $(el)[0].name;
+          var colClass = 'columns ';
+          var content  = '';
+
+          // transclude any class that might have been added onto element
+          if ($(el).attr('class')) {
+            colClass += $(el).attr('class');
+          };
+          content = insertComponents(element, elType);
+
+          // construct column class for each element
+          colHTML += '<table class="' + colClass + ' ' + colSize+'">'
+                  +'<tr>'
+                  + content +'<td class="expander"></td></tr></table>';
+        });
+
+        return colHTML;
+      };
+
+
+      // create tables with wrapper class for each column
+      $(obj).each(function(k,v) {
+        var wrapperHTML = '';
+        var colSize     = '';
+        var col         = $(v)[0];
+        var elements    = $(v).children();
+        var colClass    = '';
+        if ($(col).attr('class')) {
+          colClass = $(col).attr('class');
+        }
+
+        // if wrapper is last or the only one, put last class
+        if (k === obj.length - 1) {
+          wrapperHTML += '<td class="wrapper ' + colClass + ' last">';
+        } else {
+          wrapperHTML += '<td class="wrapper ' + colClass + '">';
+        }
+
+        // check for sizes
+        if ($(col).attr('small')) {
+          colSize += 'small' + '-' + $(col).attr('small') + ' ';
+        }
+        if ($(col).attr('large')) {
+          colSize += 'large' + '-' + $(col).attr('large') + ' ';
+        }
+
+        wrapperHTML += colElements(elements, colSize);
+        wrapperHTML += '</td>';
+
+        output += wrapperHTML;
+      });
+
+      return output;
+    };
+
+    $('container').each(function() {
+      var contents = $(this).html();
+
+      $(this).replaceWith('<table class="container"><tbody><tr><td>' + contents + '</td></tr></tbody></table>');
+    });
+
+    $('row').each(function(i) {
+      var contents = $(this).html();
+
+      // if row does has nested elements (i.e. not empty)
+      if ($(this).children('column')) {
+        contents = createCol($(contents));
+      }
+
+      $(this).replaceWith('<table class="row"><tbody><tr>'+ contents + '</tr></tbody></table>');
+
+    });
+
+    file.contents = new Buffer($.html());
+    this.emit('data', file);
+  };
+
+  return es.through(body);
+};