Skip to content

Commit

Permalink
Merge 78f7197 into 5dfc10b
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Feb 24, 2017
2 parents 5dfc10b + 78f7197 commit 3892359
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
'use strict'

var sassRenderer = require('./lib/renderer')
// export hexo to global vm context
global.hexo = hexo

// associate the Sass renderer with .scss AND .sass extensions
hexo.extend.renderer.register('scss', 'css', sassRenderer('scss'))
hexo.extend.renderer.register('sass', 'css', sassRenderer('sass'))
5 changes: 2 additions & 3 deletions lib/renderer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global hexo */
'use strict'

var sass = require('node-sass')
Expand All @@ -7,8 +6,8 @@ var extend = require('util')._extend
module.exports = (ext) => function (data) {
// support global and theme-specific config
var userConfig = extend(
hexo.theme.config.node_sass || {},
hexo.config.node_sass || {}
this.theme.config.node_sass || {},
this.config.node_sass || {}
)

var config = extend({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"node-sass": "^4.1.1"
},
"peerDependencies": {
"hexo": ">= 1.0.0"
"hexo": ">= 3"
},
"devDependencies": {
"chai": "^3.5.0",
Expand Down
28 changes: 10 additions & 18 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ describe('Sass renderer', function () {
}
}

global.hexo = ctx

var r = require('../lib/renderer')

it('default: scss syntax', function () {
Expand All @@ -24,7 +22,7 @@ describe('Sass renderer', function () {
'}'
].join('\n')

var result = r('scss')({ text: body }, {})
var result = r('scss').call(ctx, { text: body }, {})
result.should.eql([
'.foo {',
' color: red; }'
Expand All @@ -38,7 +36,7 @@ describe('Sass renderer', function () {
' color: $color'
].join('\n')

var result = r('sass')({ text: body }, {})
var result = r('sass').call(ctx, { text: body }, {})
result.should.eql([
'.foo {',
' color: red; }'
Expand All @@ -47,7 +45,6 @@ describe('Sass renderer', function () {

it('outputStyle compressed: scss syntax', function () {
ctx.theme.config = { node_sass: { outputStyle: 'compressed' } }
global.hexo = ctx

var body = [
'$color: red;',
Expand All @@ -56,23 +53,22 @@ describe('Sass renderer', function () {
'}'
].join('\n')

var result = r('scss')({ text: body }, {})
var result = r('scss').call(ctx, { text: body }, {})
result.should.eql([
'.foo{color:red}'
].join('\n') + '\n')
})

it('outputStyle compressed: sass syntax', function () {
ctx.theme.config = { node_sass: { outputStyle: 'compressed' } }
global.hexo = ctx

var body = [
'$color: red',
'.foo',
' color: $color'
].join('\n')

var result = r('sass')({ text: body }, {})
var result = r('sass').call(ctx, { text: body }, {})
result.should.eql([
'.foo{color:red}'
].join('\n') + '\n')
Expand All @@ -81,7 +77,6 @@ describe('Sass renderer', function () {
it('supports root config: scss syntax', function () {
ctx.config = { node_sass: { outputStyle: 'compressed' } }
ctx.theme.config = {}
global.hexo = ctx

var body = [
'$color: red;',
Expand All @@ -90,7 +85,7 @@ describe('Sass renderer', function () {
'}'
].join('\n')

var result = r('scss')({ text: body }, {})
var result = r('scss').call(ctx, { text: body }, {})
result.should.eql([
'.foo{color:red}'
].join('\n') + '\n')
Expand All @@ -99,15 +94,14 @@ describe('Sass renderer', function () {
it('supports root config: sass syntax', function () {
ctx.config = { node_sass: { outputStyle: 'compressed' } }
ctx.theme.config = {}
global.hexo = ctx

var body = [
'$color: red',
'.foo',
' color: $color'
].join('\n')

var result = r('sass')({ text: body }, {})
var result = r('sass').call(ctx, { text: body }, {})
result.should.eql([
'.foo{color:red}'
].join('\n') + '\n')
Expand All @@ -116,7 +110,6 @@ describe('Sass renderer', function () {
it('throw when error occurs: scss syntax', function () {
ctx.theme.config = { node_sass: { outputStyle: 'compressed' } }
ctx.config = {}
global.hexo = ctx

var body = [
'.foo {',
Expand All @@ -125,22 +118,21 @@ describe('Sass renderer', function () {
].join('\n')

should.Throw(function () {
return r('scss')({ text: body }, {})
})
return r('scss').call(ctx, { text: body }, {})
}, 'Undefined variable: "$color".')
})

it('throw when error occurs: sass syntax', function () {
ctx.theme.config = { node_sass: { outputStyle: 'compressed' } }
ctx.config = {}
global.hexo = ctx

var body = [
'.foo',
' color: $color'
].join('\n')

should.Throw(function () {
return r('sass')({ text: body }, {})
})
return r('sass').call(ctx, { text: body }, {})
}, 'Undefined variable: "$color".')
})
})

0 comments on commit 3892359

Please sign in to comment.