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
0a4970e4
Commit
0a4970e4
authored
Dec 18, 2014
by
Adeel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API: Encapsulate output in a single object.
parent
70ce07ba
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
84 deletions
+27
-84
index.js
lib/index.js
+18
-75
render.js
lib/render.js
+7
-7
api.js
test/api.js
+0
-0
spec.js
test/spec.js
+2
-2
No files found.
lib/index.js
View file @
0a4970e4
...
@@ -54,7 +54,7 @@ function getOutFile(options) {
...
@@ -54,7 +54,7 @@ function getOutFile(options) {
*/
*/
function
getStats
(
options
)
{
function
getStats
(
options
)
{
var
stats
=
options
.
stats
;
var
stats
=
{}
;
stats
.
entry
=
options
.
file
||
'data'
;
stats
.
entry
=
options
.
file
||
'data'
;
stats
.
start
=
Date
.
now
();
stats
.
start
=
Date
.
now
();
...
@@ -70,12 +70,11 @@ function getStats(options) {
...
@@ -70,12 +70,11 @@ function getStats(options) {
* @api private
* @api private
*/
*/
function
endStats
(
options
,
sourceMap
)
{
function
endStats
(
options
)
{
var
stats
=
options
.
stats
||
{};
var
stats
=
options
.
stats
||
{};
stats
.
end
=
Date
.
now
();
stats
.
end
=
Date
.
now
();
stats
.
duration
=
stats
.
end
-
stats
.
start
;
stats
.
duration
=
stats
.
end
-
stats
.
start
;
stats
.
sourceMap
=
sourceMap
;
return
stats
;
return
stats
;
}
}
...
@@ -139,14 +138,13 @@ function getOptions(options) {
...
@@ -139,14 +138,13 @@ function getOptions(options) {
options
.
paths
=
(
options
.
include_paths
||
options
.
includePaths
||
[]).
join
(
path
.
delimiter
);
options
.
paths
=
(
options
.
include_paths
||
options
.
includePaths
||
[]).
join
(
path
.
delimiter
);
options
.
precision
=
parseInt
(
options
.
precision
)
||
5
;
options
.
precision
=
parseInt
(
options
.
precision
)
||
5
;
options
.
sourceMap
=
getSourceMap
(
options
);
options
.
sourceMap
=
getSourceMap
(
options
);
options
.
stats
=
options
.
stats
||
{};
options
.
style
=
getStyle
(
options
)
||
0
;
options
.
style
=
getStyle
(
options
)
||
0
;
if
(
options
.
imagePath
&&
typeof
options
.
imagePath
!==
'string'
)
{
if
(
options
.
imagePath
&&
typeof
options
.
imagePath
!==
'string'
)
{
throw
new
Error
(
'`imagePath` needs to be a string'
);
throw
new
Error
(
'`imagePath` needs to be a string'
);
}
}
getStats
(
options
);
options
.
stats
=
getStats
(
options
);
var
error
=
options
.
error
;
var
error
=
options
.
error
;
var
success
=
options
.
success
;
var
success
=
options
.
success
;
...
@@ -159,8 +157,10 @@ function getOptions(options) {
...
@@ -159,8 +157,10 @@ function getOptions(options) {
err
=
{
message
:
err
};
err
=
{
message
:
err
};
}
}
err
.
code
=
code
;
if
(
error
)
{
if
(
error
)
{
error
(
err
,
code
);
error
(
err
);
}
}
};
};
...
@@ -170,7 +170,11 @@ function getOptions(options) {
...
@@ -170,7 +170,11 @@ function getOptions(options) {
endStats
(
options
,
sourceMap
);
endStats
(
options
,
sourceMap
);
if
(
success
)
{
if
(
success
)
{
success
(
css
,
sourceMap
);
success
({
css
:
css
,
map
:
sourceMap
,
stats
:
options
.
stats
});
}
}
};
};
...
@@ -225,77 +229,16 @@ module.exports.renderSync = function(options) {
...
@@ -225,77 +229,16 @@ module.exports.renderSync = function(options) {
options
=
getOptions
(
options
);
options
=
getOptions
(
options
);
output
=
options
.
data
?
binding
.
renderSync
(
options
)
:
binding
.
renderFileSync
(
options
);
output
=
options
.
data
?
binding
.
renderSync
(
options
)
:
binding
.
renderFileSync
(
options
);
endStats
(
options
,
JSON
.
parse
(
options
.
stats
.
sourceMap
));
endStats
(
options
);
return
output
;
};
/**
* Render file
*
* `options.sourceMap` can be used to specify that the source map should be saved:
*
* - If falsy the source map will not be saved
* - If `options.sourceMap === true` the source map will be saved to the
* standard location of `options.file + '.map'`
* - Else `options.sourceMap` specifies the path (relative to the `outFile`)
* where the source map should be saved
*
* @param {Object} options
* @api public
*/
module
.
exports
.
renderFile
=
function
(
options
)
{
options
=
options
||
{};
var
outFile
=
options
.
outFile
;
var
success
=
options
.
success
;
if
(
options
.
sourceMap
===
true
)
{
options
.
sourceMap
=
outFile
+
'.map'
;
}
options
.
success
=
function
(
css
,
sourceMap
)
{
fs
.
writeFile
(
outFile
,
css
,
function
(
err
)
{
if
(
err
)
{
return
options
.
error
(
err
);
}
if
(
!
options
.
sourceMap
)
{
return
success
(
outFile
);
}
var
dir
=
path
.
dirname
(
outFile
);
var
sourceMapFile
=
path
.
resolve
(
dir
,
options
.
sourceMap
);
fs
.
writeFile
(
sourceMapFile
,
JSON
.
stringify
(
sourceMap
),
function
(
err
)
{
if
(
err
)
{
return
options
.
error
(
err
);
}
success
(
outFile
,
sourceMapFile
);
var
result
=
{
});
css
:
output
,
});
map
:
options
.
stats
.
sourceMap
};
};
module
.
exports
.
render
(
options
);
delete
options
.
stats
.
sourceMap
;
};
/**
* Middleware
*
* @api public
*/
module
.
exports
.
middleware
=
function
()
{
result
.
stats
=
options
.
stats
;
return
new
Error
([
'The middleware has been moved to'
,
'https://github.com/sass/node-sass-middleware'
].
join
(
' '
));
endStats
(
options
,
options
.
stats
.
sourceMap
);
return
result
;
return
{
css
:
output
,
map
:
options
.
stats
.
sourceMap
};
};
};
lib/render.js
View file @
0a4970e4
...
@@ -31,7 +31,7 @@ module.exports = function(options, emitter) {
...
@@ -31,7 +31,7 @@ module.exports = function(options, emitter) {
renderOptions
.
data
=
options
.
data
;
renderOptions
.
data
=
options
.
data
;
}
}
renderOptions
.
success
=
function
(
css
,
sourceMap
)
{
renderOptions
.
success
=
function
(
result
)
{
var
todo
=
1
;
var
todo
=
1
;
var
done
=
function
()
{
var
done
=
function
()
{
if
(
--
todo
<=
0
)
{
if
(
--
todo
<=
0
)
{
...
@@ -40,37 +40,37 @@ module.exports = function(options, emitter) {
...
@@ -40,37 +40,37 @@ module.exports = function(options, emitter) {
};
};
if
(
options
.
stdout
||
(
!
options
.
dest
&&
!
process
.
stdout
.
isTTY
)
||
options
.
stdin
)
{
if
(
options
.
stdout
||
(
!
options
.
dest
&&
!
process
.
stdout
.
isTTY
)
||
options
.
stdin
)
{
emitter
.
emit
(
'log'
,
css
);
emitter
.
emit
(
'log'
,
result
.
css
);
return
done
();
return
done
();
}
}
emitter
.
emit
(
'warn'
,
chalk
.
green
(
'Rendering Complete, saving .css file...'
));
emitter
.
emit
(
'warn'
,
chalk
.
green
(
'Rendering Complete, saving .css file...'
));
fs
.
writeFile
(
options
.
dest
,
css
,
function
(
err
)
{
fs
.
writeFile
(
options
.
dest
,
result
.
css
,
function
(
err
)
{
if
(
err
)
{
if
(
err
)
{
return
emitter
.
emit
(
'error'
,
chalk
.
red
(
err
));
return
emitter
.
emit
(
'error'
,
chalk
.
red
(
err
));
}
}
emitter
.
emit
(
'warn'
,
chalk
.
green
(
'Wrote CSS to '
+
options
.
dest
));
emitter
.
emit
(
'warn'
,
chalk
.
green
(
'Wrote CSS to '
+
options
.
dest
));
emitter
.
emit
(
'write'
,
err
,
options
.
dest
,
css
);
emitter
.
emit
(
'write'
,
err
,
options
.
dest
,
result
.
css
);
done
();
done
();
});
});
if
(
options
.
sourceMap
)
{
if
(
options
.
sourceMap
)
{
todo
++
;
todo
++
;
fs
.
writeFile
(
options
.
sourceMap
,
sourceM
ap
,
function
(
err
)
{
fs
.
writeFile
(
options
.
sourceMap
,
result
.
m
ap
,
function
(
err
)
{
if
(
err
)
{
if
(
err
)
{
return
emitter
.
emit
(
'error'
,
chalk
.
red
(
'Error'
+
err
));
return
emitter
.
emit
(
'error'
,
chalk
.
red
(
'Error'
+
err
));
}
}
emitter
.
emit
(
'warn'
,
chalk
.
green
(
'Wrote Source Map to '
+
options
.
sourceMap
));
emitter
.
emit
(
'warn'
,
chalk
.
green
(
'Wrote Source Map to '
+
options
.
sourceMap
));
emitter
.
emit
(
'write-source-map'
,
err
,
options
.
sourceMap
,
sourceMap
);
emitter
.
emit
(
'write-source-map'
,
err
,
options
.
sourceMap
,
result
.
sourceMap
);
done
();
done
();
});
});
}
}
emitter
.
emit
(
'render'
,
css
);
emitter
.
emit
(
'render'
,
result
.
css
);
};
};
renderOptions
.
error
=
function
(
error
)
{
renderOptions
.
error
=
function
(
error
)
{
...
...
test/api.js
View file @
0a4970e4
This diff is collapsed.
Click to expand it.
test/spec.js
View file @
0a4970e4
...
@@ -40,8 +40,8 @@ describe('spec', function () {
...
@@ -40,8 +40,8 @@ describe('spec', function () {
sass
.
render
({
sass
.
render
({
file
:
t
.
src
,
file
:
t
.
src
,
includePaths
:
t
.
paths
,
includePaths
:
t
.
paths
,
success
:
function
(
css
)
{
success
:
function
(
result
)
{
assert
.
equal
(
util
.
normalize
(
css
),
expected
);
assert
.
equal
(
util
.
normalize
(
result
.
css
),
expected
);
done
();
done
();
},
},
error
:
function
(
err
)
{
error
:
function
(
err
)
{
...
...
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