From 25f65e9eb4f3d3aa65eb10cfb408ad6d9da83073 Mon Sep 17 00:00:00 2001 From: Danila Smirnov Date: Mon, 20 Jul 2015 10:40:34 +0300 Subject: [PATCH 1/4] add: environment option for spawn process readme: about environment option --- README.md | 13 +++++++++++++ coffee/index.coffee | 5 ++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0a915c5..79c666a 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,19 @@ slim({ options: ['attr_quote="\'"', 'js_wrapper=:cdata'] }) ``` +You can also add any other console options for custom slimrb run options. For example: + +```javascript +slim({ + prerry: true, + environment: { + cwd: process.cwd(), + env: { + "LC_CTYPE":"ru_RU.UTF-8" + } + } +}) +``` ## Some Scenarios diff --git a/coffee/index.coffee b/coffee/index.coffee index 6b98e9d..c31246d 100644 --- a/coffee/index.coffee +++ b/coffee/index.coffee @@ -10,6 +10,7 @@ module.exports = (options = {}) -> # build a command with arguments cmnd = 'slimrb' args = [] + spawn_options = {} if options.bundler cmnd = 'bundle' @@ -42,6 +43,8 @@ module.exports = (options = {}) -> args.push '-o' args.push options.options + spawn_options.env = options.environment if options.environment + through.obj (file, encoding, callback) -> if file.isNull() @@ -55,7 +58,7 @@ module.exports = (options = {}) -> ext = if options.erb then '.erb' else '.html' file.path = gutil.replaceExtension file.path, ext - program = spawn cmnd, args + program = spawn cmnd, args, spawn_options # create buffer b = new Buffer 0 From 5c5eabb88e2db38b003981df01ce546e4ee9607f Mon Sep 17 00:00:00 2001 From: Danila Smirnov Date: Mon, 20 Jul 2015 11:11:25 +0300 Subject: [PATCH 2/4] test: fix expect files for correct tests --- test/expect/test-pretty.html | 2 +- test/expect/test-single-quotes-cdata.html | 2 +- test/expect/test-single-quotes.html | 2 +- test/expect/test.html | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/expect/test-pretty.html b/test/expect/test-pretty.html index a5b98e5..fabe43d 100644 --- a/test/expect/test-pretty.html +++ b/test/expect/test-pretty.html @@ -4,7 +4,7 @@ Slim Examples - diff --git a/test/expect/test-single-quotes-cdata.html b/test/expect/test-single-quotes-cdata.html index 8f183ea..25d9a9f 100644 --- a/test/expect/test-single-quotes-cdata.html +++ b/test/expect/test-single-quotes-cdata.html @@ -1,4 +1,4 @@ -Slim Examples

Markup examples

This example shows you how a basic Slim file looks like.

+Slim Examples

Markup examples

This example shows you how a basic Slim file looks like.

diff --git a/test/expect/test.html b/test/expect/test.html index 8cd92d4..609fd5c 100644 --- a/test/expect/test.html +++ b/test/expect/test.html @@ -1 +1 @@ -Slim Examples

Markup examples

This example shows you how a basic Slim file looks like.

+Slim Examples

Markup examples

This example shows you how a basic Slim file looks like.

From d8d94ac7358b641b634a12385dfcd8757ff9aec0 Mon Sep 17 00:00:00 2001 From: Danila Smirnov Date: Mon, 20 Jul 2015 11:24:02 +0300 Subject: [PATCH 3/4] add: native slim include plugin support feature --- README.md | 6 ++++++ coffee/index.coffee | 4 ++++ test/expect/include.html | 25 +++++++++++++++++++++++++ test/fixtures/include-file.slim | 1 + test/fixtures/include.slim | 18 ++++++++++++++++++ test/main.coffee | 17 +++++++++++++++++ 6 files changed, 71 insertions(+) create mode 100644 test/expect/include.html create mode 100644 test/fixtures/include-file.slim create mode 100644 test/fixtures/include.slim diff --git a/README.md b/README.md index 79c666a..6c100a3 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ The options are the same as what's supported by `slimrb`. - `rails: true` - `translator: true` - `logicLess: true` +- `include: true` Set `bundler: true` to invoke `slimrb` via bundler. @@ -76,6 +77,11 @@ slim({ pretty: true, options: ['attr_quote="\'"', 'js_wrapper=:cdata'] }) + +slim({ + include: true, + options: 'include_dirs="[\'test/fixtures\']"' +}) ``` You can also add any other console options for custom slimrb run options. For example: diff --git a/coffee/index.coffee b/coffee/index.coffee index c31246d..9116ab2 100644 --- a/coffee/index.coffee +++ b/coffee/index.coffee @@ -30,6 +30,10 @@ module.exports = (options = {}) -> args.push '-r' args.push 'slim/logic_less' + if options.include + args.push '-r' + args.push 'slim/include' + if options.data args.push '--locals' args.push JSON.stringify options.data diff --git a/test/expect/include.html b/test/expect/include.html new file mode 100644 index 0000000..5a7181a --- /dev/null +++ b/test/expect/include.html @@ -0,0 +1,25 @@ + + + + Slim Examples + + + + + +

+ Markup examples +

+
+

+ This example shows you how a basic Slim file looks like. +

+
This is an included file with custom content
+
+ + + diff --git a/test/fixtures/include-file.slim b/test/fixtures/include-file.slim new file mode 100644 index 0000000..c04ed9f --- /dev/null +++ b/test/fixtures/include-file.slim @@ -0,0 +1 @@ +blockquote This is an included file with custom content \ No newline at end of file diff --git a/test/fixtures/include.slim b/test/fixtures/include.slim new file mode 100644 index 0000000..3bc9c30 --- /dev/null +++ b/test/fixtures/include.slim @@ -0,0 +1,18 @@ +doctype html +html + head + title Slim Examples + meta name="keywords" content="template language" + meta name="author" content="John Doe" + javascript: + alert('Slim supports embedded javascript!') + + body + h1 Markup examples + + #content + p This example shows you how a basic Slim file looks like. + include include-file + + div id="footer" + Copyright © 2014 \ No newline at end of file diff --git a/test/main.coffee b/test/main.coffee index f3d503e..493a1f9 100644 --- a/test/main.coffee +++ b/test/main.coffee @@ -102,3 +102,20 @@ describe 'gulp-slim', () -> String(htmlFile.contents).should.equal fs.readFileSync path.join(__dirname, 'expect/data.html'), 'utf8' done() stream.write slimFile + + it 'should include additional file with include plugin', (done) -> + slimFile = createFile 'include.slim' + stream = slim { + pretty:true + include: true + options: ["include_dirs=['test/fixtures']"] + } + stream.on 'data', (htmlFile) -> + should.exist htmlFile + should.exist htmlFile.path + should.exist htmlFile.relative + should.exist htmlFile.contents + htmlFile.path.should.equal path.join __dirname, 'fixtures', 'include.html' + String(htmlFile.contents).should.equal fs.readFileSync path.join(__dirname, 'expect/include.html'), 'utf8' + done() + stream.write slimFile From 86f09085ef4dfd0237f3fec7d35b0adbc3ef2cd5 Mon Sep 17 00:00:00 2001 From: Danila Smirnov Date: Wed, 22 Jul 2015 11:57:46 +0300 Subject: [PATCH 4/4] fix: readme.md example indentation --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6c100a3..9a33394 100644 --- a/README.md +++ b/README.md @@ -87,12 +87,12 @@ You can also add any other console options for custom slimrb run options. For ex ```javascript slim({ - prerry: true, - environment: { - cwd: process.cwd(), - env: { - "LC_CTYPE":"ru_RU.UTF-8" - } + prerry: true, + environment: { + cwd: process.cwd(), + env: { + 'LC_CTYPE':'ru_RU.UTF-8' + } } }) ```