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
dc237d98
Commit
dc237d98
authored
Mar 28, 2015
by
Adeel Mujahid
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #815 from am11/master
CLI: Adds support for Custom Functions
parents
9dc4b18e
d91917ab
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
74 additions
and
2 deletions
+74
-2
README.md
README.md
+2
-1
node-sass
bin/node-sass
+12
-1
render.js
lib/render.js
+1
-0
cli.js
test/cli.js
+34
-0
setter-expected.css
test/fixtures/custom-functions/setter-expected.css
+3
-0
setter.scss
test/fixtures/custom-functions/setter.scss
+1
-0
string-conversion-expected.css
.../fixtures/custom-functions/string-conversion-expected.css
+2
-0
string-conversion.scss
test/fixtures/custom-functions/string-conversion.scss
+1
-0
my_custom_functions_setter.js
test/fixtures/extras/my_custom_functions_setter.js
+10
-0
my_custom_functions_string_conversion.js
.../fixtures/extras/my_custom_functions_string_conversion.js
+8
-0
No files found.
README.md
View file @
dc237d98
...
@@ -452,7 +452,8 @@ Output will be saved with the same name as input SASS file into the current work
...
@@ -452,7 +452,8 @@ Output will be saved with the same name as input SASS file into the current work
--source-map-root
Base path, will be emitted
in
source-map as is
--source-map-root
Base path, will be emitted
in
source-map as is
--include-path
Path to look
for
imported files
--include-path
Path to look
for
imported files
--precision
The amount of precision allowed
in
decimal numbers
--precision
The amount of precision allowed
in
decimal numbers
--importer
Path to custom importer
--importer
Path to .js file containing custom importer
--functions
Path to .js file containing custom functions
--help
Print usage info
--help
Print usage info
```
```
...
...
bin/node-sass
View file @
dc237d98
...
@@ -42,7 +42,8 @@ var cli = meow({
...
@@ -42,7 +42,8 @@ var cli = meow({
' --source-map-root Base path, will be emitted in source-map as is'
,
' --source-map-root Base path, will be emitted in source-map as is'
,
' --include-path Path to look for imported files'
,
' --include-path Path to look for imported files'
,
' --precision The amount of precision allowed in decimal numbers'
,
' --precision The amount of precision allowed in decimal numbers'
,
' --importer Path to custom importer'
,
' --importer Path to .js file containing custom importer'
,
' --functions Path to .js file containing custom functions'
,
' --help Print usage info'
' --help Print usage info'
].
join
(
'
\
n'
)
].
join
(
'
\
n'
)
},
{
},
{
...
@@ -55,6 +56,8 @@ var cli = meow({
...
@@ -55,6 +56,8 @@ var cli = meow({
'source-comments'
'source-comments'
],
],
string
:
[
string
:
[
'functions'
,
'importer'
,
'include-path'
,
'include-path'
,
'indent-type'
,
'indent-type'
,
'linefeed'
,
'linefeed'
,
...
@@ -227,6 +230,14 @@ function run(options, emitter) {
...
@@ -227,6 +230,14 @@ function run(options, emitter) {
}
}
}
}
if
(
options
.
functions
)
{
if
((
path
.
resolve
(
options
.
functions
)
===
path
.
normalize
(
options
.
functions
).
replace
(
/
(
.+
)([\/
|
\\])
$/
,
'$1'
)))
{
options
.
functions
=
require
(
options
.
functions
);
}
else
{
options
.
functions
=
require
(
path
.
resolve
(
process
.
cwd
(),
options
.
functions
));
}
}
if
(
options
.
watch
)
{
if
(
options
.
watch
)
{
watch
(
options
,
emitter
);
watch
(
options
,
emitter
);
}
else
{
}
else
{
...
...
lib/render.js
View file @
dc237d98
...
@@ -30,6 +30,7 @@ module.exports = function(options, emitter) {
...
@@ -30,6 +30,7 @@ module.exports = function(options, emitter) {
sourceMap
:
options
.
sourceMap
,
sourceMap
:
options
.
sourceMap
,
sourceMapRoot
:
options
.
sourceMapRoot
,
sourceMapRoot
:
options
.
sourceMapRoot
,
importer
:
options
.
importer
,
importer
:
options
.
importer
,
functions
:
options
.
functions
,
indentWidth
:
options
.
indentWidth
,
indentWidth
:
options
.
indentWidth
,
indentType
:
options
.
indentType
,
indentType
:
options
.
indentType
,
linefeed
:
options
.
linefeed
linefeed
:
options
.
linefeed
...
...
test/cli.js
View file @
dc237d98
...
@@ -400,4 +400,38 @@ describe('cli', function() {
...
@@ -400,4 +400,38 @@ describe('cli', function() {
});
});
});
});
});
});
describe
(
'functions'
,
function
()
{
it
(
'should let custom functions call setter methods on wrapped sass values (number)'
,
function
(
done
)
{
var
dest
=
fixture
(
'custom-functions/setter.css'
);
var
src
=
fixture
(
'custom-functions/setter.scss'
);
var
expected
=
read
(
fixture
(
'custom-functions/setter-expected.css'
),
'utf8'
).
trim
().
replace
(
/
\r\n
/g
,
'
\
n'
);
var
bin
=
spawn
(
cli
,
[
src
,
'--output'
,
path
.
dirname
(
dest
),
'--functions'
,
fixture
(
'extras/my_custom_functions_setter.js'
)
]);
bin
.
once
(
'close'
,
function
()
{
assert
.
equal
(
read
(
dest
,
'utf8'
).
trim
(),
expected
);
fs
.
unlinkSync
(
dest
);
done
();
});
});
it
(
'should properly convert strings when calling custom functions'
,
function
(
done
)
{
var
dest
=
fixture
(
'custom-functions/string-conversion.css'
);
var
src
=
fixture
(
'custom-functions/string-conversion.scss'
);
var
expected
=
read
(
fixture
(
'custom-functions/string-conversion-expected.css'
),
'utf8'
).
trim
().
replace
(
/
\r\n
/g
,
'
\
n'
);
var
bin
=
spawn
(
cli
,
[
src
,
'--output'
,
path
.
dirname
(
dest
),
'--functions'
,
fixture
(
'extras/my_custom_functions_string_conversion.js'
)
]);
bin
.
once
(
'close'
,
function
()
{
assert
.
equal
(
read
(
dest
,
'utf8'
).
trim
(),
expected
);
fs
.
unlinkSync
(
dest
);
done
();
});
});
});
});
});
test/fixtures/custom-functions/setter-expected.css
0 → 100644
View file @
dc237d98
div
{
width
:
42rem
;
height
:
84px
;
}
test/fixtures/custom-functions/setter.scss
0 → 100644
View file @
dc237d98
div
{
width
:
foo
(
42px
);
height
:
bar
(
42px
);
}
test/fixtures/custom-functions/string-conversion-expected.css
0 → 100644
View file @
dc237d98
div
{
color
:
"barbar"
;
}
test/fixtures/custom-functions/string-conversion.scss
0 → 100644
View file @
dc237d98
div
{
color
:
foo
(
"bar"
);
}
test/fixtures/extras/my_custom_functions_setter.js
0 → 100644
View file @
dc237d98
module
.
exports
=
{
'foo($a)'
:
function
(
size
)
{
size
.
setUnit
(
'rem'
);
return
size
;
},
'bar($a)'
:
function
(
size
)
{
size
.
setValue
(
size
.
getValue
()
*
2
);
return
size
;
}
};
test/fixtures/extras/my_custom_functions_string_conversion.js
0 → 100644
View file @
dc237d98
var
sass
=
require
(
'../../..'
);
module
.
exports
=
{
'foo($a)'
:
function
(
str
)
{
str
=
str
.
getValue
().
replace
(
/
[
'"
]
/g
,
''
);
return
new
sass
.
types
.
String
(
'"'
+
str
+
str
+
'"'
);
}
};
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