From 3bfcddd2998421d57e53167c34bc4d51fb8a839d Mon Sep 17 00:00:00 2001 From: Michael Barlock Date: Thu, 23 Oct 2014 00:17:13 -0400 Subject: [PATCH 1/7] Add support for partials directory --- package.json | 5 +++-- src/handlebars.plugin.coffee | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index cd259a5..e2a1e62 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,8 @@ "url": "https://github.com/docpad/docpad-plugin-handlebars.git" }, "dependencies": { - "handlebars": "~1.3.0" + "handlebars": "~1.3.0", + "safefs": "~3.1.1" }, "devDependencies": { "coffee-script": "~1.7.1", @@ -66,4 +67,4 @@ "cakeConfiguration": { "COFFEE_SRC_PATH": "src" } -} \ No newline at end of file +} diff --git a/src/handlebars.plugin.coffee b/src/handlebars.plugin.coffee index 85a8026..b499820 100644 --- a/src/handlebars.plugin.coffee +++ b/src/handlebars.plugin.coffee @@ -1,3 +1,6 @@ +fs = require('safefs') +path = require('path') + module.exports = (BasePlugin) -> # Define Plugin @@ -66,3 +69,17 @@ module.exports = (BasePlugin) -> post += '})();' return pre + @handlebars.precompile(opts.content) + post + + generateBefore: (opts, next) -> + partialsDir = @config.partialsDir + handlebars = @handlebars + docpad = @docpad + if partialsDir + fs.readdir partialsDir, (err, files) -> + return docpad.error(err) if err + + for fileName in files + filePath = path.join(partialsDir, fileName) + partial = fs.readFileSync filePath, 'utf8' + handlebars.registerPartial(fileName.split('.')[0], partial) + next() From a57efe448af1b86d30243bff96e489c7e39f406e Mon Sep 17 00:00:00 2001 From: Michael Barlock Date: Thu, 23 Oct 2014 14:24:40 -0400 Subject: [PATCH 2/7] Add tests for partials dir --- HISTORY.md | 1 + README.md | 2 ++ test/docpad.cson | 3 ++- test/out-expected/handlebars-partials-dir.html | 5 +++++ test/src/documents/handlebars-partials-dir.html.hbs | 6 ++++++ test/src/layouts/partials/partial3.hbs | 1 + test/src/layouts/partials/partial4.hbs | 1 + 7 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/out-expected/handlebars-partials-dir.html create mode 100644 test/src/documents/handlebars-partials-dir.html.hbs create mode 100644 test/src/layouts/partials/partial3.hbs create mode 100644 test/src/layouts/partials/partial4.hbs diff --git a/HISTORY.md b/HISTORY.md index ea715a3..1e16e9a 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,7 @@ - v2.4.x - Updated dependencies - coffee-script 1.6.3 to 1.7.1 + - Added support for partials directory - v2.3.0 January 10, 2014 - Repackaged diff --git a/README.md b/README.md index 1e9f5c0..f688e71 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ plugins: getBlock: (type, additional...) -> additional.pop() # remove the hash object @getBlock(type).add(additional).toHTML() + partialsDir: './src/layouts/partials' partials: title: '

{{document.title}}

' goUp: 'Scroll up' @@ -139,6 +140,7 @@ These amazing people have contributed code to this project: - [Mike Moulton](https://github.com/mmoulton) — [view contributions](https://github.com/docpad/docpad-plugin-handlebars/commits?author=mmoulton) - [RobLoach](https://github.com/RobLoach) — [view contributions](https://github.com/docpad/docpad-plugin-handlebars/commits?author=RobLoach) - [Tobias Birmili](https://github.com/toabi) — [view contributions](https://github.com/docpad/docpad-plugin-handlebars/commits?author=toabi) +- [Michael Barlock](https://github.com/mbarlock) — [view contributions](https://github.com/docpad/docpad-plugin-handlebars/commits?author=mbarlock) [Become a contributor!](https://github.com/docpad/docpad-plugin-handlebars/blob/master/CONTRIBUTING.md#files) diff --git a/test/docpad.cson b/test/docpad.cson index 75c00e7..2a25f00 100644 --- a/test/docpad.cson +++ b/test/docpad.cson @@ -4,7 +4,8 @@ helpers: helperTest: () -> output = "Testing Helpers" + partialsDir: './test/src/layouts/partials' partials: partial1: '

{{document.example}}

' partial2: 'Scroll up' -} \ No newline at end of file +} diff --git a/test/out-expected/handlebars-partials-dir.html b/test/out-expected/handlebars-partials-dir.html new file mode 100644 index 0000000..1f4a653 --- /dev/null +++ b/test/out-expected/handlebars-partials-dir.html @@ -0,0 +1,5 @@ +

Handlebars Example

+ +

Handlebars Example

+ +Scroll up diff --git a/test/src/documents/handlebars-partials-dir.html.hbs b/test/src/documents/handlebars-partials-dir.html.hbs new file mode 100644 index 0000000..89aa45a --- /dev/null +++ b/test/src/documents/handlebars-partials-dir.html.hbs @@ -0,0 +1,6 @@ +--- +example: 'Handlebars Example' +--- +{{>partial3}} +{{>partial3}} +{{>partial4}} diff --git a/test/src/layouts/partials/partial3.hbs b/test/src/layouts/partials/partial3.hbs new file mode 100644 index 0000000..a1c16a0 --- /dev/null +++ b/test/src/layouts/partials/partial3.hbs @@ -0,0 +1 @@ +

{{document.example}}

diff --git a/test/src/layouts/partials/partial4.hbs b/test/src/layouts/partials/partial4.hbs new file mode 100644 index 0000000..bab2368 --- /dev/null +++ b/test/src/layouts/partials/partial4.hbs @@ -0,0 +1 @@ +Scroll up From 3b4703d1ed460fc2d866e26b57a3326166c8742d Mon Sep 17 00:00:00 2001 From: Michael Barlock Date: Wed, 5 Nov 2014 15:48:48 -0500 Subject: [PATCH 3/7] Update handlebars version --- package.json | 2 +- test/out-expected/handlebars-partials-dir.html | 2 -- test/out-expected/handlebars-partials.html | 4 +--- test/out-expected/handlebars.inlinejs | 15 +++++---------- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index e2a1e62..06be922 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "url": "https://github.com/docpad/docpad-plugin-handlebars.git" }, "dependencies": { - "handlebars": "~1.3.0", + "handlebars": "~2.0.0", "safefs": "~3.1.1" }, "devDependencies": { diff --git a/test/out-expected/handlebars-partials-dir.html b/test/out-expected/handlebars-partials-dir.html index 1f4a653..11c051a 100644 --- a/test/out-expected/handlebars-partials-dir.html +++ b/test/out-expected/handlebars-partials-dir.html @@ -1,5 +1,3 @@

Handlebars Example

-

Handlebars Example

- Scroll up diff --git a/test/out-expected/handlebars-partials.html b/test/out-expected/handlebars-partials.html index a60a443..ce7897e 100644 --- a/test/out-expected/handlebars-partials.html +++ b/test/out-expected/handlebars-partials.html @@ -1,3 +1 @@ -

Handlebars Example

-

Handlebars Example

-Scroll up \ No newline at end of file +

Handlebars Example

Handlebars Example

Scroll up \ No newline at end of file diff --git a/test/out-expected/handlebars.inlinejs b/test/out-expected/handlebars.inlinejs index e525761..cbca626 100644 --- a/test/out-expected/handlebars.inlinejs +++ b/test/out-expected/handlebars.inlinejs @@ -1,14 +1,9 @@ (function() { var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {}; -templates['handlebars'] = template(function (Handlebars,depth0,helpers,partials,data) { - this.compilerInfo = [4,'>= 1.0.0']; -helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; - var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression; - - - buffer += "

" - + escapeExpression(((stack1 = ((stack1 = (depth0 && depth0.document)),stack1 == null || stack1 === false ? stack1 : stack1.example)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1)) +templates['handlebars'] = template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { + var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression; + return "

" + + escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.document : depth0)) != null ? stack1.example : stack1), depth0)) + "

"; - return buffer; - }); +},"useData":true}); })(); \ No newline at end of file From 9d179f04d050115dca10e6ad2af20e7b5676cade Mon Sep 17 00:00:00 2001 From: Michael Barlock Date: Wed, 12 Nov 2014 10:09:31 -0500 Subject: [PATCH 4/7] Updated Bevy/Base files --- .gitignore | 4 ++ .jshintrc | 63 ++++++++++++++++++++++++++ .npmignore | 9 +++- .travis.yml | 9 +++- CONTRIBUTING.md | 8 ++-- Cakefile | 48 +++++++++++--------- README.md | 1 - coffeelint.json | 114 ++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 9 files changed, 228 insertions(+), 30 deletions(-) create mode 100644 .jshintrc create mode 100644 coffeelint.json diff --git a/.gitignore b/.gitignore index 5d8a5a2..c408720 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,10 @@ bower_components/ node_modules/ out/ +# Private Files +.env + + # ===================================== # CUSTOM MODIFICATIONS diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..643c399 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,63 @@ +{ + // enforcing options + "bitwise": true, + "camelcase": true, + "curly": false, // we like one liners + "eqeqeq": true, + "es3": true, + "forin": true, + "freeze": true, + "immed": true, + "indent": 1, // we use tabs + "latedef": true, + "newcap": true, + "noarg": true, + "noempty": true, + "nonbsp": true, + "nonew": true, + "plusplus": false, // we are good at js + "quotmark": false, // we like flexibility + "undef": true, + "unused": true, + "strict": true, + "trailing": true, + "maxparams": false, // no + "maxdepth": false, // no + "maxstatements": false, // no + "maxcomplexity": false, // no + "maxlen": false, // no + + // relaxing options + "asi": true, // we use asi + "boss": true, // we understand assignments + "debug": false, + "eqnull": true, // we know how to do null/undefined checks + "esnext": false, + "evil": false, + "expr": false, + "funcscope": false, + "gcl": true, + "globalstrict": false, + "iterator": false, + "lastsemic": false, + "laxbreak": false, + "laxcomma": false, + "loopfunc": false, + "moz": false, + "multistr": false, + "notypeof": false, + "proto": false, + "scripturl": false, + "smarttabs": false, // default; spaces should only be mixed with tabs after words + "shadow": false, + "sub": false, + "supernew": false, + "noyield": false, + + // environments + "browser": true, + "node": true, + + // legacy + "onevar": false +} diff --git a/.npmignore b/.npmignore index 91caedf..04f814f 100644 --- a/.npmignore +++ b/.npmignore @@ -1,4 +1,4 @@ -# v1.3.10 December 10, 2013 +# v1.3.23 October 11, 2014 # https://github.com/bevry/base # Temp Files @@ -11,7 +11,14 @@ components/ bower_components/ node_modules/ +# Private Files +.env + # Development Files +.editorconfig +.eslintrc +.jshintrc +coffeelint.json .travis* Cakefile Makefile diff --git a/.travis.yml b/.travis.yml index 54f953e..9eab201 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,12 @@ -# v1.3.14 February 6, 2014 +# v1.3.23 October 11, 2014 # https://github.com/bevry/base language: node_js -install: "npm install; ./node_modules/.bin/cake install" +# ensure npm@1 is the latest 0.8 compatible version (needed to ensure modules are installed correctly) +# ensure coffee-script is installed (needed for cake commands) +# ensure dev dependencies are installed (handled via npm install) +# ensure test dependencies are installed (handled via cake install) +install: "npm install -g npm@1 && npm install coffee-script && npm install && ./node_modules/.bin/cake install" +# ensure our application is compiled before we run our tests before_script: "./node_modules/.bin/cake compile" script: "npm test" node_js: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6dc12e4..011ee84 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,5 @@ @@ -9,9 +9,9 @@ https://github.com/bevry/base ## Resources -- [Coding Standards](http://bevry.me/bevry/coding-standards) -- [Documentation Guidelines](http://bevry.me/bevry/documentation-guidelines) -- [Support Guidelines](http://bevry.me/bevry/support-guidelines) +- [Coding Standards](http://learn.bevry.me/community/coding-standards) +- [Documentation Guidelines](http://learn.bevry.me/community/documentation-guidelines) +- [Support Guidelines](http://learn.bevry.me/community/support-guidelines) ## Development diff --git a/Cakefile b/Cakefile index 07c73ce..8a076ef 100644 --- a/Cakefile +++ b/Cakefile @@ -1,4 +1,4 @@ -# v1.3.15 May 16, 2014 +# v1.3.20 June 16, 2014 # https://github.com/bevry/base @@ -18,27 +18,29 @@ NPM = (if WINDOWS then process.execPath.replace('node.exe', 'npm.cm EXT = (if WINDOWS then '.cmd' else '') GIT = "git" -APP_PATH = process.cwd() +APP_PATH = process.cwd() PACKAGE_PATH = pathUtil.join(APP_PATH, "package.json") PACKAGE_DATA = require(PACKAGE_PATH) MODULES_PATH = pathUtil.join(APP_PATH, "node_modules") DOCPAD_PATH = pathUtil.join(MODULES_PATH, "docpad") -BIN_PATH = pathUtil.join(MODULES_PATH, ".bin") -CAKE = pathUtil.join(BIN_PATH, "cake" + EXT) -COFFEE = pathUtil.join(BIN_PATH, "coffee" + EXT) -PROJECTZ = pathUtil.join(BIN_PATH, "projectz" + EXT) -DOCCO = pathUtil.join(BIN_PATH, "docco" + EXT) -DOCPAD = pathUtil.join(BIN_PATH, "docpad" + EXT) +CAKE = pathUtil.join(MODULES_PATH, "coffee-script/bin/cake") +COFFEE = pathUtil.join(MODULES_PATH, "coffee-script/bin/coffee") +PROJECTZ = pathUtil.join(MODULES_PATH, "projectz/bin/projectz") +DOCCO = pathUtil.join(MODULES_PATH, "docco/bin/docco") +DOCPAD = pathUtil.join(MODULES_PATH, "docpad/bin/docpad") +BISCOTTO = pathUtil.join(MODULES_PATH, "biscotto/bin/biscotto") config = {} -config.TEST_PATH = "test" -config.DOCCO_SRC_PATH = null -config.DOCCO_OUT_PATH = "docs" -config.COFFEE_SRC_PATH = null -config.COFFEE_OUT_PATH = "out" -config.DOCPAD_SRC_PATH = null -config.DOCPAD_OUT_PATH = "out" +config.TEST_PATH = "test" +config.DOCCO_SRC_PATH = null +config.DOCCO_OUT_PATH = "docs" +config.BISCOTTO_SRC_PATH = null +config.BISCOTTO_OUT_PATH = "docs" +config.COFFEE_SRC_PATH = null +config.COFFEE_OUT_PATH = "out" +config.DOCPAD_SRC_PATH = null +config.DOCPAD_OUT_PATH = "out" for own key,value of (PACKAGE_DATA.cakeConfiguration or {}) config[key] = value @@ -133,11 +135,11 @@ actions = step2 = -> return step3() if !config.COFFEE_SRC_PATH or !fsUtil.existsSync(COFFEE) console.log('coffee compile') - spawn(COFFEE, ['-co', config.COFFEE_OUT_PATH, config.COFFEE_SRC_PATH], {stdio:'inherit', cwd:APP_PATH}).on('close', safe next, step3) + spawn(NODE, [COFFEE, '-co', config.COFFEE_OUT_PATH, config.COFFEE_SRC_PATH], {stdio:'inherit', cwd:APP_PATH}).on('close', safe next, step3) step3 = -> return step4() if !config.DOCPAD_SRC_PATH or !fsUtil.existsSync(DOCPAD) console.log('docpad generate') - spawn(DOCPAD, ['generate'], {stdio:'inherit', cwd:APP_PATH}).on('close', safe next, step4) + spawn(NODE, [DOCPAD, 'generate'], {stdio:'inherit', cwd:APP_PATH}).on('close', safe next, step4) step4 = next # Start @@ -154,12 +156,12 @@ actions = step2 = -> return step3() if !config.COFFEE_SRC_PATH or !fsUtil.existsSync(COFFEE) console.log('coffee watch') - spawn(COFFEE, ['-wco', config.COFFEE_OUT_PATH, config.COFFEE_SRC_PATH], {stdio:'inherit', cwd:APP_PATH}).on('close', safe) # background + spawn(NODE, [COFFEE, '-wco', config.COFFEE_OUT_PATH, config.COFFEE_SRC_PATH], {stdio:'inherit', cwd:APP_PATH}).on('close', safe) # background step3() # continue while coffee runs in background step3 = -> return step4() if !config.DOCPAD_SRC_PATH or !fsUtil.existsSync(DOCPAD) console.log('docpad run') - spawn(DOCPAD, ['run'], {stdio:'inherit', cwd:APP_PATH}).on('close', safe) # background + spawn(NODE, [DOCPAD, 'run'], {stdio:'inherit', cwd:APP_PATH}).on('close', safe) # background step4() # continue while docpad runs in background step4 = next @@ -193,12 +195,16 @@ actions = step2 = -> return step3() if !fsUtil.existsSync(PROJECTZ) console.log('projectz compile') - spawn(PROJECTZ, ['compile'], {stdio:'inherit', cwd:APP_PATH}).on('close', safe next, step3) + spawn(NODE, [PROJECTZ, 'compile'], {stdio:'inherit', cwd:APP_PATH}).on('close', safe next, step3) step3 = -> return step4() if !config.DOCCO_SRC_PATH or !fsUtil.existsSync(DOCCO) console.log('docco compile') - exec("#{DOCCO} -o #{config.DOCCO_OUT_PATH} #{config.DOCCO_SRC_PATH}", {stdio:'inherit', cwd:APP_PATH}, safe next, step4) + exec("#{NODE} #{DOCCO} -o #{config.DOCCO_OUT_PATH} #{config.DOCCO_SRC_PATH}", {stdio:'inherit', cwd:APP_PATH}, safe next, step4) step4 = -> + return step5() if !config.BISCOTTO_SRC_PATH or !fsUtil.existsSync(BISCOTTO) + console.log('biscotto compile') + exec("""#{BISCOTTO} --name #{PACKAGE_DATA.title or PACKAGE_DATA.name} --title "#{PACKAGE_DATA.title or PACKAGE_DATA.name} API Documentation" --readme README.md --output-dir #{config.BISCOTTO_OUT_PATH} #{config.BISCOTTO_SRC_PATH} - LICENSE.md HISTORY.md""", {stdio:'inherit', cwd:APP_PATH}, safe next, step5) + step5 = -> console.log('cake test') actions.test(opts, safe next, step5) step5 = next diff --git a/README.md b/README.md index f688e71..6d4ff2b 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,6 @@ These amazing people have contributed code to this project: - [Mike Moulton](https://github.com/mmoulton) — [view contributions](https://github.com/docpad/docpad-plugin-handlebars/commits?author=mmoulton) - [RobLoach](https://github.com/RobLoach) — [view contributions](https://github.com/docpad/docpad-plugin-handlebars/commits?author=RobLoach) - [Tobias Birmili](https://github.com/toabi) — [view contributions](https://github.com/docpad/docpad-plugin-handlebars/commits?author=toabi) -- [Michael Barlock](https://github.com/mbarlock) — [view contributions](https://github.com/docpad/docpad-plugin-handlebars/commits?author=mbarlock) [Become a contributor!](https://github.com/docpad/docpad-plugin-handlebars/blob/master/CONTRIBUTING.md#files) diff --git a/coffeelint.json b/coffeelint.json new file mode 100644 index 0000000..d07f481 --- /dev/null +++ b/coffeelint.json @@ -0,0 +1,114 @@ +{ + "coffeescript_error": { + "level": "error" + }, + "arrow_spacing": { + "name": "arrow_spacing", + "level": "error" + }, + "no_tabs": { + "name": "no_tabs", + "level": "ignore" + }, + "no_trailing_whitespace": { + "name": "no_trailing_whitespace", + "level": "error", + "allowed_in_comments": false, + "allowed_in_empty_lines": true + }, + "max_line_length": { + "name": "max_line_length", + "value": 80, + "level": "ignore", + "limitComments": true + }, + "line_endings": { + "name": "line_endings", + "level": "error", + "value": "unix" + }, + "no_trailing_semicolons": { + "name": "no_trailing_semicolons", + "level": "error" + }, + "indentation": { + "name": "indentation", + "value": 1, + "level": "error" + }, + "camel_case_classes": { + "name": "camel_case_classes", + "level": "error" + }, + "colon_assignment_spacing": { + "name": "colon_assignment_spacing", + "level": "ignore", + "spacing": { + "left": 0, + "right": 0 + } + }, + "no_implicit_braces": { + "name": "no_implicit_braces", + "level": "ignore", + "strict": true + }, + "no_plusplus": { + "name": "no_plusplus", + "level": "ignore" + }, + "no_throwing_strings": { + "name": "no_throwing_strings", + "level": "error" + }, + "no_backticks": { + "name": "no_backticks", + "level": "ignore" + }, + "no_implicit_parens": { + "name": "no_implicit_parens", + "level": "ignore" + }, + "no_empty_param_list": { + "name": "no_empty_param_list", + "level": "error" + }, + "no_stand_alone_at": { + "name": "no_stand_alone_at", + "level": "ignore" + }, + "space_operators": { + "name": "space_operators", + "level": "ignore" + }, + "duplicate_key": { + "name": "duplicate_key", + "level": "error" + }, + "empty_constructor_needs_parens": { + "name": "empty_constructor_needs_parens", + "level": "ignore" + }, + "cyclomatic_complexity": { + "name": "cyclomatic_complexity", + "value": 10, + "level": "ignore" + }, + "newlines_after_classes": { + "name": "newlines_after_classes", + "value": 3, + "level": "ignore" + }, + "no_unnecessary_fat_arrows": { + "name": "no_unnecessary_fat_arrows", + "level": "warn" + }, + "missing_fat_arrows": { + "name": "missing_fat_arrows", + "level": "ignore" + }, + "non_empty_constructor_needs_parens": { + "name": "non_empty_constructor_needs_parens", + "level": "ignore" + } +} diff --git a/package.json b/package.json index 06be922..7140c71 100644 --- a/package.json +++ b/package.json @@ -67,4 +67,4 @@ "cakeConfiguration": { "COFFEE_SRC_PATH": "src" } -} +} \ No newline at end of file From e2cf91b404b7e59fa787c5d96090827ebcdf71fe Mon Sep 17 00:00:00 2001 From: Michael Barlock Date: Mon, 1 Dec 2014 15:30:47 -0500 Subject: [PATCH 5/7] Added the ability to create partial dir namespaces --- package.json | 6 ++++-- src/handlebars.plugin.coffee | 12 +++++++----- test/out-expected/handlebars-partials-namespace.html | 3 +++ .../documents/handlebars-partials-namespace.html.hbs | 6 ++++++ test/src/layouts/partials/namespace/partial5.hbs | 1 + 5 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 test/out-expected/handlebars-partials-namespace.html create mode 100644 test/src/documents/handlebars-partials-namespace.html.hbs create mode 100644 test/src/layouts/partials/namespace/partial5.hbs diff --git a/package.json b/package.json index 7140c71..3e428f7 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "Gilles Bouthenot (https://github.com/gbouthenot)", "Mike Moulton (https://github.com/mmoulton)", "RobLoach (https://github.com/RobLoach)", - "Tobias Birmili (https://github.com/toabi)" + "Tobias Birmili (https://github.com/toabi)", + "Michael Barlock (https://github.com/mbarlock)" ], "bugs": { "url": "https://github.com/docpad/docpad-plugin-handlebars/issues" @@ -33,6 +34,7 @@ }, "dependencies": { "handlebars": "~2.0.0", + "wrench": "~1.5.8", "safefs": "~3.1.1" }, "devDependencies": { @@ -67,4 +69,4 @@ "cakeConfiguration": { "COFFEE_SRC_PATH": "src" } -} \ No newline at end of file +} diff --git a/src/handlebars.plugin.coffee b/src/handlebars.plugin.coffee index b499820..93b3676 100644 --- a/src/handlebars.plugin.coffee +++ b/src/handlebars.plugin.coffee @@ -1,4 +1,5 @@ fs = require('safefs') +wrench = require('wrench') path = require('path') module.exports = (BasePlugin) -> @@ -75,11 +76,12 @@ module.exports = (BasePlugin) -> handlebars = @handlebars docpad = @docpad if partialsDir - fs.readdir partialsDir, (err, files) -> + wrench.readdirRecursive partialsDir, (err, files) -> return docpad.error(err) if err - for fileName in files - filePath = path.join(partialsDir, fileName) - partial = fs.readFileSync filePath, 'utf8' - handlebars.registerPartial(fileName.split('.')[0], partial) + + for fileName in files when fileName.match /(hb|hbs|handlebars)$/ + filePath = path.join(partialsDir, fileName) + partial = fs.readFileSync filePath, 'utf8' + handlebars.registerPartial(fileName.split('.')[0], partial) next() diff --git a/test/out-expected/handlebars-partials-namespace.html b/test/out-expected/handlebars-partials-namespace.html new file mode 100644 index 0000000..7771bd3 --- /dev/null +++ b/test/out-expected/handlebars-partials-namespace.html @@ -0,0 +1,3 @@ +

Handlebars Example

+

Handlebars Example

+

Namespaced!

diff --git a/test/src/documents/handlebars-partials-namespace.html.hbs b/test/src/documents/handlebars-partials-namespace.html.hbs new file mode 100644 index 0000000..505eb18 --- /dev/null +++ b/test/src/documents/handlebars-partials-namespace.html.hbs @@ -0,0 +1,6 @@ +--- +example: 'Handlebars Example' +--- +{{>partial3}} +{{>partial3}} +{{>namespace/partial5}} diff --git a/test/src/layouts/partials/namespace/partial5.hbs b/test/src/layouts/partials/namespace/partial5.hbs new file mode 100644 index 0000000..ef643a1 --- /dev/null +++ b/test/src/layouts/partials/namespace/partial5.hbs @@ -0,0 +1 @@ +

Namespaced!

From 4fa45512764125328a1daf81289581dd3815ac99 Mon Sep 17 00:00:00 2001 From: Michael Barlock Date: Mon, 1 Dec 2014 15:34:40 -0500 Subject: [PATCH 6/7] fixed spacing --- src/handlebars.plugin.coffee | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/handlebars.plugin.coffee b/src/handlebars.plugin.coffee index 93b3676..7eab9d8 100644 --- a/src/handlebars.plugin.coffee +++ b/src/handlebars.plugin.coffee @@ -79,9 +79,8 @@ module.exports = (BasePlugin) -> wrench.readdirRecursive partialsDir, (err, files) -> return docpad.error(err) if err - for fileName in files when fileName.match /(hb|hbs|handlebars)$/ - filePath = path.join(partialsDir, fileName) - partial = fs.readFileSync filePath, 'utf8' - handlebars.registerPartial(fileName.split('.')[0], partial) + filePath = path.join(partialsDir, fileName) + partial = fs.readFileSync filePath, 'utf8' + handlebars.registerPartial(fileName.split('.')[0], partial) next() From 773c1e156942c8260ed5be34c7d690919af48e67 Mon Sep 17 00:00:00 2001 From: Michael Barlock Date: Fri, 5 Dec 2014 10:10:38 -0500 Subject: [PATCH 7/7] Support Windows for partial namespaces --- src/handlebars.plugin.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/handlebars.plugin.coffee b/src/handlebars.plugin.coffee index 7eab9d8..3d7053e 100644 --- a/src/handlebars.plugin.coffee +++ b/src/handlebars.plugin.coffee @@ -52,7 +52,7 @@ module.exports = (BasePlugin) -> argv.amdPath ?= "" pre = post = ""; - + # slug for {src}/tpl/a/abc/test.js.handlebars is "tpl-a-abc-test" templateName = opts.file.attributes.slug; if (argv.wrapper is "amd") @@ -80,7 +80,7 @@ module.exports = (BasePlugin) -> return docpad.error(err) if err for fileName in files when fileName.match /(hb|hbs|handlebars)$/ - filePath = path.join(partialsDir, fileName) + filePath = path.join(partialsDir, fileName).replace(path.sep, '/') partial = fs.readFileSync filePath, 'utf8' handlebars.registerPartial(fileName.split('.')[0], partial) next()