]> git.ipfire.org Git - thirdparty/foundation/foundation-emails.git/commitdiff
Finalized inky-parser method with working reload. Now you can work on partials withou...
authorJeanie Chung <jeanie.chung@gmail.com>
Fri, 20 Feb 2015 02:04:29 +0000 (18:04 -0800)
committerJeanie Chung <jeanie.chung@gmail.com>
Fri, 20 Feb 2015 02:04:29 +0000 (18:04 -0800)
gulpfile.js
package.json
src/pages/hello.handlebars
src/partials/header.handlebars

index 32d0fd89af72cc92390161eed3a27cd4524f99de..391eefe464584810870f4dc20a2f8ff8e93c4a79 100644 (file)
@@ -8,7 +8,7 @@
 //   3. Cleaning files
 //   4. Stylesheets
 //   5. HTML
-//   6. Syntax Transformer
+//   6. Testing
 //   7. GO FORTH AND BUILD
 //   8. Serve/Watch Tasks
 
 // - - - - - - - - - - - - - - -
 
 var gulp       = require('gulp'),
-    watch      = require('gulp-watch'),
-    sass       = require('gulp-ruby-sass'),
-    inlineCss  = require('gulp-inline-css'),
+    // Gulp utilities
     rename     = require('gulp-rename'),
     connect    = require('gulp-connect'),
+    path       = require('path'),
+    map        = require('vinyl-map'),
+    fs         = require('fs'),
+    rimraf     = require('rimraf'),
+    // HTML stuff
     minifyHTML = require('gulp-minify-html'),
-    // extractMQ  = require('media-query-extractor'),
-    // inject     = require('gulp-inject'),
-    // inkyGulp   = require('gulp-inky'),
-    handlebars = require('gulp-compile-handlebars'),
-    omglob     = require('glob'),
-    gSync      = require('gulp-sync')(gulp),
-    runOrder   = require('run-sequence'),
-    rimraf     = require('rimraf');
-
-// Testin' and sheeeet
-
-var htmlParse = function(settings) {
-  var Handlebars = require('handlebars');
-  var map = require('vinyl-map');
-  var glob = require('glob');
-  var path = require('path');
-  var fs = require('fs');
-
-  var partials = glob.sync(settings.partials);
-  var layout   = fs.readFileSync(settings.layout);
-  
-  // Find partials and register with Handlebars
-  for (var i in partials) {
-    var file = fs.readFileSync(partials[i]);
-    var name = path.basename(partials[i], '.handlebars');
-    Handlebars.registerPartial(name, file.toString());
-  }
-
-  // Compile pages with the above helpers
-  return map(function(code, filename) {
-    var pageTemplate = Handlebars.compile(code.toString() + '\n');
-    var layoutTemplate = Handlebars.compile(layout.toString());
+    inkyGulp   = require('gulp-inky'),
+    Handlebars = require('handlebars'),
+    globLobLaw = require('glob'),
 
-    Handlebars.registerPartial('body', pageTemplate);
-    return layoutTemplate();
-  });
-}
+    // CSS stuff
+    extractMQ  = require('media-query-extractor'),
+    inject     = require('gulp-inject'),
+    sass       = require('gulp-ruby-sass'),
+    inlineCss  = require('gulp-inline-css');
 
-gulp.task('htmlparse', function() {
-  gulp.src('src/pages/*.handlebars')
-    .pipe(htmlParse({
-      layout: 'src/layouts/default.html',
-      partials: 'src/partials/**/*.handlebars'
-    }))
-    .pipe(rename({
-      ext: '.html'
-    }))
-    .pipe(gulp.dest('dist'));
-});
 
 
 
@@ -156,16 +120,6 @@ gulp.task('minify-html', function() {
     .pipe(connect.reload())
 });
 
-// Convert HTML to plain text, just in caseies
-gulp.task('html-plaintext', function() {
-  gulp.src(dirs.dist)
-    .pipe(html2txt())
-    .pipe(rename(function(path) {
-      path.basename += '-plaintext'
-    }))
-    .pipe(gulp.dest(dirs.dist));
-});
-
 // Task to copy HTML directly, without minifying
 gulp.task('copy-html', function() {
   return gulp.src(dirs.src + '/layouts/*.html')
@@ -173,68 +127,50 @@ gulp.task('copy-html', function() {
   .pipe(connect.reload())
 });
 
-// Inject handlebars partials
-gulp.task('compile-html', function() {
-  // silly gulp asynch. The previous task sometimes happens too fast, so it can't find
-  // the new temporary partials
-  var injectHtml = function() {
-    omglob(dirs.temp + '/*.html', function(er, files) {
-      for (var i = 0; i < files.length; i++) {
-        var filePath = files[i].replace(/\\/g, '/');
-        var fileName = filePath.substring(filePath.lastIndexOf('/')+1, filePath.lastIndexOf('.'));
-
-        gulp.src(dirs.src + '/layouts/default.html')
-          .pipe(inject(gulp.src(files[i]), {
-            starttag: '<!-- inject:page:{{ext}} -->',
-            transform: function (filePath, file) {
-            // return file contents as string 
-            return file.contents.toString('utf8')
-          }
-        }))
-        .pipe(rename({
-          basename: fileName
-        }))
-        .pipe(gulp.dest(dirs.temp)) 
-      }
-    })
-  };
-
-  omglob(dirs.src + '/pages/*.handlebars', function(er, files) {
-
-    for (var i = 0; i < files.length; i++) {
-      var filePath = files[i].replace(/\\/g, '/');
-      var fileName = filePath.substring(filePath.lastIndexOf('/')+1, filePath.lastIndexOf('.'));
-
-      var templateData = {},
-          options = {
-            batch : ['./src/partials']
-          };
-   
-      gulp.src(files[i])
-        .pipe(handlebars(templateData, options))
-        .pipe(rename(fileName + '.html'))
-        .pipe(gulp.dest(dirs.temp));
-    }
 
-  injectHtml();
-  })
+// Helper function to compile Handlebars partials
 
-});
+var htmlParse = function(settings) {
+  var partials = globLobLaw.sync(settings.partials);
+  var layout   = fs.readFileSync(settings.layout);
+  
+  // Find partials and register with Handlebars
+  for (var i in partials) {
+    var file = fs.readFileSync(partials[i]);
+    var name = path.basename(partials[i], '.handlebars');
+    Handlebars.registerPartial(name, file.toString());
+  }
 
+  // Compile pages with the above helpers
+  return map(function(code, filename) {
+    var pageTemplate = Handlebars.compile(code.toString() + '\n');
+    var layoutTemplate = Handlebars.compile(layout.toString());
 
-// 6. Syntax Transformer
-// - - - - - - - - - - - - - - -
+    Handlebars.registerPartial('body', pageTemplate);
+    return layoutTemplate();
+  });
+}
 
-// get the HTML from the body and run it through Inky parser
+// Compile Handlebars partials and
+// rename .handlebars to .html
+// run through Inky parser
 
-gulp.task('query', function() {
-  gulp.src(dirs.temp + '/*.html')
+gulp.task('inky-parse', function() {
+  gulp.src('src/pages/*.handlebars')
+    .pipe(htmlParse({
+      layout: 'src/layouts/default.html',
+      partials: 'src/partials/**/*.handlebars'
+    }))
+    .pipe(rename({
+      extname: '.html'
+    }))
     .pipe(inkyGulp())
     .pipe(gulp.dest(dirs.dist))
     .pipe(connect.reload());
+
 });
 
-// 7. Testing
+// 6. Testing
 // - - - - - - - - - - - - - - -
 
 // Eventual Litmus/Mailgun integration
@@ -242,16 +178,16 @@ gulp.task('query', function() {
 
 // });
 
-// 8. GO FORTH AND BUILD
+// 7. GO FORTH AND BUILD
 // - - - - - - - - - - - - - - -
 
 
 // Wipes build folder, then compiles SASS, then minifies and copies HTML
 gulp.task('build', function() {
-  runOrder('clean:dist', 'sass','query','minify-html');
+  runOrder('clean:dist', 'sass', 'inky-parse', 'minify-html');
 });
 
-// 9. Serve/Watch Tasks
+// 8. Serve/Watch/Default Tasks
 // - - - - - - - - - - - - - - -
 
 // Starts a server
@@ -267,14 +203,15 @@ gulp.task('serve', function() {
 // Watch all HTML files and SCSS files for changes
 // Live reloads on change
 gulp.task('watch', ['serve'], function() {
-  gulp.watch([dirs.src + '/*/*.*'], ['compile-html']);
+  gulp.watch([dirs.src + '/*/*.*'], ['inky-parse']);
   gulp.watch([dirs.styles], ['sass']);
 
 });
 
-
+// Minify the html, inline the css, inject media queries in the head
 gulp.task('deploy', ['minify-html', 'inline'], function() {
   gulp.start('inject-mq');
 });
+
 // Default task
 gulp.task('default', ['serve', 'watch']);
index 82b8301d9a5a977b0e91990544a67cfc8532be77..f19cbd8831f28b8496818867721a04e65b011a43 100644 (file)
@@ -3,7 +3,7 @@
   "version": "0.2.0",
   "description": "A framework for responsive emails made by ZURB",
   "devDependencies": {
-    "cheerio": "^0.18.0",
+    "fs": "0.0.2",
     "glob": "^4.4.0",
     "gulp": "^3.8.10",
     "gulp-compile-handlebars": "^0.4.4",
     "gulp-minify-html": "^0.1.8",
     "gulp-rename": "^1.2.0",
     "gulp-ruby-sass": "^0.7.1",
-    "gulp-sync": "^0.1.4",
-    "gulp-watch": "^4.1.1",
+    "handlebars": "^3.0.0",
+    "media-query-extractor": "^0.1.1",
+    "path": "^0.11.14",
     "rimraf": "^2.2.8",
-    "run-sequence": "^1.0.2"
+    "vinyl-map": "^1.0.1"
   }
 }
index 78aba0983f959bb832d772de6474f79239fc521d..a4991a392f2b3a38067f9778ef7c7ff05e7775cb 100644 (file)
@@ -2,7 +2,7 @@
 <container>
   <row>
     <columns large='12'>
-      <h1>Welcome, Daneel Olivan</h1>
+      <h1>Welcome, Com Truise</h1>
       <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et.</p>
       <img width="580" height="300" src="http://placehold.it/580x300">
     </columns>
@@ -10,7 +10,8 @@
   <row>
     <columns large='12'>
       <callout>
-        <p>Phasellus dictum sapien a neque luctus cursus. Pellentesque sem dolor, fringilla et pharetra vitae. <a href="#">Click it! »</a></p>
+        <p>Phasellus dictum sapien a neque luctus cursus. Pellentesque sem dolor, fringilla et pharetra vitae.</p>
+        <button><a href="#">Click it! »</a></button>
       </callout>
     </columns>
   </row>
 
       <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et. Lorem ipsum dolor sit amet.</p>
       <button><a href="#">Click Me!</a></button>
+      <br>
+      <callout>
+      <p>What a game</p>
+      <button><a href="#">wow</a></button>
+      </callout>
     </columns>
     <columns large='6'>
       <callout>
index 2ec4b26e9a74f3adb6bad97bcd848bf44fcd8897..d7cf77ab7b7bbd35f565c7348af5dfee4a298c49 100644 (file)
@@ -1,4 +1,4 @@
-<row class="header" style="background-color: red;">
+<row class="header">
   <columns large='12' small='12'>
     <subcolumns large='6' small='6'>
       <img src="http://placehold.it/200x50">