Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: environment option for spawn process #33

Merged
merged 4 commits into from
Aug 14, 2015
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}
})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yozzh could you fix the indentation above?
Then happy to merge it ;)
Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

```


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