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
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
161 additions
and
132 deletions
+161
-132
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
+96
-93
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({
...
@@ -31,6 +31,8 @@ var cli = meow({
' --output-style CSS output style (nested|expanded|compact|compressed)'
,
' --output-style CSS output style (nested|expanded|compact|compressed)'
,
' --source-comments Include debug info in output'
,
' --source-comments Include debug info in output'
,
' --source-map Emit source map'
,
' --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'
,
' --include-path Path to look for imported files'
,
' --image-path Path to prepend when using the `image-url()` helper'
,
' --image-path Path to prepend when using the `image-url()` helper'
,
' --precision The amount of precision allowed in decimal numbers'
,
' --precision The amount of precision allowed in decimal numbers'
,
...
@@ -43,6 +45,8 @@ var cli = meow({
...
@@ -43,6 +45,8 @@ var cli = meow({
'omit-source-map-url'
,
'omit-source-map-url'
,
'recursive'
,
'recursive'
,
'stdout'
,
'stdout'
,
'source-map-embed'
,
'source-map-contents'
,
'source-comments'
'source-comments'
],
],
string
:
[
string
:
[
...
@@ -116,7 +120,17 @@ function getOptions(args, options) {
...
@@ -116,7 +120,17 @@ function getOptions(args, options) {
var
dir
=
options
.
output
||
process
.
cwd
();
var
dir
=
options
.
output
||
process
.
cwd
();
options
.
src
=
args
[
0
];
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
)
{
if
(
!
options
.
dest
&&
!
options
.
stdout
)
{
var
ext
=
path
.
extname
(
options
.
src
);
var
ext
=
path
.
extname
(
options
.
src
);
...
...
binding.gyp
View file @
7c354bf6
...
@@ -29,8 +29,10 @@
...
@@ -29,8 +29,10 @@
'src/libsass/remove_placeholders.cpp',
'src/libsass/remove_placeholders.cpp',
'src/libsass/sass.cpp',
'src/libsass/sass.cpp',
'src/libsass/sass2scss.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_util.cpp',
'src/libsass/sass_values.cpp',
'src/libsass/source_map.cpp',
'src/libsass/source_map.cpp',
'src/libsass/to_c.cpp',
'src/libsass/to_c.cpp',
'src/libsass/to_string.cpp',
'src/libsass/to_string.cpp',
...
...
lib/index.js
View file @
7c354bf6
...
@@ -36,11 +36,11 @@ function getOutFile(options) {
...
@@ -36,11 +36,11 @@ function getOutFile(options) {
var
outFile
=
options
.
outFile
;
var
outFile
=
options
.
outFile
;
if
(
!
file
||
!
outFile
||
typeof
outFile
!==
'string'
||
typeof
file
!==
'string'
)
{
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
+
'$'
),
'
'
))
{
if
(
path
.
resolve
(
outFile
)
===
path
.
normalize
(
outFile
).
replace
(
/
(
.+
)([\/
|
\\])
$/
,
'$1
'
))
{
return
fals
e
;
return
outFil
e
;
}
}
return
path
.
resolve
(
path
.
dirname
(
file
),
outFile
);
return
path
.
resolve
(
path
.
dirname
(
file
),
outFile
);
...
@@ -135,7 +135,7 @@ function getOptions(options) {
...
@@ -135,7 +135,7 @@ function getOptions(options) {
options
.
data
=
options
.
data
||
null
;
options
.
data
=
options
.
data
||
null
;
options
.
file
=
options
.
file
||
null
;
options
.
file
=
options
.
file
||
null
;
options
.
imagePath
=
options
.
image_path
||
options
.
imagePath
||
''
;
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
.
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
);
...
@@ -152,12 +152,20 @@ function getOptions(options) {
...
@@ -152,12 +152,20 @@ function getOptions(options) {
var
success
=
options
.
success
;
var
success
=
options
.
success
;
options
.
error
=
function
(
err
,
code
)
{
options
.
error
=
function
(
err
,
code
)
{
try
{
err
=
JSON
.
parse
(
err
);
}
catch
(
e
)
{
err
=
{
message
:
err
};
}
if
(
error
)
{
if
(
error
)
{
error
(
err
,
code
);
error
(
err
,
code
);
}
}
};
};
options
.
success
=
function
(
css
,
sourceMap
)
{
options
.
success
=
function
(
css
,
sourceMap
)
{
sourceMap
=
JSON
.
parse
(
sourceMap
);
endStats
(
options
,
sourceMap
);
endStats
(
options
,
sourceMap
);
if
(
success
)
{
if
(
success
)
{
...
@@ -248,7 +256,7 @@ module.exports.renderSync = function(options) {
...
@@ -248,7 +256,7 @@ module.exports.renderSync = function(options) {
options
=
getOptions
(
options
);
options
=
getOptions
(
options
);
output
=
options
.
file
?
binding
.
renderFileSync
(
options
)
:
binding
.
renderSync
(
options
);
output
=
options
.
file
?
binding
.
renderFileSync
(
options
)
:
binding
.
renderSync
(
options
);
endStats
(
options
,
options
.
stats
.
sourceMap
);
endStats
(
options
,
JSON
.
parse
(
options
.
stats
.
sourceMap
)
);
return
output
;
return
output
;
};
};
...
@@ -290,7 +298,7 @@ module.exports.renderFile = function(options) {
...
@@ -290,7 +298,7 @@ module.exports.renderFile = function(options) {
var
dir
=
path
.
dirname
(
outFile
);
var
dir
=
path
.
dirname
(
outFile
);
var
sourceMapFile
=
path
.
resolve
(
dir
,
options
.
sourceMap
);
var
sourceMapFile
=
path
.
resolve
(
dir
,
options
.
sourceMap
);
fs
.
writeFile
(
sourceMapFile
,
sourceMap
,
function
(
err
)
{
fs
.
writeFile
(
sourceMapFile
,
JSON
.
stringify
(
sourceMap
)
,
function
(
err
)
{
if
(
err
)
{
if
(
err
)
{
return
options
.
error
(
err
);
return
options
.
error
(
err
);
}
}
...
...
lib/render.js
View file @
7c354bf6
...
@@ -20,6 +20,8 @@ module.exports = function(options, emitter) {
...
@@ -20,6 +20,8 @@ module.exports = function(options, emitter) {
outputStyle
:
options
.
outputStyle
,
outputStyle
:
options
.
outputStyle
,
precision
:
options
.
precision
,
precision
:
options
.
precision
,
sourceComments
:
options
.
sourceComments
,
sourceComments
:
options
.
sourceComments
,
sourceMapEmbed
:
options
.
sourceMapEmbed
,
sourceMapContents
:
options
.
sourceMapContents
,
sourceMap
:
options
.
sourceMap
sourceMap
:
options
.
sourceMap
};
};
...
@@ -46,7 +48,7 @@ module.exports = function(options, emitter) {
...
@@ -46,7 +48,7 @@ module.exports = function(options, emitter) {
fs
.
writeFile
(
options
.
dest
,
css
,
function
(
err
)
{
fs
.
writeFile
(
options
.
dest
,
css
,
function
(
err
)
{
if
(
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
));
emitter
.
emit
(
'warn'
,
chalk
.
green
(
'Wrote CSS to '
+
options
.
dest
));
...
@@ -72,7 +74,7 @@ module.exports = function(options, emitter) {
...
@@ -72,7 +74,7 @@ module.exports = function(options, emitter) {
};
};
renderOptions
.
error
=
function
(
error
)
{
renderOptions
.
error
=
function
(
error
)
{
emitter
.
emit
(
'error'
,
chalk
.
red
(
error
));
emitter
.
emit
(
'error'
,
chalk
.
red
(
JSON
.
stringify
(
error
,
null
,
2
)
));
};
};
sass
.
render
(
renderOptions
);
sass
.
render
(
renderOptions
);
...
...
src/binding.cpp
View file @
7c354bf6
#include <nan.h>
#include <nan.h>
#include <string>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include "sass_context_wrapper.h"
#include "sass_context_wrapper.h"
using
namespace
v8
;
using
namespace
std
;
void
WorkOnContext
(
uv_work_t
*
req
)
{
sass_context_wrapper
*
ctx_w
=
static_cast
<
sass_context_wrapper
*>
(
req
->
data
);
if
(
ctx_w
->
ctx
)
{
sass_context
*
ctx
=
static_cast
<
sass_context
*>
(
ctx_w
->
ctx
);
sass_compile
(
ctx
);
}
else
if
(
ctx_w
->
fctx
)
{
sass_file_context
*
ctx
=
static_cast
<
sass_file_context
*>
(
ctx_w
->
fctx
);
sass_compile_file
(
ctx
);
}
}
char
*
CreateString
(
Local
<
Value
>
value
)
{
char
*
CreateString
(
Local
<
Value
>
value
)
{
if
(
value
->
IsNull
()
||
!
value
->
IsString
())
{
if
(
value
->
IsNull
()
||
!
value
->
IsString
())
{
return
const_cast
<
char
*>
(
""
);
// return empty string.
return
const_cast
<
char
*>
(
""
);
// return empty string.
...
@@ -30,10 +12,7 @@ char* CreateString(Local<Value> value) {
...
@@ -30,10 +12,7 @@ char* CreateString(Local<Value> value) {
return
str
;
return
str
;
}
}
void
ExtractOptions
(
Local
<
Value
>
optionsValue
,
void
*
cptr
,
sass_context_wrapper
*
ctx_w
,
bool
isFile
)
{
void
ExtractOptions
(
Local
<
Object
>
options
,
void
*
cptr
,
sass_context_wrapper
*
ctx_w
,
bool
isFile
)
{
bool
source_comments
;
Local
<
Object
>
options
=
optionsValue
->
ToObject
();
if
(
ctx_w
)
{
if
(
ctx_w
)
{
NanAssignPersistent
(
ctx_w
->
stats
,
options
->
Get
(
NanNew
(
"stats"
))
->
ToObject
());
NanAssignPersistent
(
ctx_w
->
stats
,
options
->
Get
(
NanNew
(
"stats"
))
->
ToObject
());
...
@@ -41,66 +20,62 @@ void ExtractOptions(Local<Value> optionsValue, void* cptr, sass_context_wrapper*
...
@@ -41,66 +20,62 @@ void ExtractOptions(Local<Value> optionsValue, void* cptr, sass_context_wrapper*
Local
<
Function
>
callback
=
Local
<
Function
>::
Cast
(
options
->
Get
(
NanNew
(
"success"
)));
Local
<
Function
>
callback
=
Local
<
Function
>::
Cast
(
options
->
Get
(
NanNew
(
"success"
)));
Local
<
Function
>
errorCallback
=
Local
<
Function
>::
Cast
(
options
->
Get
(
NanNew
(
"error"
)));
Local
<
Function
>
errorCallback
=
Local
<
Function
>::
Cast
(
options
->
Get
(
NanNew
(
"error"
)));
if
(
isFile
)
{
if
(
isFile
)
{
ctx_w
->
fctx
=
(
s
ass_file_c
ontext
*
)
cptr
;
ctx_w
->
fctx
=
(
s
truct
Sass_File_C
ontext
*
)
cptr
;
}
else
{
}
else
{
ctx_w
->
ctx
=
(
sass_c
ontext
*
)
cptr
;
ctx_w
->
dctx
=
(
struct
Sass_Data_C
ontext
*
)
cptr
;
}
}
ctx_w
->
request
.
data
=
ctx_w
;
ctx_w
->
request
.
data
=
ctx_w
;
ctx_w
->
callback
=
new
NanCallback
(
callback
);
ctx_w
->
callback
=
new
NanCallback
(
callback
);
ctx_w
->
errorCallback
=
new
NanCallback
(
errorCallback
);
ctx_w
->
errorCallback
=
new
NanCallback
(
errorCallback
);
}
}
struct
Sass_Context
*
ctx
;
if
(
isFile
)
{
if
(
isFile
)
{
sass_file_context
*
ctx
=
(
sass_file_context
*
)
cptr
;
ctx
=
sass_file_context_get_context
((
struct
Sass_File_Context
*
)
cptr
);
ctx
->
input_path
=
CreateString
(
options
->
Get
(
NanNew
(
"file"
)));
ctx
->
output_path
=
CreateString
(
options
->
Get
(
NanNew
(
"outFile"
)));
ctx
->
options
.
image_path
=
CreateString
(
options
->
Get
(
NanNew
(
"imagePath"
)));
ctx
->
options
.
output_style
=
options
->
Get
(
NanNew
(
"style"
))
->
Int32Value
();
ctx
->
options
.
source_comments
=
source_comments
=
options
->
Get
(
NanNew
(
"comments"
))
->
BooleanValue
();
ctx
->
options
.
omit_source_map_url
=
options
->
Get
(
NanNew
(
"omitSourceMapUrl"
))
->
BooleanValue
();
ctx
->
options
.
source_map_file
=
CreateString
(
options
->
Get
(
NanNew
(
"sourceMap"
)));
ctx
->
options
.
include_paths
=
CreateString
(
options
->
Get
(
NanNew
(
"paths"
)));
ctx
->
options
.
precision
=
options
->
Get
(
NanNew
(
"precision"
))
->
Int32Value
();
}
else
{
}
else
{
sass_context
*
ctx
=
(
sass_context
*
)
cptr
;
ctx
=
sass_data_context_get_context
((
struct
Sass_Data_Context
*
)
cptr
);
ctx
->
source_string
=
CreateString
(
options
->
Get
(
NanNew
(
"data"
)));
ctx
->
output_path
=
CreateString
(
options
->
Get
(
NanNew
(
"outFile"
)));
ctx
->
options
.
is_indented_syntax_src
=
options
->
Get
(
NanNew
(
"indentedSyntax"
))
->
BooleanValue
();
ctx
->
options
.
image_path
=
CreateString
(
options
->
Get
(
NanNew
(
"imagePath"
)));
ctx
->
options
.
output_style
=
options
->
Get
(
NanNew
(
"style"
))
->
Int32Value
();
ctx
->
options
.
source_comments
=
source_comments
=
options
->
Get
(
NanNew
(
"comments"
))
->
BooleanValue
();
ctx
->
options
.
omit_source_map_url
=
options
->
Get
(
NanNew
(
"omitSourceMapUrl"
))
->
BooleanValue
();
ctx
->
options
.
source_map_file
=
CreateString
(
options
->
Get
(
NanNew
(
"sourceMap"
)));
ctx
->
options
.
include_paths
=
CreateString
(
options
->
Get
(
NanNew
(
"paths"
)));
ctx
->
options
.
precision
=
options
->
Get
(
NanNew
(
"precision"
))
->
Int32Value
();
}
}
struct
Sass_Options
*
sass_options
=
sass_context_get_options
(
ctx
);
sass_option_set_output_path
(
sass_options
,
CreateString
(
options
->
Get
(
NanNew
(
"outFile"
))));
sass_option_set_image_path
(
sass_options
,
CreateString
(
options
->
Get
(
NanNew
(
"imagePath"
))));
sass_option_set_output_style
(
sass_options
,
(
Sass_Output_Style
)
options
->
Get
(
NanNew
(
"style"
))
->
Int32Value
());
sass_option_set_is_indented_syntax_src
(
sass_options
,
options
->
Get
(
NanNew
(
"indentedSyntax"
))
->
BooleanValue
());
sass_option_set_source_comments
(
sass_options
,
options
->
Get
(
NanNew
(
"comments"
))
->
BooleanValue
());
sass_option_set_omit_source_map_url
(
sass_options
,
options
->
Get
(
NanNew
(
"omitSourceMapUrl"
))
->
BooleanValue
());
sass_option_set_source_map_embed
(
sass_options
,
options
->
Get
(
NanNew
(
"sourceMapEmbed"
))
->
BooleanValue
());
sass_option_set_source_map_contents
(
sass_options
,
options
->
Get
(
NanNew
(
"sourceMapContents"
))
->
BooleanValue
());
sass_option_set_source_map_file
(
sass_options
,
CreateString
(
options
->
Get
(
NanNew
(
"sourceMap"
))));
sass_option_set_include_path
(
sass_options
,
CreateString
(
options
->
Get
(
NanNew
(
"paths"
))));
sass_option_set_precision
(
sass_options
,
options
->
Get
(
NanNew
(
"precision"
))
->
Int32Value
());
}
}
template
<
typename
Ctx
>
void
FillStatsObj
(
Handle
<
Object
>
stats
,
Sass_Context
*
ctx
)
{
void
FillStatsObj
(
Handle
<
Object
>
stats
,
Ctx
ctx
)
{
char
**
included_files
=
sass_context_get_included_files
(
ctx
);
int
i
;
Handle
<
Array
>
arr
=
NanNew
<
Array
>
();
Handle
<
Array
>
arr
;
arr
=
NanNew
<
Array
>
(
ctx
->
num_included_files
);
if
(
included_files
)
{
for
(
i
=
0
;
i
<
ctx
->
num_included_files
;
i
++
)
{
for
(
int
i
=
0
;
included_files
[
i
]
!=
nullptr
;
++
i
)
{
arr
->
Set
(
i
,
NanNew
<
String
>
(
ctx
->
included_files
[
i
]));
arr
->
Set
(
i
,
NanNew
<
String
>
(
included_files
[
i
]));
}
}
}
(
*
stats
)
->
Set
(
NanNew
(
"includedFiles"
),
arr
);
(
*
stats
)
->
Set
(
NanNew
(
"includedFiles"
),
arr
);
}
void
FillStatsObj
(
Handle
<
Object
>
stats
,
sass_file_context
*
ctx
)
{
Handle
<
Value
>
source_map
;
Handle
<
Value
>
source_map
;
FillStatsObj
<
sass_file_context
*>
(
stats
,
ctx
);
if
(
sass_context_get_error_status
(
ctx
))
{
if
(
ctx
->
error_status
)
{
return
;
return
;
}
}
if
(
ctx
->
source_map_string
)
{
source_map
=
NanNew
<
String
>
(
ctx
->
source_map_string
);
if
(
sass_context_get_source_map_string
(
ctx
))
{
source_map
=
NanNew
<
String
>
(
sass_context_get_source_map_string
(
ctx
));
}
else
{
}
else
{
source_map
=
NanN
ull
(
);
source_map
=
NanN
ew
<
String
>
(
"{}"
);
}
}
(
*
stats
)
->
Set
(
NanNew
(
"sourceMap"
),
source_map
);
(
*
stats
)
->
Set
(
NanNew
(
"sourceMap"
),
source_map
);
}
}
...
@@ -109,17 +84,22 @@ void MakeCallback(uv_work_t* req) {
...
@@ -109,17 +84,22 @@ void MakeCallback(uv_work_t* req) {
TryCatch
try_catch
;
TryCatch
try_catch
;
sass_context_wrapper
*
ctx_w
=
static_cast
<
sass_context_wrapper
*>
(
req
->
data
);
sass_context_wrapper
*
ctx_w
=
static_cast
<
sass_context_wrapper
*>
(
req
->
data
);
int
error_status
=
ctx_w
->
ctx
?
ctx_w
->
ctx
->
error_status
:
ctx_w
->
fctx
->
error_status
;
int
error_status
;
struct
Sass_Context
*
ctx
;
if
(
ctx_w
->
ctx
)
{
if
(
ctx_w
->
dctx
)
{
FillStatsObj
(
NanNew
(
ctx_w
->
stats
),
ctx_w
->
ctx
);
ctx
=
sass_data_context_get_context
(
ctx_w
->
dctx
);
FillStatsObj
(
NanNew
(
ctx_w
->
stats
),
ctx
);
error_status
=
sass_context_get_error_status
(
ctx
);
}
else
{
}
else
{
FillStatsObj
(
NanNew
(
ctx_w
->
stats
),
ctx_w
->
fctx
);
ctx
=
sass_file_context_get_context
(
ctx_w
->
fctx
);
FillStatsObj
(
NanNew
(
ctx_w
->
stats
),
ctx
);
error_status
=
sass_context_get_error_status
(
ctx
);
}
}
if
(
error_status
==
0
)
{
if
(
error_status
==
0
)
{
// if no error, do callback(null, result)
// if no error, do callback(null, result)
c
har
*
val
=
ctx_w
->
ctx
?
ctx_w
->
ctx
->
output_string
:
ctx_w
->
fctx
->
output_string
;
c
onst
char
*
val
=
sass_context_get_output_string
(
ctx
)
;
Local
<
Value
>
argv
[]
=
{
Local
<
Value
>
argv
[]
=
{
NanNew
<
String
>
(
val
),
NanNew
<
String
>
(
val
),
NanNew
(
ctx_w
->
stats
)
->
Get
(
NanNew
(
"sourceMap"
))
NanNew
(
ctx_w
->
stats
)
->
Get
(
NanNew
(
"sourceMap"
))
...
@@ -127,7 +107,7 @@ void MakeCallback(uv_work_t* req) {
...
@@ -127,7 +107,7 @@ void MakeCallback(uv_work_t* req) {
ctx_w
->
callback
->
Call
(
2
,
argv
);
ctx_w
->
callback
->
Call
(
2
,
argv
);
}
else
{
}
else
{
// if error, do callback(error)
// if error, do callback(error)
c
har
*
err
=
ctx_w
->
ctx
?
ctx_w
->
ctx
->
error_message
:
ctx_w
->
fctx
->
error_message
;
c
onst
char
*
err
=
sass_context_get_error_json
(
ctx
)
;
Local
<
Value
>
argv
[]
=
{
Local
<
Value
>
argv
[]
=
{
NanNew
<
String
>
(
err
),
NanNew
<
String
>
(
err
),
NanNew
<
Integer
>
(
error_status
)
NanNew
<
Integer
>
(
error_status
)
...
@@ -137,18 +117,24 @@ void MakeCallback(uv_work_t* req) {
...
@@ -137,18 +117,24 @@ void MakeCallback(uv_work_t* req) {
if
(
try_catch
.
HasCaught
())
{
if
(
try_catch
.
HasCaught
())
{
node
::
FatalException
(
try_catch
);
node
::
FatalException
(
try_catch
);
}
}
sass_free_context_wrapper
(
ctx_w
);
sass_free_context_wrapper
(
ctx_w
);
}
}
NAN_METHOD
(
Render
)
{
NAN_METHOD
(
Render
)
{
NanScope
();
NanScope
();
sass_context
*
ctx
=
sass_new_context
();
Local
<
Object
>
options
=
args
[
0
]
->
ToObject
();
sass_context_wrapper
*
ctx_w
=
sass_new_context_wrapper
();
char
*
source_string
=
CreateString
(
options
->
Get
(
NanNew
(
"data"
)));
ctx_w
->
ctx
=
ctx
;
struct
Sass_Data_Context
*
dctx
=
sass_make_data_context
(
source_string
);
ExtractOptions
(
args
[
0
],
ctx
,
ctx_w
,
false
);
sass_context_wrapper
*
ctx_w
=
sass_make_context_wrapper
();
ctx_w
->
dctx
=
dctx
;
ExtractOptions
(
options
,
dctx
,
ctx_w
,
false
);
int
status
=
uv_queue_work
(
uv_default_loop
(),
&
ctx_w
->
request
,
compile_it
,
(
uv_after_work_cb
)
MakeCallback
);
int
status
=
uv_queue_work
(
uv_default_loop
(),
&
ctx_w
->
request
,
WorkOnContext
,
(
uv_after_work_cb
)
MakeCallback
);
assert
(
status
==
0
);
assert
(
status
==
0
);
NanReturnUndefined
();
NanReturnUndefined
();
...
@@ -156,58 +142,75 @@ NAN_METHOD(Render) {
...
@@ -156,58 +142,75 @@ NAN_METHOD(Render) {
NAN_METHOD
(
RenderSync
)
{
NAN_METHOD
(
RenderSync
)
{
NanScope
();
NanScope
();
Handle
<
Object
>
options
=
args
[
0
]
->
ToObject
();
sass_context
*
ctx
=
sass_new_context
();
ExtractOptions
(
args
[
0
],
ctx
,
NULL
,
false
);
sass_compile
(
ctx
);
Local
<
Object
>
options
=
args
[
0
]
->
ToObject
();
char
*
source_string
=
CreateString
(
options
->
Get
(
NanNew
(
"data"
)));
struct
Sass_Data_Context
*
dctx
=
sass_make_data_context
(
source_string
);
struct
Sass_Context
*
ctx
=
sass_data_context_get_context
(
dctx
);
ExtractOptions
(
options
,
dctx
,
NULL
,
false
);
compile_data
(
dctx
);
FillStatsObj
(
options
->
Get
(
NanNew
(
"stats"
))
->
ToObject
(),
ctx
);
FillStatsObj
(
options
->
Get
(
NanNew
(
"stats"
))
->
ToObject
(),
ctx
);
if
(
ctx
->
error_status
==
0
)
{
if
(
sass_context_get_error_status
(
ctx
)
==
0
)
{
Local
<
String
>
output
=
NanNew
<
String
>
(
ctx
->
output_string
);
Local
<
String
>
output
=
NanNew
<
String
>
(
sass_context_get_output_string
(
ctx
));
free_context
(
ctx
);
sass_delete_data_context
(
dctx
);
NanReturnValue
(
output
);
NanReturnValue
(
output
);
}
}
Local
<
String
>
error
=
NanNew
<
String
>
(
ctx
->
error_message
);
Local
<
String
>
error
=
NanNew
<
String
>
(
sass_context_get_error_json
(
ctx
));
free_context
(
ctx
);
sass_delete_data_context
(
dctx
);
NanThrowError
(
error
);
NanThrowError
(
error
);
NanReturnUndefined
();
NanReturnUndefined
();
}
}
NAN_METHOD
(
RenderFile
)
{
NAN_METHOD
(
RenderFile
)
{
NanScope
();
NanScope
();
sass_file_context
*
fctx
=
sass_new_file_context
();
sass_context_wrapper
*
ctx_w
=
sass_new_context_wrapper
();
Local
<
Object
>
options
=
args
[
0
]
->
ToObject
();
char
*
input_path
=
CreateString
(
options
->
Get
(
NanNew
(
"file"
)));
struct
Sass_File_Context
*
fctx
=
sass_make_file_context
(
input_path
);
sass_context_wrapper
*
ctx_w
=
sass_make_context_wrapper
();
ctx_w
->
fctx
=
fctx
;
ctx_w
->
fctx
=
fctx
;
ExtractOptions
(
args
[
0
],
fctx
,
ctx_w
,
true
);
ExtractOptions
(
options
,
fctx
,
ctx_w
,
true
);
int
status
=
uv_queue_work
(
uv_default_loop
(),
&
ctx_w
->
request
,
compile_it
,
(
uv_after_work_cb
)
MakeCallback
);
int
status
=
uv_queue_work
(
uv_default_loop
(),
&
ctx_w
->
request
,
WorkOnContext
,
(
uv_after_work_cb
)
MakeCallback
);
assert
(
status
==
0
);
assert
(
status
==
0
);
free
(
input_path
);
NanReturnUndefined
();
NanReturnUndefined
();
}
}
NAN_METHOD
(
RenderFileSync
)
{
NAN_METHOD
(
RenderFileSync
)
{
NanScope
();
NanScope
();
sass_file_context
*
ctx
=
sass_new_file_context
();
ExtractOptions
(
args
[
0
],
ctx
,
NULL
,
true
);
Handle
<
Object
>
options
=
args
[
0
]
->
ToObject
();
sass_compile_file
(
ctx
);
Local
<
Object
>
options
=
args
[
0
]
->
ToObject
();
char
*
input_path
=
CreateString
(
options
->
Get
(
NanNew
(
"file"
)));
struct
Sass_File_Context
*
fctx
=
sass_make_file_context
(
input_path
);
struct
Sass_Context
*
ctx
=
sass_file_context_get_context
(
fctx
);
ExtractOptions
(
options
,
fctx
,
NULL
,
true
);
compile_file
(
fctx
);
FillStatsObj
(
options
->
Get
(
NanNew
(
"stats"
))
->
ToObject
(),
ctx
);
FillStatsObj
(
options
->
Get
(
NanNew
(
"stats"
))
->
ToObject
(),
ctx
);
free
(
input_path
);
if
(
ctx
->
error_status
==
0
)
{
if
(
sass_context_get_error_status
(
ctx
)
==
0
)
{
Local
<
String
>
output
=
NanNew
<
String
>
(
ctx
->
output_string
);
Local
<
String
>
output
=
NanNew
<
String
>
(
sass_context_get_output_string
(
ctx
));
free_file_context
(
ctx
);
sass_delete_file_context
(
fctx
);
NanReturnValue
(
output
);
NanReturnValue
(
output
);
}
}
Local
<
String
>
error
=
NanNew
<
String
>
(
ctx
->
error_message
);
Local
<
String
>
error
=
NanNew
<
String
>
(
sass_context_get_error_json
(
ctx
));
free_file_context
(
ctx
);
sass_delete_file_context
(
fctx
);
NanThrowError
(
error
);
NanThrowError
(
error
);
NanReturnUndefined
();
NanReturnUndefined
();
}
}
...
...
src/sass_context_wrapper.cpp
View file @
7c354bf6
#include "sass_context_wrapper.h"
#include "sass_context_wrapper.h"
#include <nan.h>
#include <cstdlib>
extern
"C"
{
extern
"C"
{
using
namespace
std
;
using
namespace
std
;
void
free_context
(
sass_context
*
ctx
)
{
void
compile_it
(
uv_work_t
*
req
)
{
delete
[]
ctx
->
source_string
;
sass_context_wrapper
*
ctx_w
=
static_cast
<
sass_context_wrapper
*>
(
req
->
data
);
delete
[]
ctx
->
options
.
include_paths
;
delete
[]
ctx
->
options
.
image_path
;
if
(
ctx_w
->
dctx
)
{
sass_free_context
(
ctx
);
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
)
{
void
compile_file
(
struct
Sass_File_Context
*
fctx
)
{
delete
[]
fctx
->
input_path
;
sass_compile_file_context
(
fctx
);
delete
[]
fctx
->
options
.
include_paths
;
delete
[]
fctx
->
options
.
image_path
;
sass_free_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
));
return
(
sass_context_wrapper
*
)
calloc
(
1
,
sizeof
(
sass_context_wrapper
));
}
}
void
sass_free_context_wrapper
(
sass_context_wrapper
*
ctx_w
)
{
void
sass_free_context_wrapper
(
sass_context_wrapper
*
ctx_w
)
{
if
(
ctx_w
->
ctx
)
{
if
(
ctx_w
->
d
ctx
)
{
free_context
(
ctx_w
->
ctx
);
sass_delete_data_context
(
ctx_w
->
d
ctx
);
}
else
if
(
ctx_w
->
fctx
)
{
}
else
if
(
ctx_w
->
fctx
)
{
fre
e_file_context
(
ctx_w
->
fctx
);
sass_delet
e_file_context
(
ctx_w
->
fctx
);
}
}
NanDisposePersistent
(
ctx_w
->
stats
);
NanDisposePersistent
(
ctx_w
->
stats
);
...
...
src/sass_context_wrapper.h
View file @
7c354bf6
#include "libsass/sass_interface.h"
#include <nan.h>
#include <nan.h>
#include "libsass/sass_context.h"
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
@@ -7,20 +7,21 @@ extern "C" {
...
@@ -7,20 +7,21 @@ extern "C" {
using
namespace
v8
;
using
namespace
v8
;
void
free_context
(
sass_context
*
ctx
);
void
compile_data
(
struct
Sass_Data_Context
*
dctx
);
void
free_file_context
(
sass_file_context
*
fctx
);
void
compile_file
(
struct
Sass_File_Context
*
fctx
);
void
compile_it
(
uv_work_t
*
req
);
struct
sass_context_wrapper
{
struct
sass_context_wrapper
{
sass_context
*
ctx
;
Sass_Data_Context
*
d
ctx
;
sass_file_c
ontext
*
fctx
;
Sass_File_C
ontext
*
fctx
;
Persistent
<
Object
>
stats
;
Persistent
<
Object
>
stats
;
uv_work_t
request
;
uv_work_t
request
;
NanCallback
*
callback
;
NanCallback
*
callback
;
NanCallback
*
errorCallback
;
NanCallback
*
errorCallback
;
};
};
struct
sass_context_wrapper
*
sass_
new
_context_wrapper
(
void
);
struct
sass_context_wrapper
*
sass_
make
_context_wrapper
(
void
);
void
sass_free_context_wrapper
(
struct
sass_context_wrapper
*
ctx
);
void
sass_free_context_wrapper
(
struct
sass_context_wrapper
*
ctx
_w
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
test/api.js
View file @
7c354bf6
...
@@ -187,8 +187,7 @@ describe('api', function() {
...
@@ -187,8 +187,7 @@ describe('api', function() {
var
stats
=
{};
var
stats
=
{};
var
expected
=
[
var
expected
=
[
fixture
(
'include-files/bar.scss'
).
replace
(
/
\\
/g
,
'/'
),
fixture
(
'include-files/bar.scss'
).
replace
(
/
\\
/g
,
'/'
),
fixture
(
'include-files/foo.scss'
).
replace
(
/
\\
/g
,
'/'
),
fixture
(
'include-files/foo.scss'
).
replace
(
/
\\
/g
,
'/'
)
'stdin'
];
];
sass
.
render
({
sass
.
render
({
...
@@ -422,8 +421,7 @@ describe('api', function() {
...
@@ -422,8 +421,7 @@ describe('api', function() {
stats
:
stats
,
stats
:
stats
,
sourceMap
:
true
,
sourceMap
:
true
,
success
:
function
()
{
success
:
function
()
{
var
map
=
JSON
.
parse
(
stats
.
sourceMap
);
assert
.
equal
(
stats
.
sourceMap
.
sources
[
0
],
'index.scss'
);
assert
.
equal
(
map
.
sources
[
0
],
'index.scss'
);
done
();
done
();
}
}
});
});
...
@@ -517,8 +515,7 @@ describe('api', function() {
...
@@ -517,8 +515,7 @@ describe('api', function() {
sourceMap
:
true
sourceMap
:
true
});
});
var
map
=
JSON
.
parse
(
stats
.
sourceMap
);
assert
.
equal
(
stats
.
sourceMap
.
sources
[
0
],
'index.scss'
);
assert
.
equal
(
map
.
sources
[
0
],
'index.scss'
);
done
();
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