Skip to content

Commit

Permalink
Merge pull request #4 from lvivier/wintersmith-2.0
Browse files Browse the repository at this point in the history
update for wintersmith 2
  • Loading branch information
jnwng committed Jun 9, 2013
2 parents bb2618b + b1b4f8c commit 4e2acac
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "wintersmith-stylus",
"version": "0.1.1",
"version": "0.3.0",
"author": "Jon Wong <[email protected]>",
"description": "stylus plugin for wintersmith",
"keywords": ["wintersmith-plugin"],
"license": "MIT",
"dependencies": {
"stylus": ">=0.19.x",
Expand All @@ -12,7 +13,7 @@
},

"devDependencies": {
"wintersmith": ">=1.0.0",
"wintersmith": ">=2.0.0",
"mocha": ">=1.0.0"
}
}
43 changes: 22 additions & 21 deletions plugin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,36 @@ path = require 'path'
async = require 'async'
fs = require 'fs'

module.exports = (wintersmith, callback) ->
module.exports = (env, callback) ->

class StylusPlugin extends wintersmith.ContentPlugin
class StylusPlugin extends env.ContentPlugin

constructor: (@_filename, @_base, @_text) ->
constructor: (@_filepath, @_text) ->

getFilename: ->
@_filename.replace /styl$/, 'css'
@_filepath.relative.replace /styl$/, 'css'

render: (locals, contents, templates, callback) ->
try
stylus(@_text)
.set('filename', this.getFilename())
.set('paths', [path.dirname(path.join(@_base, @_filename))])
.use(nib())
.render (err, css) ->
if err
callback err
else
callback null, new Buffer css
catch error
callback error
getView: ->
return (env, locals, contents, templates, callback) ->
try
stylus(@_text)
.set('filename', this.getFilename())
.set('paths', [path.dirname(@_filepath.full)])
.use(nib())
.render (err, css) ->
if err
callback err
else
callback null, new Buffer css
catch error
callback error

StylusPlugin.fromFile = (filename, base, callback) ->
fs.readFile path.join(base, filename), (error, buffer) ->
StylusPlugin.fromFile = (filepath, callback) ->
fs.readFile filepath.full, (error, buffer) ->
if error
callback error
else
callback null, new StylusPlugin filename, base, buffer.toString()
callback null, new StylusPlugin filepath, buffer.toString()

wintersmith.registerContentPlugin 'styles', '**/*.styl', StylusPlugin
env.registerContentPlugin 'styles', '**/*.styl', StylusPlugin
callback()
1 change: 1 addition & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--compilers coffee:coffee-script
12 changes: 7 additions & 5 deletions test/nib.coffee
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
wintersmith = require('wintersmith')
Config = require('wintersmith/src/core/config').Config
wsStylus = require('./../')

# new wintersmith environment
env = wintersmith(new Config, __dirname)

describe "Nib integration", ->

beforeEach (done)->

# Install this plugin onto wintersmith
wsStylus wintersmith, ->
wsStylus env, ->

# Installed, now wintersmith can handle .styl
done()

it "should compile stylus with nib", (done)->

# Parse contents
wintersmith.ContentTree.fromDirectory 'test/contents/css', __dirname, (err, tree)->
env.ContentTree.fromDirectory env, 'test/contents/css', (err, tree)->

# For style.styl, we want to make sure styl is compiling using nib
tree['style.styl'].render null, null, null, (err, content)->
tree['style.styl'].getView() env, null, null, null, (err, content)->

if content?
content.should.equal("""
Expand All @@ -28,5 +32,3 @@ describe "Nib integration", ->
}""")
# yay
done()


0 comments on commit 4e2acac

Please sign in to comment.