Skip to content

Commit

Permalink
Merge pull request #33 from yozzh/master
Browse files Browse the repository at this point in the history
add: environment option for spawn process
  • Loading branch information
cognitom committed Aug 14, 2015
2 parents a27c225 + 86f0908 commit fb232f4
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 5 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -76,6 +77,24 @@ 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:

```javascript
slim({
prerry: true,
environment: {
cwd: process.cwd(),
env: {
'LC_CTYPE':'ru_RU.UTF-8'
}
}
})
```


Expand Down
9 changes: 8 additions & 1 deletion coffee/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = (options = {}) ->
# build a command with arguments
cmnd = 'slimrb'
args = []
spawn_options = {}

if options.bundler
cmnd = 'bundle'
Expand All @@ -29,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
Expand All @@ -42,6 +47,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()
Expand All @@ -55,7 +62,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
Expand Down
25 changes: 25 additions & 0 deletions test/expect/include.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>Slim Examples</title>
<meta content="template language" name="keywords" />
<meta content="John Doe" name="author" />
<script>
alert('Slim supports embedded javascript!')
</script>
</head>
<body>
<h1>
Markup examples
</h1>
<div id="content">
<p>
This example shows you how a basic Slim file looks like.
</p>
<blockquote>This is an included file with custom content</blockquote>
</div>
<div id="footer">
<Copyright>&copy; 2014</Copyright>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion test/expect/test-pretty.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Slim Examples</title>
<meta content="template language" name="keywords" />
<meta content="John Doe" name="author" />
<script type="text/javascript">
<script>
alert('Slim supports embedded javascript!')
</script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion test/expect/test-single-quotes-cdata.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html><html><head><title>Slim Examples</title><meta content='template language' name='keywords' /><meta content='John Doe' name='author' /><script type='text/javascript'>
<!DOCTYPE html><html><head><title>Slim Examples</title><meta content='template language' name='keywords' /><meta content='John Doe' name='author' /><script>
//<![CDATA[
alert('Slim supports embedded javascript!')
//]]>
Expand Down
2 changes: 1 addition & 1 deletion test/expect/test-single-quotes.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html><head><title>Slim Examples</title><meta content='template language' name='keywords' /><meta content='John Doe' name='author' /><script type='text/javascript'>alert('Slim supports embedded javascript!')</script></head><body><h1>Markup examples</h1><div id='content'><p>This example shows you how a basic Slim file looks like.</p></div><div id='footer'><Copyright>&copy; 2014</Copyright></div></body></html>
<!DOCTYPE html><html><head><title>Slim Examples</title><meta content='template language' name='keywords' /><meta content='John Doe' name='author' /><script>alert('Slim supports embedded javascript!')</script></head><body><h1>Markup examples</h1><div id='content'><p>This example shows you how a basic Slim file looks like.</p></div><div id='footer'><Copyright>&copy; 2014</Copyright></div></body></html>
2 changes: 1 addition & 1 deletion test/expect/test.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html><head><title>Slim Examples</title><meta content="template language" name="keywords" /><meta content="John Doe" name="author" /><script type="text/javascript">alert('Slim supports embedded javascript!')</script></head><body><h1>Markup examples</h1><div id="content"><p>This example shows you how a basic Slim file looks like.</p></div><div id="footer"><Copyright>&copy; 2014</Copyright></div></body></html>
<!DOCTYPE html><html><head><title>Slim Examples</title><meta content="template language" name="keywords" /><meta content="John Doe" name="author" /><script>alert('Slim supports embedded javascript!')</script></head><body><h1>Markup examples</h1><div id="content"><p>This example shows you how a basic Slim file looks like.</p></div><div id="footer"><Copyright>&copy; 2014</Copyright></div></body></html>
1 change: 1 addition & 0 deletions test/fixtures/include-file.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blockquote This is an included file with custom content
18 changes: 18 additions & 0 deletions test/fixtures/include.slim
Original file line number Diff line number Diff line change
@@ -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 &copy; 2014
17 changes: 17 additions & 0 deletions test/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fb232f4

Please sign in to comment.