diff --git a/index.js b/index.js index 9ecfe59..4378053 100644 --- a/index.js +++ b/index.js @@ -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')) diff --git a/lib/renderer.js b/lib/renderer.js index b46292d..1140396 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -1,4 +1,3 @@ -/* global hexo */ 'use strict' var sass = require('node-sass') @@ -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({ diff --git a/package.json b/package.json index c1a6145..d9584b1 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "node-sass": "^4.1.1" }, "peerDependencies": { - "hexo": ">= 1.0.0" + "hexo": ">= 3" }, "devDependencies": { "chai": "^3.5.0", diff --git a/test/index.js b/test/index.js index 5e53275..1e2584a 100644 --- a/test/index.js +++ b/test/index.js @@ -12,8 +12,6 @@ describe('Sass renderer', function () { } } - global.hexo = ctx - var r = require('../lib/renderer') it('default: scss syntax', function () { @@ -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; }' @@ -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; }' @@ -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;', @@ -56,7 +53,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') @@ -64,7 +61,6 @@ describe('Sass renderer', function () { it('outputStyle compressed: sass syntax', function () { ctx.theme.config = { node_sass: { outputStyle: 'compressed' } } - global.hexo = ctx var body = [ '$color: red', @@ -72,7 +68,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}' ].join('\n') + '\n') @@ -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;', @@ -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') @@ -99,7 +94,6 @@ 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', @@ -107,7 +101,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}' ].join('\n') + '\n') @@ -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 {', @@ -125,14 +118,13 @@ 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', @@ -140,7 +132,7 @@ describe('Sass renderer', function () { ].join('\n') should.Throw(function () { - return r('sass')({ text: body }, {}) - }) + return r('sass').call(ctx, { text: body }, {}) + }, 'Undefined variable: "$color".') }) })