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
09bf80c8
Commit
09bf80c8
authored
Mar 23, 2016
by
Michael Mifsud
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1390 from eoneill/customFunctionsContext
Invoke custom functions with options.context
parents
5b2862e2
662b98cb
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 @
09bf80c8
...
@@ -343,7 +343,7 @@ module.exports.render = function(options, cb) {
...
@@ -343,7 +343,7 @@ module.exports.render = function(options, cb) {
bridge
.
success
(
data
);
bridge
.
success
(
data
);
}
}
var
result
=
tryCallback
(
cb
.
callback
,
args
.
concat
(
done
));
var
result
=
tryCallback
(
cb
.
callback
.
bind
(
options
.
context
)
,
args
.
concat
(
done
));
if
(
result
)
{
if
(
result
)
{
done
(
result
);
done
(
result
);
...
@@ -400,7 +400,7 @@ module.exports.renderSync = function(options) {
...
@@ -400,7 +400,7 @@ module.exports.renderSync = function(options) {
var
cb
=
normalizeFunctionSignature
(
signature
,
functions
[
signature
]);
var
cb
=
normalizeFunctionSignature
(
signature
,
functions
[
signature
]);
options
.
functions
[
cb
.
signature
]
=
function
()
{
options
.
functions
[
cb
.
signature
]
=
function
()
{
return
tryCallback
(
cb
.
callback
,
arguments
);
return
tryCallback
(
cb
.
callback
.
bind
(
options
.
context
)
,
arguments
);
};
};
});
});
}
}
...
...
test/api.js
View file @
09bf80c8
...
@@ -911,6 +911,28 @@ describe('api', function() {
...
@@ -911,6 +911,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
()
{
describe
(
'should properly bubble up errors from sass color constructor'
,
function
()
{
it
(
'four booleans'
,
function
(
done
)
{
it
(
'four booleans'
,
function
(
done
)
{
sass
.
render
({
sass
.
render
({
...
@@ -1646,6 +1668,25 @@ describe('api', function() {
...
@@ -1646,6 +1668,25 @@ describe('api', function() {
done
();
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
()
{
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