From: Jeanie Chung
Date: Wed, 18 Feb 2015 22:25:19 +0000 (-0800)
Subject: Changes to subcolumns function and added optional parameters.
X-Git-Tag: v2.0.0-rc.1~129
X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5430ddd9346c1482ff238edd4b7336f12ebb171e;p=thirdparty%2Ffoundation%2Ffoundation-emails.git
Changes to subcolumns function and added optional parameters.
---
diff --git a/gulpfile.js b/gulpfile.js
index fedb9b71..e32294bd 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -139,7 +139,10 @@ gulp.task('js', function() {
gulp.task('query', function() {
gulp.src(dirs.html)
- .pipe(zfEmail())
+ .pipe(zfEmail({
+ grid: 12
+
+ }))
.pipe(gulp.dest(dirs.build))
.pipe(connect.reload());
});
diff --git a/html/index.html b/html/index.html
index 6bae2840..f98dc620 100644
--- a/html/index.html
+++ b/html/index.html
@@ -94,33 +94,35 @@
+ Hlaksdjflaksdjf
+
nerewo!!!!!!
-
- hellooo!!!
-
-
+
great success
-
- Some side content
-
-
-
+
Some side content
+
+ I'm calling you out!
+
-
+
Some side content
-
-
+
Some side content
-
+
+ .two
+
+
+ .ten
+
diff --git a/output/gulp-zurb-foundation-email/index.js b/output/gulp-zurb-foundation-email/index.js
index 9b1c2d6f..6664ef27 100644
--- a/output/gulp-zurb-foundation-email/index.js
+++ b/output/gulp-zurb-foundation-email/index.js
@@ -6,7 +6,7 @@ var cheerio = require('cheerio');
var inky = require('gulp-zurb-inky');
-module.exports = function () {
+module.exports = function (opts) {
"use strict";
var body = function (file) {
@@ -16,10 +16,9 @@ module.exports = function () {
var str = file.contents.toString('utf8');
var $ = cheerio.load(str);
- $ = inky.releaseTheKraken($);
+ $ = inky.releaseTheKraken($, opts);
file.contents = new Buffer($.html({normalizeWhitespace: true}));
- console.log($.html())
this.emit('data', file);
};
diff --git a/output/gulp-zurb-inky/index.js b/output/gulp-zurb-inky/index.js
index 0b31eb84..882f06bd 100644
--- a/output/gulp-zurb-inky/index.js
+++ b/output/gulp-zurb-inky/index.js
@@ -11,7 +11,7 @@ var Inky = function Inky () {
inlineListH: 'inline-list-h',
inlineListV: 'inline-list-v'
},
- this.columns = 12
+ this.grid = 12
};
Inky.prototype = {
@@ -89,10 +89,10 @@ Inky.prototype = {
// Returns:
// boolean: true/false
isTdElement: function(elType) {
- var tdEls = ['subcolumns', 'callout']
+ var tdEls = ['subcolumns'];
// if the element is an element that comes with td
- if (tdEls.indexOf(elType) !== -1) {
+ if (tdEls.indexOf(elType) > -1) {
// return true
return true;
}
@@ -101,20 +101,37 @@ Inky.prototype = {
}
},
+ // Description:
+ // Sets custom config for Inky
+ //
+ // Arguments:
+ // opts (object): configuration object
+ // Returns:
+ // null
+ setConfig: function(opts) {
+
+ for (var prop in opts) {
+ this[prop] = opts[prop];
+ }
+ },
// Description:
// Awww yiss. Kickstarts the whole parser. Takes in HTML loaded via Cheerio as an argument,
// checks if there are any custom components. If there are, it replaces the nested components,
// traverses the DOM and replaces them with email markup.
//
// Arguments:
- // $: Cheerio loaded string
+ // $, opts (object): Cheerio loaded string, configuration object
// Returns:
// $: Cheerio modified string
- releaseTheKraken: function($) {
+ releaseTheKraken: function($, opts) {
var center = $('center').html(),
self = this;
+ // set configuration
+ if (opts) {
+ self.setConfig(opts);
+ }
// create an array of our custom tags
self.setTagArray();
@@ -133,7 +150,7 @@ Inky.prototype = {
$ = cheerio.load(str);
// see the mark up for dev purposes
- console.log($.html());
+ // console.log($.html());
}
else {
console.log("all done");
@@ -312,23 +329,9 @@ Inky.prototype = {
case self.zfTags.button:
output = '';
break;
- // TODO: This is super messed up right now
- case self.zfTags.subcolumns:
- var subColSize = '';
- if ($(component).attr('small')) {
- subColSize += 'small' + '-' + $(component).attr('small') + ' ';
- }
- if ($(component).attr('large')) {
- subColSize += 'large' + '-' + $(component).attr('large') + ' ';
- }
-
- if ($(component).next()[0].name !== 'subcolumns') {
- output = '' + inner + ' | ';
- }
- else {
- output = '' + inner + ' | ';
- }
+ case self.zfTags.subcolumns:
+ output = self.makeCols($, component, 'subcolumns');
break;
case self.zfTags.container:
@@ -336,7 +339,7 @@ Inky.prototype = {
break;
case self.zfTags.columns:
- output = self.makeCols($, component);
+ output = self.makeCols($, component, 'columns');
break;
case self.zfTags.row:
@@ -363,6 +366,13 @@ Inky.prototype = {
return output;
},
+ // Description:
+ // Returns output for inline list elements.
+ //
+ // Arguments:
+ // $ (obj), col (obj), orientation (str): cheerio, the list, whether vertical/horizontal list
+ // Returns:
+ // HTML (string): Mark up for inline lists
makeInlineList: function($, list, orientation) {
var output = '';
var children = list.children();
@@ -390,7 +400,7 @@ Inky.prototype = {
// $ (obj), col (obj): cheerio, the target column
// Returns:
// HTML (string): Mark up for columns all contained in a row
- makeCols: function($, col) {
+ makeCols: function($, col, type) {
var output = '',
wrapperHTML = '',
colSize = '',
@@ -405,44 +415,51 @@ Inky.prototype = {
colClass = $(col).attr('class');
}
- // if it is the last column, add the class last
- if (!$(col).next()[0]) {
- output = '';
-
- } else {
- output = ' | ';
- }
-
// check for sizes
+ // if no attribute is provided, default to small-12
+ // divide evenly for large columns
if ($(col).attr('small')) {
colSize += 'small' + '-' + $(col).attr('small') + ' ';
}
else {
- colSize += 'large-' + Math.floor(self.columns/colCount) + ' ';
+ colSize += 'small-12 ';
}
if ($(col).attr('large')) {
colSize += 'large' + '-' + $(col).attr('large') + ' ';
}
else {
- colSize += 'large-' + Math.floor(self.columns/colCount) + ' ';
+ colSize += 'large-' + Math.floor(self.grid/colCount) + ' ';
}
- output += '';
+ // start making markup
+ if (type === 'columns') {
+ // if it is the last column, add the class last
+ if ($(col).next()[0] && $(col).next()[0].name !== 'columns') {
+ output = '| ';
+ } else {
+ output = ' | ';
+ }
- // if the column has children, put them in a td
- // if the child already has a td with it (i.e subcolumns/callouts), just place them inside
- // otherwise, place stuff inside columns in a td
+ output += '';
+ output += inner;
+ output += ' | ';
+ }
+ else if (type === 'subcolumns') {
- if ($(col).children()[0] && !self.isTdElement($(col).children()[0].name)) {
- output += ' | ' + inner + ' | ';
+ // if it is the last subcolumn, add the last class
+ if ($(col).next()[0] && $(col).next()[0].name !== 'subcolumns') {
+ output = '' + inner + ' | ';
+ }
+ else {
+ output = '' + inner + ' | ';
+ }
}
else {
- output += inner;
+ return;
}
- output += ' | ';
return output;
}
};
|