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
7c354bf6
Commit
7c354bf6
authored
Dec 18, 2014
by
Adeel Mujahid
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #543 from am11/master
Binding: Refurbishes binding to use new API
parents
e9b69ab6
187cfde2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
65 additions
and
39 deletions
+65
-39
node-sass
bin/node-sass
+15
-1
binding.gyp
binding.gyp
+3
-1
index.js
lib/index.js
+14
-6
render.js
lib/render.js
+4
-2
binding.cpp
src/binding.cpp
+0
-0
sass_context_wrapper.cpp
src/sass_context_wrapper.cpp
+18
-16
sass_context_wrapper.h
src/sass_context_wrapper.h
+8
-7
api.js
test/api.js
+3
-6
No files found.
bin/node-sass
View file @
7c354bf6
...
...
@@ -31,6 +31,8 @@ var cli = meow({
' --output-style CSS output style (nested|expanded|compact|compressed)'
,
' --source-comments Include debug info in output'
,
' --source-map Emit source map'
,
' --source-map-embed Embed sourceMappingUrl as data URI'
,
' --source-map-contents Embed include contents in map'
,
' --include-path Path to look for imported files'
,
' --image-path Path to prepend when using the `image-url()` helper'
,
' --precision The amount of precision allowed in decimal numbers'
,
...
...
@@ -43,6 +45,8 @@ var cli = meow({
'omit-source-map-url'
,
'recursive'
,
'stdout'
,
'source-map-embed'
,
'source-map-contents'
,
'source-comments'
],
string
:
[
...
...
@@ -116,7 +120,17 @@ function getOptions(args, options) {
var
dir
=
options
.
output
||
process
.
cwd
();
options
.
src
=
args
[
0
];
options
.
dest
=
args
[
1
]
?
path
.
join
(
dir
,
args
[
1
])
:
null
;
options
.
dest
=
null
;
if
(
args
[
1
])
{
// destination is available
// now first check if the destination is absolute path
// see http://stackoverflow.com/a/24225816/863980 for Marc Diethelm's comment
if
(
path
.
resolve
(
args
[
1
])
===
path
.
normalize
(
args
[
1
]).
replace
(
/
(
.+
)([\/
|
\\])
$/
,
'$1'
))
{
options
.
dest
=
args
[
1
];
}
else
{
// since dest path is relative, resolve it w.r.t input
options
.
dest
=
path
.
join
(
dir
,
args
[
1
]);
}
}
if
(
!
options
.
dest
&&
!
options
.
stdout
)
{
var
ext
=
path
.
extname
(
options
.
src
);
...
...
binding.gyp
View file @
7c354bf6
...
...
@@ -29,8 +29,10 @@
'src/libsass/remove_placeholders.cpp',
'src/libsass/sass.cpp',
'src/libsass/sass2scss.cpp',
'src/libsass/sass_interface.cpp',
'src/libsass/sass_context.cpp',
'src/libsass/sass_functions.cpp',
'src/libsass/sass_util.cpp',
'src/libsass/sass_values.cpp',
'src/libsass/source_map.cpp',
'src/libsass/to_c.cpp',
'src/libsass/to_string.cpp',
...
...
lib/index.js
View file @
7c354bf6
...
...
@@ -36,11 +36,11 @@ function getOutFile(options) {
var
outFile
=
options
.
outFile
;
if
(
!
file
||
!
outFile
||
typeof
outFile
!==
'string'
||
typeof
file
!==
'string'
)
{
return
false
;
return
null
;
}
if
(
path
.
resolve
(
outFile
)
!==
path
.
normalize
(
outFile
).
replace
(
new
RegExp
(
path
.
sep
+
'$'
),
'
'
))
{
return
fals
e
;
if
(
path
.
resolve
(
outFile
)
===
path
.
normalize
(
outFile
).
replace
(
/
(
.+
)([\/
|
\\])
$/
,
'$1
'
))
{
return
outFil
e
;
}
return
path
.
resolve
(
path
.
dirname
(
file
),
outFile
);
...
...
@@ -135,7 +135,7 @@ function getOptions(options) {
options
.
data
=
options
.
data
||
null
;
options
.
file
=
options
.
file
||
null
;
options
.
imagePath
=
options
.
image_path
||
options
.
imagePath
||
''
;
options
.
outFile
=
getOutFile
(
options
)
||
null
;
options
.
outFile
=
getOutFile
(
options
);
options
.
paths
=
(
options
.
include_paths
||
options
.
includePaths
||
[]).
join
(
path
.
delimiter
);
options
.
precision
=
parseInt
(
options
.
precision
)
||
5
;
options
.
sourceMap
=
getSourceMap
(
options
);
...
...
@@ -152,12 +152,20 @@ function getOptions(options) {
var
success
=
options
.
success
;
options
.
error
=
function
(
err
,
code
)
{
try
{
err
=
JSON
.
parse
(
err
);
}
catch
(
e
)
{
err
=
{
message
:
err
};
}
if
(
error
)
{
error
(
err
,
code
);
}
};
options
.
success
=
function
(
css
,
sourceMap
)
{
sourceMap
=
JSON
.
parse
(
sourceMap
);
endStats
(
options
,
sourceMap
);
if
(
success
)
{
...
...
@@ -248,7 +256,7 @@ module.exports.renderSync = function(options) {
options
=
getOptions
(
options
);
output
=
options
.
file
?
binding
.
renderFileSync
(
options
)
:
binding
.
renderSync
(
options
);
endStats
(
options
,
options
.
stats
.
sourceMap
);
endStats
(
options
,
JSON
.
parse
(
options
.
stats
.
sourceMap
)
);
return
output
;
};
...
...
@@ -290,7 +298,7 @@ module.exports.renderFile = function(options) {
var
dir
=
path
.
dirname
(
outFile
);
var
sourceMapFile
=
path
.
resolve
(
dir
,
options
.
sourceMap
);
fs
.
writeFile
(
sourceMapFile
,
sourceMap
,
function
(
err
)
{
fs
.
writeFile
(
sourceMapFile
,
JSON
.
stringify
(
sourceMap
)
,
function
(
err
)
{
if
(
err
)
{
return
options
.
error
(
err
);
}
...
...
lib/render.js
View file @
7c354bf6
...
...
@@ -20,6 +20,8 @@ module.exports = function(options, emitter) {
outputStyle
:
options
.
outputStyle
,
precision
:
options
.
precision
,
sourceComments
:
options
.
sourceComments
,
sourceMapEmbed
:
options
.
sourceMapEmbed
,
sourceMapContents
:
options
.
sourceMapContents
,
sourceMap
:
options
.
sourceMap
};
...
...
@@ -46,7 +48,7 @@ module.exports = function(options, emitter) {
fs
.
writeFile
(
options
.
dest
,
css
,
function
(
err
)
{
if
(
err
)
{
return
emitter
.
emit
(
'error'
,
chalk
.
red
(
'Error: '
+
err
));
return
emitter
.
emit
(
'error'
,
chalk
.
red
(
err
));
}
emitter
.
emit
(
'warn'
,
chalk
.
green
(
'Wrote CSS to '
+
options
.
dest
));
...
...
@@ -72,7 +74,7 @@ module.exports = function(options, emitter) {
};
renderOptions
.
error
=
function
(
error
)
{
emitter
.
emit
(
'error'
,
chalk
.
red
(
error
));
emitter
.
emit
(
'error'
,
chalk
.
red
(
JSON
.
stringify
(
error
,
null
,
2
)
));
};
sass
.
render
(
renderOptions
);
...
...
src/binding.cpp
View file @
7c354bf6
This diff is collapsed.
Click to expand it.
src/sass_context_wrapper.cpp
View file @
7c354bf6
#include "sass_context_wrapper.h"
#include <nan.h>
#include <cstdlib>
extern
"C"
{
using
namespace
std
;
void
free_context
(
sass_context
*
ctx
)
{
delete
[]
ctx
->
source_string
;
delete
[]
ctx
->
options
.
include_paths
;
delete
[]
ctx
->
options
.
image_path
;
sass_free_context
(
ctx
);
void
compile_it
(
uv_work_t
*
req
)
{
sass_context_wrapper
*
ctx_w
=
static_cast
<
sass_context_wrapper
*>
(
req
->
data
);
if
(
ctx_w
->
dctx
)
{
compile_data
(
ctx_w
->
dctx
);
}
else
if
(
ctx_w
->
fctx
)
{
compile_file
(
ctx_w
->
fctx
);
}
}
void
compile_data
(
struct
Sass_Data_Context
*
dctx
)
{
sass_compile_data_context
(
dctx
);
}
void
free_file_context
(
sass_file_context
*
fctx
)
{
delete
[]
fctx
->
input_path
;
delete
[]
fctx
->
options
.
include_paths
;
delete
[]
fctx
->
options
.
image_path
;
sass_free_file_context
(
fctx
);
void
compile_file
(
struct
Sass_File_Context
*
fctx
)
{
sass_compile_file_context
(
fctx
);
}
sass_context_wrapper
*
sass_
new
_context_wrapper
()
{
sass_context_wrapper
*
sass_
make
_context_wrapper
()
{
return
(
sass_context_wrapper
*
)
calloc
(
1
,
sizeof
(
sass_context_wrapper
));
}
void
sass_free_context_wrapper
(
sass_context_wrapper
*
ctx_w
)
{
if
(
ctx_w
->
ctx
)
{
free_context
(
ctx_w
->
ctx
);
if
(
ctx_w
->
d
ctx
)
{
sass_delete_data_context
(
ctx_w
->
d
ctx
);
}
else
if
(
ctx_w
->
fctx
)
{
fre
e_file_context
(
ctx_w
->
fctx
);
sass_delet
e_file_context
(
ctx_w
->
fctx
);
}
NanDisposePersistent
(
ctx_w
->
stats
);
...
...
src/sass_context_wrapper.h
View file @
7c354bf6
#include "libsass/sass_interface.h"
#include <nan.h>
#include "libsass/sass_context.h"
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -7,20 +7,21 @@ extern "C" {
using
namespace
v8
;
void
free_context
(
sass_context
*
ctx
);
void
free_file_context
(
sass_file_context
*
fctx
);
void
compile_data
(
struct
Sass_Data_Context
*
dctx
);
void
compile_file
(
struct
Sass_File_Context
*
fctx
);
void
compile_it
(
uv_work_t
*
req
);
struct
sass_context_wrapper
{
sass_context
*
ctx
;
sass_file_c
ontext
*
fctx
;
Sass_Data_Context
*
d
ctx
;
Sass_File_C
ontext
*
fctx
;
Persistent
<
Object
>
stats
;
uv_work_t
request
;
NanCallback
*
callback
;
NanCallback
*
errorCallback
;
};
struct
sass_context_wrapper
*
sass_
new
_context_wrapper
(
void
);
void
sass_free_context_wrapper
(
struct
sass_context_wrapper
*
ctx
);
struct
sass_context_wrapper
*
sass_
make
_context_wrapper
(
void
);
void
sass_free_context_wrapper
(
struct
sass_context_wrapper
*
ctx
_w
);
#ifdef __cplusplus
}
...
...
test/api.js
View file @
7c354bf6
...
...
@@ -187,8 +187,7 @@ describe('api', function() {
var
stats
=
{};
var
expected
=
[
fixture
(
'include-files/bar.scss'
).
replace
(
/
\\
/g
,
'/'
),
fixture
(
'include-files/foo.scss'
).
replace
(
/
\\
/g
,
'/'
),
'stdin'
fixture
(
'include-files/foo.scss'
).
replace
(
/
\\
/g
,
'/'
)
];
sass
.
render
({
...
...
@@ -422,8 +421,7 @@ describe('api', function() {
stats
:
stats
,
sourceMap
:
true
,
success
:
function
()
{
var
map
=
JSON
.
parse
(
stats
.
sourceMap
);
assert
.
equal
(
map
.
sources
[
0
],
'index.scss'
);
assert
.
equal
(
stats
.
sourceMap
.
sources
[
0
],
'index.scss'
);
done
();
}
});
...
...
@@ -517,8 +515,7 @@ describe('api', function() {
sourceMap
:
true
});
var
map
=
JSON
.
parse
(
stats
.
sourceMap
);
assert
.
equal
(
map
.
sources
[
0
],
'index.scss'
);
assert
.
equal
(
stats
.
sourceMap
.
sources
[
0
],
'index.scss'
);
done
();
});
});
...
...
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