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
6ccc708b
Commit
6ccc708b
authored
Feb 15, 2015
by
Adeel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code: Uses more C++ style nomenclature.
parent
50f374df
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
41 deletions
+41
-41
binding.cpp
src/binding.cpp
+41
-41
No files found.
src/binding.cpp
View file @
6ccc708b
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#include <vector>
#include <vector>
#include "sass_context_wrapper.h"
#include "sass_context_wrapper.h"
char
*
CreateS
tring
(
Local
<
Value
>
value
)
{
char
*
create_s
tring
(
Local
<
Value
>
value
)
{
if
(
value
->
IsNull
()
||
!
value
->
IsString
())
{
if
(
value
->
IsNull
()
||
!
value
->
IsString
())
{
return
0
;
return
0
;
}
}
...
@@ -30,8 +30,8 @@ void prepare_import_results(Local<Value> returned_value, sass_context_wrapper* c
...
@@ -30,8 +30,8 @@ void prepare_import_results(Local<Value> returned_value, sass_context_wrapper* c
continue
;
continue
;
Local
<
Object
>
object
=
Local
<
Object
>::
Cast
(
value
);
Local
<
Object
>
object
=
Local
<
Object
>::
Cast
(
value
);
char
*
path
=
CreateS
tring
(
object
->
Get
(
NanNew
<
String
>
(
"file"
)));
char
*
path
=
create_s
tring
(
object
->
Get
(
NanNew
<
String
>
(
"file"
)));
char
*
contents
=
CreateS
tring
(
object
->
Get
(
NanNew
<
String
>
(
"contents"
)));
char
*
contents
=
create_s
tring
(
object
->
Get
(
NanNew
<
String
>
(
"contents"
)));
ctx_w
->
imports
[
i
]
=
sass_make_import_entry
(
path
,
(
!
contents
||
contents
[
0
]
==
'\0'
)
?
0
:
strdup
(
contents
),
0
);
ctx_w
->
imports
[
i
]
=
sass_make_import_entry
(
path
,
(
!
contents
||
contents
[
0
]
==
'\0'
)
?
0
:
strdup
(
contents
),
0
);
}
}
...
@@ -39,8 +39,8 @@ void prepare_import_results(Local<Value> returned_value, sass_context_wrapper* c
...
@@ -39,8 +39,8 @@ void prepare_import_results(Local<Value> returned_value, sass_context_wrapper* c
else
if
(
returned_value
->
IsObject
())
{
else
if
(
returned_value
->
IsObject
())
{
ctx_w
->
imports
=
sass_make_import_list
(
1
);
ctx_w
->
imports
=
sass_make_import_list
(
1
);
Local
<
Object
>
object
=
Local
<
Object
>::
Cast
(
returned_value
);
Local
<
Object
>
object
=
Local
<
Object
>::
Cast
(
returned_value
);
char
*
path
=
CreateS
tring
(
object
->
Get
(
NanNew
<
String
>
(
"file"
)));
char
*
path
=
create_s
tring
(
object
->
Get
(
NanNew
<
String
>
(
"file"
)));
char
*
contents
=
CreateS
tring
(
object
->
Get
(
NanNew
<
String
>
(
"contents"
)));
char
*
contents
=
create_s
tring
(
object
->
Get
(
NanNew
<
String
>
(
"contents"
)));
ctx_w
->
imports
[
0
]
=
sass_make_import_entry
(
path
,
(
!
contents
||
contents
[
0
]
==
'\0'
)
?
0
:
strdup
(
contents
),
0
);
ctx_w
->
imports
[
0
]
=
sass_make_import_entry
(
path
,
(
!
contents
||
contents
[
0
]
==
'\0'
)
?
0
:
strdup
(
contents
),
0
);
}
}
...
@@ -106,14 +106,14 @@ struct Sass_Import** sass_importer(const char* file, const char* prev, void* coo
...
@@ -106,14 +106,14 @@ struct Sass_Import** sass_importer(const char* file, const char* prev, void* coo
return
ctx_w
->
imports
;
return
ctx_w
->
imports
;
}
}
void
ExtractOptions
(
Local
<
Object
>
options
,
void
*
cptr
,
sass_context_wrapper
*
ctx_w
,
bool
isFile
,
bool
isS
ync
)
{
void
extract_options
(
Local
<
Object
>
options
,
void
*
cptr
,
sass_context_wrapper
*
ctx_w
,
bool
is_file
,
bool
is_s
ync
)
{
NanScope
();
NanScope
();
struct
Sass_Context
*
ctx
;
struct
Sass_Context
*
ctx
;
NanAssignPersistent
(
ctx_w
->
result
,
options
->
Get
(
NanNew
(
"result"
))
->
ToObject
());
NanAssignPersistent
(
ctx_w
->
result
,
options
->
Get
(
NanNew
(
"result"
))
->
ToObject
());
if
(
is
F
ile
)
{
if
(
is
_f
ile
)
{
ctx_w
->
fctx
=
(
struct
Sass_File_Context
*
)
cptr
;
ctx_w
->
fctx
=
(
struct
Sass_File_Context
*
)
cptr
;
ctx
=
sass_file_context_get_context
(
ctx_w
->
fctx
);
ctx
=
sass_file_context_get_context
(
ctx_w
->
fctx
);
}
}
...
@@ -125,9 +125,9 @@ void ExtractOptions(Local<Object> options, void* cptr, sass_context_wrapper* ctx
...
@@ -125,9 +125,9 @@ void ExtractOptions(Local<Object> options, void* cptr, sass_context_wrapper* ctx
struct
Sass_Options
*
sass_options
=
sass_context_get_options
(
ctx
);
struct
Sass_Options
*
sass_options
=
sass_context_get_options
(
ctx
);
ctx_w
->
importer_callback
=
NULL
;
ctx_w
->
importer_callback
=
NULL
;
ctx_w
->
is_sync
=
is
S
ync
;
ctx_w
->
is_sync
=
is
_s
ync
;
if
(
!
is
S
ync
)
{
if
(
!
is
_s
ync
)
{
ctx_w
->
request
.
data
=
ctx_w
;
ctx_w
->
request
.
data
=
ctx_w
;
// async (callback) style
// async (callback) style
...
@@ -146,24 +146,24 @@ void ExtractOptions(Local<Object> options, void* cptr, sass_context_wrapper* ctx
...
@@ -146,24 +146,24 @@ void ExtractOptions(Local<Object> options, void* cptr, sass_context_wrapper* ctx
sass_option_set_importer
(
sass_options
,
sass_make_importer
(
sass_importer
,
ctx_w
));
sass_option_set_importer
(
sass_options
,
sass_make_importer
(
sass_importer
,
ctx_w
));
}
}
if
(
!
is
F
ile
)
{
if
(
!
is
_f
ile
)
{
sass_option_set_input_path
(
sass_options
,
CreateS
tring
(
options
->
Get
(
NanNew
(
"file"
))));
sass_option_set_input_path
(
sass_options
,
create_s
tring
(
options
->
Get
(
NanNew
(
"file"
))));
}
}
sass_option_set_output_path
(
sass_options
,
CreateS
tring
(
options
->
Get
(
NanNew
(
"outFile"
))));
sass_option_set_output_path
(
sass_options
,
create_s
tring
(
options
->
Get
(
NanNew
(
"outFile"
))));
sass_option_set_image_path
(
sass_options
,
CreateS
tring
(
options
->
Get
(
NanNew
(
"imagePath"
))));
sass_option_set_image_path
(
sass_options
,
create_s
tring
(
options
->
Get
(
NanNew
(
"imagePath"
))));
sass_option_set_output_style
(
sass_options
,
(
Sass_Output_Style
)
options
->
Get
(
NanNew
(
"style"
))
->
Int32Value
());
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_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_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_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_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_contents
(
sass_options
,
options
->
Get
(
NanNew
(
"sourceMapContents"
))
->
BooleanValue
());
sass_option_set_source_map_file
(
sass_options
,
CreateS
tring
(
options
->
Get
(
NanNew
(
"sourceMap"
))));
sass_option_set_source_map_file
(
sass_options
,
create_s
tring
(
options
->
Get
(
NanNew
(
"sourceMap"
))));
sass_option_set_include_path
(
sass_options
,
CreateS
tring
(
options
->
Get
(
NanNew
(
"paths"
))));
sass_option_set_include_path
(
sass_options
,
create_s
tring
(
options
->
Get
(
NanNew
(
"paths"
))));
sass_option_set_precision
(
sass_options
,
options
->
Get
(
NanNew
(
"precision"
))
->
Int32Value
());
sass_option_set_precision
(
sass_options
,
options
->
Get
(
NanNew
(
"precision"
))
->
Int32Value
());
}
}
void
GetS
tats
(
sass_context_wrapper
*
ctx_w
,
Sass_Context
*
ctx
)
{
void
get_s
tats
(
sass_context_wrapper
*
ctx_w
,
Sass_Context
*
ctx
)
{
NanScope
();
NanScope
();
char
**
included_files
=
sass_context_get_included_files
(
ctx
);
char
**
included_files
=
sass_context_get_included_files
(
ctx
);
...
@@ -178,7 +178,7 @@ void GetStats(sass_context_wrapper* ctx_w, Sass_Context* ctx) {
...
@@ -178,7 +178,7 @@ void GetStats(sass_context_wrapper* ctx_w, Sass_Context* ctx) {
NanNew
(
ctx_w
->
result
)
->
Get
(
NanNew
(
"stats"
))
->
ToObject
()
->
Set
(
NanNew
(
"includedFiles"
),
arr
);
NanNew
(
ctx_w
->
result
)
->
Get
(
NanNew
(
"stats"
))
->
ToObject
()
->
Set
(
NanNew
(
"includedFiles"
),
arr
);
}
}
void
GetSourceM
ap
(
sass_context_wrapper
*
ctx_w
,
Sass_Context
*
ctx
)
{
void
get_source_m
ap
(
sass_context_wrapper
*
ctx_w
,
Sass_Context
*
ctx
)
{
NanScope
();
NanScope
();
Handle
<
Value
>
source_map
;
Handle
<
Value
>
source_map
;
...
@@ -197,15 +197,15 @@ void GetSourceMap(sass_context_wrapper* ctx_w, Sass_Context* ctx) {
...
@@ -197,15 +197,15 @@ void GetSourceMap(sass_context_wrapper* ctx_w, Sass_Context* ctx) {
NanNew
(
ctx_w
->
result
)
->
Set
(
NanNew
(
"map"
),
source_map
);
NanNew
(
ctx_w
->
result
)
->
Set
(
NanNew
(
"map"
),
source_map
);
}
}
int
GetR
esult
(
sass_context_wrapper
*
ctx_w
,
Sass_Context
*
ctx
,
bool
is_sync
=
false
)
{
int
get_r
esult
(
sass_context_wrapper
*
ctx_w
,
Sass_Context
*
ctx
,
bool
is_sync
=
false
)
{
NanScope
();
NanScope
();
int
status
=
sass_context_get_error_status
(
ctx
);
int
status
=
sass_context_get_error_status
(
ctx
);
if
(
status
==
0
)
{
if
(
status
==
0
)
{
NanNew
(
ctx_w
->
result
)
->
Set
(
NanNew
(
"css"
),
NanNew
<
String
>
(
sass_context_get_output_string
(
ctx
)));
NanNew
(
ctx_w
->
result
)
->
Set
(
NanNew
(
"css"
),
NanNew
<
String
>
(
sass_context_get_output_string
(
ctx
)));
GetS
tats
(
ctx_w
,
ctx
);
get_s
tats
(
ctx_w
,
ctx
);
GetSourceM
ap
(
ctx_w
,
ctx
);
get_source_m
ap
(
ctx_w
,
ctx
);
}
}
else
if
(
is_sync
)
{
else
if
(
is_sync
)
{
NanNew
(
ctx_w
->
result
)
->
Set
(
NanNew
(
"error"
),
NanNew
<
String
>
(
sass_context_get_error_json
(
ctx
)));
NanNew
(
ctx_w
->
result
)
->
Set
(
NanNew
(
"error"
),
NanNew
<
String
>
(
sass_context_get_error_json
(
ctx
)));
...
@@ -228,7 +228,7 @@ void make_callback(uv_work_t* req) {
...
@@ -228,7 +228,7 @@ void make_callback(uv_work_t* req) {
ctx
=
sass_file_context_get_context
(
ctx_w
->
fctx
);
ctx
=
sass_file_context_get_context
(
ctx_w
->
fctx
);
}
}
int
status
=
GetR
esult
(
ctx_w
,
ctx
);
int
status
=
get_r
esult
(
ctx_w
,
ctx
);
if
(
status
==
0
&&
ctx_w
->
success_callback
)
{
if
(
status
==
0
&&
ctx_w
->
success_callback
)
{
// if no error, do callback(null, result)
// if no error, do callback(null, result)
...
@@ -253,15 +253,15 @@ void make_callback(uv_work_t* req) {
...
@@ -253,15 +253,15 @@ void make_callback(uv_work_t* req) {
sass_free_context_wrapper
(
ctx_w
);
sass_free_context_wrapper
(
ctx_w
);
}
}
NAN_METHOD
(
R
ender
)
{
NAN_METHOD
(
r
ender
)
{
NanScope
();
NanScope
();
Local
<
Object
>
options
=
args
[
0
]
->
ToObject
();
Local
<
Object
>
options
=
args
[
0
]
->
ToObject
();
char
*
source_string
=
CreateS
tring
(
options
->
Get
(
NanNew
(
"data"
)));
char
*
source_string
=
create_s
tring
(
options
->
Get
(
NanNew
(
"data"
)));
struct
Sass_Data_Context
*
dctx
=
sass_make_data_context
(
source_string
);
struct
Sass_Data_Context
*
dctx
=
sass_make_data_context
(
source_string
);
sass_context_wrapper
*
ctx_w
=
sass_make_context_wrapper
();
sass_context_wrapper
*
ctx_w
=
sass_make_context_wrapper
();
ExtractO
ptions
(
options
,
dctx
,
ctx_w
,
false
,
false
);
extract_o
ptions
(
options
,
dctx
,
ctx_w
,
false
,
false
);
int
status
=
uv_queue_work
(
uv_default_loop
(),
&
ctx_w
->
request
,
compile_it
,
(
uv_after_work_cb
)
make_callback
);
int
status
=
uv_queue_work
(
uv_default_loop
(),
&
ctx_w
->
request
,
compile_it
,
(
uv_after_work_cb
)
make_callback
);
...
@@ -270,35 +270,35 @@ NAN_METHOD(Render) {
...
@@ -270,35 +270,35 @@ NAN_METHOD(Render) {
NanReturnUndefined
();
NanReturnUndefined
();
}
}
NAN_METHOD
(
RenderS
ync
)
{
NAN_METHOD
(
render_s
ync
)
{
NanScope
();
NanScope
();
Local
<
Object
>
options
=
args
[
0
]
->
ToObject
();
Local
<
Object
>
options
=
args
[
0
]
->
ToObject
();
char
*
source_string
=
CreateS
tring
(
options
->
Get
(
NanNew
(
"data"
)));
char
*
source_string
=
create_s
tring
(
options
->
Get
(
NanNew
(
"data"
)));
struct
Sass_Data_Context
*
dctx
=
sass_make_data_context
(
source_string
);
struct
Sass_Data_Context
*
dctx
=
sass_make_data_context
(
source_string
);
struct
Sass_Context
*
ctx
=
sass_data_context_get_context
(
dctx
);
struct
Sass_Context
*
ctx
=
sass_data_context_get_context
(
dctx
);
sass_context_wrapper
*
ctx_w
=
sass_make_context_wrapper
();
sass_context_wrapper
*
ctx_w
=
sass_make_context_wrapper
();
ExtractO
ptions
(
options
,
dctx
,
ctx_w
,
false
,
true
);
extract_o
ptions
(
options
,
dctx
,
ctx_w
,
false
,
true
);
compile_data
(
dctx
);
compile_data
(
dctx
);
int
result
=
GetR
esult
(
ctx_w
,
ctx
,
true
);
int
result
=
get_r
esult
(
ctx_w
,
ctx
,
true
);
sass_wrapper_dispose
(
ctx_w
,
source_string
);
sass_wrapper_dispose
(
ctx_w
,
source_string
);
NanReturnValue
(
NanNew
<
Boolean
>
(
result
==
0
));
NanReturnValue
(
NanNew
<
Boolean
>
(
result
==
0
));
}
}
NAN_METHOD
(
RenderF
ile
)
{
NAN_METHOD
(
render_f
ile
)
{
NanScope
();
NanScope
();
Local
<
Object
>
options
=
args
[
0
]
->
ToObject
();
Local
<
Object
>
options
=
args
[
0
]
->
ToObject
();
char
*
input_path
=
CreateS
tring
(
options
->
Get
(
NanNew
(
"file"
)));
char
*
input_path
=
create_s
tring
(
options
->
Get
(
NanNew
(
"file"
)));
struct
Sass_File_Context
*
fctx
=
sass_make_file_context
(
input_path
);
struct
Sass_File_Context
*
fctx
=
sass_make_file_context
(
input_path
);
sass_context_wrapper
*
ctx_w
=
sass_make_context_wrapper
();
sass_context_wrapper
*
ctx_w
=
sass_make_context_wrapper
();
ExtractO
ptions
(
options
,
fctx
,
ctx_w
,
true
,
false
);
extract_o
ptions
(
options
,
fctx
,
ctx_w
,
true
,
false
);
int
status
=
uv_queue_work
(
uv_default_loop
(),
&
ctx_w
->
request
,
compile_it
,
(
uv_after_work_cb
)
make_callback
);
int
status
=
uv_queue_work
(
uv_default_loop
(),
&
ctx_w
->
request
,
compile_it
,
(
uv_after_work_cb
)
make_callback
);
...
@@ -307,26 +307,26 @@ NAN_METHOD(RenderFile) {
...
@@ -307,26 +307,26 @@ NAN_METHOD(RenderFile) {
NanReturnUndefined
();
NanReturnUndefined
();
}
}
NAN_METHOD
(
RenderFileS
ync
)
{
NAN_METHOD
(
render_file_s
ync
)
{
NanScope
();
NanScope
();
Local
<
Object
>
options
=
args
[
0
]
->
ToObject
();
Local
<
Object
>
options
=
args
[
0
]
->
ToObject
();
char
*
input_path
=
CreateS
tring
(
options
->
Get
(
NanNew
(
"file"
)));
char
*
input_path
=
create_s
tring
(
options
->
Get
(
NanNew
(
"file"
)));
struct
Sass_File_Context
*
fctx
=
sass_make_file_context
(
input_path
);
struct
Sass_File_Context
*
fctx
=
sass_make_file_context
(
input_path
);
struct
Sass_Context
*
ctx
=
sass_file_context_get_context
(
fctx
);
struct
Sass_Context
*
ctx
=
sass_file_context_get_context
(
fctx
);
sass_context_wrapper
*
ctx_w
=
sass_make_context_wrapper
();
sass_context_wrapper
*
ctx_w
=
sass_make_context_wrapper
();
ExtractO
ptions
(
options
,
fctx
,
ctx_w
,
true
,
true
);
extract_o
ptions
(
options
,
fctx
,
ctx_w
,
true
,
true
);
compile_file
(
fctx
);
compile_file
(
fctx
);
int
result
=
GetR
esult
(
ctx_w
,
ctx
,
true
);
int
result
=
get_r
esult
(
ctx_w
,
ctx
,
true
);
sass_wrapper_dispose
(
ctx_w
,
input_path
);
sass_wrapper_dispose
(
ctx_w
,
input_path
);
NanReturnValue
(
NanNew
<
Boolean
>
(
result
==
0
));
NanReturnValue
(
NanNew
<
Boolean
>
(
result
==
0
));
}
}
NAN_METHOD
(
ImportedC
allback
)
{
NAN_METHOD
(
imported_c
allback
)
{
NanScope
();
NanScope
();
TryCatch
try_catch
;
TryCatch
try_catch
;
...
@@ -352,11 +352,11 @@ NAN_METHOD(ImportedCallback) {
...
@@ -352,11 +352,11 @@ NAN_METHOD(ImportedCallback) {
}
}
void
RegisterModule
(
v8
::
Handle
<
v8
::
Object
>
target
)
{
void
RegisterModule
(
v8
::
Handle
<
v8
::
Object
>
target
)
{
NODE_SET_METHOD
(
target
,
"render"
,
R
ender
);
NODE_SET_METHOD
(
target
,
"render"
,
r
ender
);
NODE_SET_METHOD
(
target
,
"renderSync"
,
RenderS
ync
);
NODE_SET_METHOD
(
target
,
"renderSync"
,
render_s
ync
);
NODE_SET_METHOD
(
target
,
"renderFile"
,
RenderF
ile
);
NODE_SET_METHOD
(
target
,
"renderFile"
,
render_f
ile
);
NODE_SET_METHOD
(
target
,
"renderFileSync"
,
RenderFileS
ync
);
NODE_SET_METHOD
(
target
,
"renderFileSync"
,
render_file_s
ync
);
NODE_SET_METHOD
(
target
,
"importedCallback"
,
ImportedC
allback
);
NODE_SET_METHOD
(
target
,
"importedCallback"
,
imported_c
allback
);
}
}
NODE_MODULE
(
binding
,
RegisterModule
);
NODE_MODULE
(
binding
,
RegisterModule
);
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