Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add Stylus support

  • Loading branch information...
commit 986c5c14601b092b5424a5c319802798ada69ca1 1 parent a2670a2
@eldargab authored
View
7 lib/engines/index.js
@@ -3,6 +3,10 @@ var extname = require('path').extname
var engines = module.exports = function (ext) {
var factory = engines.extensions[ext] || engines[ext]
+ if (!factory) throw new Error(~ext.indexOf('.')
+ ? 'Engine for ' + ext + ' not found'
+ : 'Engine ' + ext + ' not found'
+ )
return factory()
}
@@ -15,5 +19,6 @@ require('fs').readdirSync(__dirname).forEach(function (item) {
engines.extensions = {
'.jade': engines.jade,
'.md': engines.markdown,
- '.less': engines.less
+ '.less': engines.less,
+ '.styl': engines.stylus
}
View
23 lib/engines/stylus.js
@@ -0,0 +1,23 @@
+var fs = require('fs')
+
+module.exports = function () {
+ var stylus = require('stylus')
+
+ return {
+ contentType: 'text/css',
+
+ renderFile: function (file, cb) {
+ var paths = this.paths
+ ? this.paths
+ : this.root ? [this.root] : null
+
+ fs.readFile(file, 'utf8', function (error, str) {
+ if (error) return cb(error)
+ stylus.render(str, {
+ filename: file,
+ paths: paths
+ }, cb)
+ })
+ }
+ }
+}
View
1  test/fixtures/stylus/index.styl
@@ -0,0 +1 @@
+@import 'main'
View
2  test/fixtures/stylus/subdir/main.styl
@@ -0,0 +1,2 @@
+#header
+ color #4D926F
View
7 test/integration.js
@@ -22,6 +22,13 @@ describe('Integration tests', function () {
req.get('/').expect('text/css', /header/)
})
+ testEngine('Stylus', function (req, opts) {
+ opts.styl = {
+ paths: [opts.root + '/subdir']
+ }
+ req.get('/').expect('text/css', /header/)
+ })
+
testEngine('Markdown', function (req) {
req.get('/hello').expect('text/html', /<h1>Hello<\/h1>/)
})
Please sign in to comment.
Something went wrong with that request. Please try again.