Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sass
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
楚学文
node-sass
Commits
662b98cb
Commit
662b98cb
authored
Feb 18, 2016
by
Eugene ONeill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
invoke custom functions with options.context
parent
11c96eee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
2 deletions
+43
-2
index.js
lib/index.js
+2
-2
api.js
test/api.js
+41
-0
No files found.
lib/index.js
View file @
662b98cb
...
...
@@ -343,7 +343,7 @@ module.exports.render = function(options, cb) {
bridge
.
success
(
data
);
}
var
result
=
tryCallback
(
cb
.
callback
,
args
.
concat
(
done
));
var
result
=
tryCallback
(
cb
.
callback
.
bind
(
options
.
context
)
,
args
.
concat
(
done
));
if
(
result
)
{
done
(
result
);
...
...
@@ -400,7 +400,7 @@ module.exports.renderSync = function(options) {
var
cb
=
normalizeFunctionSignature
(
signature
,
functions
[
signature
]);
options
.
functions
[
cb
.
signature
]
=
function
()
{
return
tryCallback
(
cb
.
callback
,
arguments
);
return
tryCallback
(
cb
.
callback
.
bind
(
options
.
context
)
,
arguments
);
};
});
}
...
...
test/api.js
View file @
662b98cb
...
...
@@ -857,6 +857,28 @@ describe('api', function() {
});
});
it
(
'should call custom functions with correct context'
,
function
(
done
)
{
function
assertExpected
(
result
)
{
assert
.
equal
(
result
.
css
.
toString
().
trim
(),
'div {
\
n foo1: 1;
\
n foo2: 2; }'
);
}
var
options
=
{
data
:
'div { foo1: foo(); foo2: foo(); }'
,
functions
:
{
// foo() is stateful and will persist an incrementing counter
'foo()'
:
function
()
{
assert
(
this
);
this
.
fooCounter
=
(
this
.
fooCounter
||
0
)
+
1
;
return
new
sass
.
types
.
Number
(
this
.
fooCounter
);
}
}
};
sass
.
render
(
options
,
function
(
error
,
result
)
{
assertExpected
(
result
);
done
();
});
});
describe
(
'should properly bubble up errors from sass color constructor'
,
function
()
{
it
(
'four booleans'
,
function
(
done
)
{
sass
.
render
({
...
...
@@ -1592,6 +1614,25 @@ describe('api', function() {
done
();
});
it
(
'should call custom functions with correct context'
,
function
(
done
)
{
function
assertExpected
(
result
)
{
assert
.
equal
(
result
.
css
.
toString
().
trim
(),
'div {
\
n foo1: 1;
\
n foo2: 2; }'
);
}
var
options
=
{
data
:
'div { foo1: foo(); foo2: foo(); }'
,
functions
:
{
// foo() is stateful and will persist an incrementing counter
'foo()'
:
function
()
{
assert
(
this
);
this
.
fooCounter
=
(
this
.
fooCounter
||
0
)
+
1
;
return
new
sass
.
types
.
Number
(
this
.
fooCounter
);
}
}
};
assertExpected
(
sass
.
renderSync
(
options
));
done
();
});
});
describe
(
'.renderSync({stats: {}})'
,
function
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment