Skip to content

Commit

Permalink
Merge branch 'master' of github.com:mechanoid/wintersmith-stylus into…
Browse files Browse the repository at this point in the history
… jw/rebasing

Conflicts:
	package.json
	plugin.coffee
	test/mocha.opts
	test/nib.coffee
  • Loading branch information
jnwng committed Jun 28, 2015
2 parents 99503b3 + 9533b14 commit 52f9288
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"devDependencies": {
"mocha": "^1.21.3",
"should": "~4.0.4",
"wintersmith": "^2.1.0"
},
"scripts": {
Expand Down
35 changes: 26 additions & 9 deletions plugin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,35 @@ module.exports = (env, callback) ->
@_filepath.relative.replace /styl$/, 'css'

getView: ->
return (env, locals, contents, templates, callback) ->
return (env, locals, contents, templates, callback) =>

try
options = env.config.stylus or {}
options.filename = this.getFilename()
options.filename = @getFilename()
options.paths = [path.dirname(@_filepath.full)]
stylus(@_text, options)
.use(nib())
.render (err, css) ->
if err
callback err
else
callback null, new Buffer css

renderer = stylus(@_text, options)

# allowing to specify dependencies (including nib) via config file
#
# "stylus": {
# "dependencies": [
# "nib",
# "jeet"
# ]
# }
dependencies = options.dependencies

if dependencies?
for dependency in dependencies
currentLib = require(dependency)
renderer.use(currentLib()) if currentLib?

renderer.render (err, css) ->
if err
callback err
else
callback null, new Buffer css
catch error
callback error

Expand Down
2 changes: 2 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
--require should
--ui bdd
--compilers coffee:coffee-script/register
11 changes: 8 additions & 3 deletions test/nib.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ wsStylus = require './../'

# new wintersmith environment
env = wintersmith new Config, __dirname
env.config.stylus ?= {}
env.config.stylus.dependencies = ['nib']

describe "Nib integration", ->

Expand All @@ -20,11 +22,14 @@ describe "Nib integration", ->
tree['style.styl'].getView() env, null, null, null, (err, content)->

if content?
content.should.equal("""
content.toString().should.equal("""
body {
-webkit-box-shadow: 0 0 1px #000;
-moz-box-shadow: 0 0 1px #000;
box-shadow: 0 0 1px #000;
}""")
}
""")
else
throw err

do done

0 comments on commit 52f9288

Please sign in to comment.