From ab90cc18fa050b6bfa328c2ba8423fa1da436f40 Mon Sep 17 00:00:00 2001 From: Massimiliano Marcon Date: Thu, 13 Nov 2014 08:28:01 +0100 Subject: [PATCH 1/4] Adds code to add optional macro files --- lib/helpers.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/helpers.js b/lib/helpers.js index ef936fe3..0abdc9fa 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -94,6 +94,21 @@ var walk = function(dir, done) { } +var loadMacros = function(projectPath) { + var macros = {} + var macroDir = path.join(projectPath, "_macros/") + if (!fs.existsSync(macroDir)) { + return macros + } + fs.readdirSync(macroDir).forEach(function(file) { + if(!file.match(/.+\.js/)) { + return + } + macros[file.replace('.js', '')] = require(path.join(macroDir, file)); + }) + return macros +} + /** * @@ -131,14 +146,17 @@ exports.setup = function(projectPath, env){ var configPath = path.join(projectPath, "harp.json") var contents = fs.readFileSync(configPath).toString() var publicPath = path.join(projectPath, "public") + var macros = loadMacros(projectPath) }catch(e){ try{ var configPath = path.join(projectPath, "_harp.json") var contents = fs.readFileSync(configPath).toString() var publicPath = projectPath + var macros = loadMacros(projectPath) }catch(e){ var contents = "{}" var publicPath = projectPath + var macros = loadMacros(projectPath) } } @@ -168,6 +186,8 @@ exports.setup = function(projectPath, env){ // e.g. '$foo' -> process.env.foo cfg = envy(cfg) + cfg.globals.macros = macros + return { projectPath : projectPath, publicPath : publicPath, From 44e68807d2da6d5360d5c1d4ae67a61d90534121 Mon Sep 17 00:00:00 2001 From: Massimiliano Marcon Date: Thu, 13 Nov 2014 10:58:58 +0100 Subject: [PATCH 2/4] Unit tests for macros functionality --- test/apps/macros/_macros/test.js | 3 +++ test/apps/macros/index.ejs | 1 + test/helpers.js | 13 +++++++++++++ 3 files changed, 17 insertions(+) create mode 100644 test/apps/macros/_macros/test.js create mode 100644 test/apps/macros/index.ejs diff --git a/test/apps/macros/_macros/test.js b/test/apps/macros/_macros/test.js new file mode 100644 index 00000000..82383550 --- /dev/null +++ b/test/apps/macros/_macros/test.js @@ -0,0 +1,3 @@ +module.exports = function(someparam) { + return 'macro:' + someparam; +} \ No newline at end of file diff --git a/test/apps/macros/index.ejs b/test/apps/macros/index.ejs new file mode 100644 index 00000000..05746dba --- /dev/null +++ b/test/apps/macros/index.ejs @@ -0,0 +1 @@ +<%- macros.test('foo') %> \ No newline at end of file diff --git a/test/helpers.js b/test/helpers.js index 2a904927..1b09807e 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -102,6 +102,19 @@ describe("helpers", function(){ done() }) + it("should load macros when available", function(done){ + var cfg = helpers.setup(path.join(__dirname, "apps", "macros")) + cfg.should.have.property("config") + cfg.should.have.property("projectPath") + cfg.should.have.property("publicPath") + cfg.config.should.have.property("globals") + cfg.config.globals.should.have.property("macros") + cfg.config.globals.macros.should.have.property("test") + cfg.config.globals.macros.test.should.be.type("function") + should(cfg.config.globals.macros.test("foo")).equal("macro:foo") + done() + }) + }) describe("prime(outputPath)", function(){ From 1e61fdd01b4ca4d367a5bb0d056e1cb785dacf04 Mon Sep 17 00:00:00 2001 From: Massimiliano Marcon Date: Thu, 13 Nov 2014 11:48:20 +0100 Subject: [PATCH 3/4] Edited contributors list --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 32fe34a5..6cfeaa83 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ , "Remy Sharp " , "Zeke Sikelianos " , "Marc Knaup " + , "Massimiliano Marcon " ], "keywords": [ "static web server", From 79726098549edb1c90e60435810064001a0475f3 Mon Sep 17 00:00:00 2001 From: Massimiliano Marcon Date: Tue, 18 Nov 2014 16:28:03 +0100 Subject: [PATCH 4/4] Depend on terraform 0.9.1 that supports consistent minification --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6cfeaa83..ebf42df2 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "url": "https://github.com/sintaxi/harp.git" }, "dependencies": { - "terraform": "0.9.0", + "terraform": "git://github.com/sintaxi/terraform.git#release-v0.9.1", "commander": "2.0.0", "connect": "2.9.0", "fs-extra": "0.6.4",