Permalink
Browse files

Adding global() function

  • Loading branch information...
davidkpiano committed Feb 1, 2016
1 parent e3ddf12 commit c181eb2097824cdee655a2ae1d1a839ec410944c
Showing with 37 additions and 8 deletions.
  1. +10 −5 dist/index.js
  2. +3 −1 package.json
  3. +5 −2 src/index.js
  4. +19 −0 test/globals.js
View
@@ -91,7 +91,8 @@ var Sassport = function () {
*/
function Sassport(name) {
var _this = this;
var _this = this,
_functions;
var modules = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
@@ -121,8 +122,8 @@ var Sassport = function () {
};
this._exports = {};
this._loaders = {};
this._variables = {};
this._localPath = _path2.default.resolve('./');
this._localAssetPath = null;
@@ -131,7 +132,7 @@ var Sassport = function () {
this._onRequire = options.onRequire.bind(this);
this.options = {
functions: _defineProperty({
functions: (_functions = {
'resolve-path($source, $module: null)': function resolvePath$source$moduleNull(source, module) {
var modulePath = _utils2.default.isNull(module) ? '' : module.getValue();
var assetPath = source.getValue();
@@ -152,7 +153,7 @@ var Sassport = function () {
return _nodeSass2.default.types.String(assetUrl);
}
}, 'require($path, $propPath: null, $infer: ' + options.infer + ')', function undefined(file, propPath, infer, done) {
}, _defineProperty(_functions, 'require($path, $propPath: null, $infer: ' + options.infer + ')', function undefined(file, propPath, infer, done) {
file = file.getValue();
propPath = _utils2.default.isNull(propPath) ? false : propPath.getValue();
@@ -165,7 +166,9 @@ var Sassport = function () {
return _utils2.default.toSass(data, {
infer: _utils2.default.castToJs(infer)
});
}),
}), _defineProperty(_functions, 'global($variable)', (0, _wrap2.default)(function (variable) {
return _this._variables[variable];
})), _functions),
importer: this._importer,
includePaths: ['node_modules'],
sassportModules: modules // carried over to node-sass
@@ -253,6 +256,8 @@ var Sassport = function () {
}, {
key: 'globals',
value: function globals(variableMap) {
this._variables = variableMap;
for (var key in variableMap) {
var value = variableMap[key];
var sassValue = _utils2.default.sassString(_utils2.default.castToSass(value));
View
@@ -5,7 +5,9 @@
"main": "dist/index.js",
"scripts": {
"start": "babel -w ./src -d ./dist",
"test": "mocha -w --require babel-core/register"
"build": "babel ./src -d ./dist",
"test": "npm run build && mocha --require babel-core/register",
"test:watch": "mocha -w --require babel-core/register"
},
"repository": {
"type": "git",
View
@@ -76,8 +76,8 @@ class Sassport {
};
this._exports = {};
this._loaders = {};
this._variables = {};
this._localPath = path.resolve('./');
this._localAssetPath = null;
@@ -124,7 +124,8 @@ class Sassport {
return utils.toSass(data, {
infer: utils.castToJs(infer)
});
}
},
'global($variable)': wrap((variable) => this._variables[variable])
},
importer: this._importer,
includePaths: ['node_modules'],
@@ -204,6 +205,8 @@ class Sassport {
}
globals(variableMap) {
this._variables = variableMap;
for (let key in variableMap) {
let value = variableMap[key];
let sassValue = utils.sassString(utils.castToSass(value));
View
@@ -99,4 +99,23 @@ describe('Sassport.globals', function() {
done);
});
});
describe('global() Sass function', () => {
let testModule = sassport()
.globals({
'$foo': 'foo value',
'$bar': 'bar value'
});
it('should retrieve the proper global variables from the root module', (done) => {
testModule.render({
data: 'test { foo: global("$foo"); }',
outputStyle: 'compressed'
}, (err, result) => {
done(assert.equal(
result.css.toString(),
'test{foo:foo value}\n'));
});
});
});
});

0 comments on commit c181eb2

Please sign in to comment.