From c8618225a5e6750586193043340bb4d84c00ad9f Mon Sep 17 00:00:00 2001 From: Dustin Silk Date: Tue, 21 Oct 2014 12:04:37 +0200 Subject: [PATCH] Choose the order patterns are added using the settings option: files: ['file-1.html', 'file-2.html'...] along with the src setting as the base destination --- tasks/patternprimer.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/tasks/patternprimer.js b/tasks/patternprimer.js index 750fa89..0389fb8 100644 --- a/tasks/patternprimer.js +++ b/tasks/patternprimer.js @@ -76,8 +76,6 @@ module.exports = function(grunt) { // generates the html output for the patterns var outputPatterns = function (patterns, cb) { getSourceFile(function generatePatterns(content) { - var scripts = content.match(/[\s\S]*?<\/script>/g); - content = content.replace(/[\s\S]*?<\/script>/g, ""); patterns.forEach(function (file) { content += '
'; content += '
'; @@ -87,7 +85,6 @@ module.exports = function(grunt) { content += ''; content += '
'; }); - content += scripts; content += ''; cb(content); }); @@ -131,7 +128,6 @@ module.exports = function(grunt) { files.push(content); } }); - // handle all the found pattern files handleFiles(patternFolder, files, cb); }); @@ -152,19 +148,35 @@ module.exports = function(grunt) { snapshot_port: Array.isArray(data.ports) && data.ports[1] ? data.ports[1] : Array.isArray(options.ports) && options.ports[1] ? options.ports[1] : 7040, wwwroot: data.wwwroot || options.wwwroot || 'public', src: data.src || options.src || 'public/patterns', + files: data.files || options.files || [], dest: data.dest || options.dest || 'docs', snapshot: (data.snapshot !== undefined ? data.snapshot : (options.snapshot !== undefined ? options.snapshot : false)), index: data.index || options.index || null, css: data.css || options.css || ['global.css'] }; + var primer; + // local pattern folder (there are the html snapshots) - var patternFolder = './' + settings.src; + if (settings.files.length > 0) { + var patterns = settings.files; + var patternsFolder = settings.src; - // our main function that starts the process - var primer = function (cb) { - readPatterns(patternFolder, cb); - }; + // our main function that starts the process + primer = function (cb) { + handleFiles(patternsFolder, patterns, cb); + }; + + } else { + var patternFolder = './' + settings.src; + + // our main function that starts the process + primer = function (cb) { + readPatterns(patternFolder, cb); + }; + } + + // middleware to spit out 404 (in case a non existing ressource is request) // or to process the `non static` requests