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
45ad189a
Commit
45ad189a
authored
May 02, 2013
by
Brett Wilkins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding new API
parent
ed6fd4dc
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
316 additions
and
18 deletions
+316
-18
binding.cpp
binding.cpp
+152
-2
binding.node
precompiled/darwin-x64/binding.node
+0
-0
sass.js
sass.js
+49
-8
sass_context_wrapper.cpp
sass_context_wrapper.cpp
+12
-0
sass_context_wrapper.h
sass_context_wrapper.h
+11
-0
sample.scss
test/sample.scss
+11
-7
test.js
test/test.js
+81
-1
No files found.
binding.cpp
View file @
45ad189a
...
...
@@ -16,7 +16,7 @@ void WorkOnContext(uv_work_t* req) {
sass_compile
(
ctx
);
}
void
MakeCallback
(
uv_work_t
*
req
)
{
void
Make
Old
Callback
(
uv_work_t
*
req
)
{
HandleScope
scope
;
TryCatch
try_catch
;
sass_context_wrapper
*
ctx_w
=
static_cast
<
sass_context_wrapper
*>
(
req
->
data
);
...
...
@@ -46,7 +46,7 @@ void MakeCallback(uv_work_t* req) {
sass_free_context_wrapper
(
ctx_w
);
}
Handle
<
Value
>
Render
(
const
Arguments
&
args
)
{
Handle
<
Value
>
Old
Render
(
const
Arguments
&
args
)
{
HandleScope
scope
;
sass_context
*
ctx
=
sass_new_context
();
sass_context_wrapper
*
ctx_w
=
sass_new_context_wrapper
();
...
...
@@ -66,6 +66,63 @@ Handle<Value> Render(const Arguments& args) {
ctx_w
->
callback
=
Persistent
<
Function
>::
New
(
callback
);
ctx_w
->
request
.
data
=
ctx_w
;
int
status
=
uv_queue_work
(
uv_default_loop
(),
&
ctx_w
->
request
,
WorkOnContext
,
(
uv_after_work_cb
)
MakeOldCallback
);
assert
(
status
==
0
);
return
scope
.
Close
(
Undefined
());
}
void
MakeCallback
(
uv_work_t
*
req
)
{
HandleScope
scope
;
TryCatch
try_catch
;
sass_context_wrapper
*
ctx_w
=
static_cast
<
sass_context_wrapper
*>
(
req
->
data
);
sass_context
*
ctx
=
static_cast
<
sass_context
*>
(
ctx_w
->
ctx
);
if
(
ctx
->
error_status
==
0
)
{
// if no error, do callback(null, result)
const
unsigned
argc
=
1
;
Local
<
Value
>
argv
[
argc
]
=
{
Local
<
Value
>::
New
(
String
::
New
(
ctx
->
output_string
))
};
ctx_w
->
callback
->
Call
(
Context
::
GetCurrent
()
->
Global
(),
argc
,
argv
);
}
else
{
// if error, do callback(error)
const
unsigned
argc
=
1
;
Local
<
Value
>
argv
[
argc
]
=
{
Local
<
Value
>::
New
(
String
::
New
(
ctx
->
error_message
))
};
ctx_w
->
errorCallback
->
Call
(
Context
::
GetCurrent
()
->
Global
(),
argc
,
argv
);
}
if
(
try_catch
.
HasCaught
())
{
node
::
FatalException
(
try_catch
);
}
sass_free_context_wrapper
(
ctx_w
);
}
Handle
<
Value
>
Render
(
const
Arguments
&
args
)
{
HandleScope
scope
;
sass_context
*
ctx
=
sass_new_context
();
sass_context_wrapper
*
ctx_w
=
sass_new_context_wrapper
();
char
*
source
;
String
::
AsciiValue
astr
(
args
[
0
]);
Local
<
Function
>
callback
=
Local
<
Function
>::
Cast
(
args
[
1
]);
Local
<
Function
>
errorCallback
=
Local
<
Function
>::
Cast
(
args
[
2
]);
String
::
AsciiValue
bstr
(
args
[
3
]);
source
=
new
char
[
strlen
(
*
astr
)
+
1
];
strcpy
(
source
,
*
astr
);
ctx
->
source_string
=
source
;
ctx
->
options
.
include_paths
=
new
char
[
strlen
(
*
bstr
)
+
1
];
strcpy
(
ctx
->
options
.
include_paths
,
*
bstr
);
// ctx->options.output_style = SASS_STYLE_NESTED;
ctx
->
options
.
output_style
=
args
[
4
]
->
Int32Value
();
ctx_w
->
ctx
=
ctx
;
ctx_w
->
callback
=
Persistent
<
Function
>::
New
(
callback
);
ctx_w
->
errorCallback
=
Persistent
<
Function
>::
New
(
errorCallback
);
ctx_w
->
request
.
data
=
ctx_w
;
int
status
=
uv_queue_work
(
uv_default_loop
(),
&
ctx_w
->
request
,
WorkOnContext
,
(
uv_after_work_cb
)
MakeCallback
);
assert
(
status
==
0
);
...
...
@@ -95,9 +152,102 @@ Handle<Value> RenderSync(const Arguments& args) {
return
scope
.
Close
(
Undefined
());
}
/**
Rendering Files
**/
void
WorkOnFileContext
(
uv_work_t
*
req
)
{
sass_file_context_wrapper
*
ctx_w
=
static_cast
<
sass_file_context_wrapper
*>
(
req
->
data
);
sass_file_context
*
ctx
=
static_cast
<
sass_file_context
*>
(
ctx_w
->
ctx
);
sass_compile_file
(
ctx
);
}
void
MakeFileCallback
(
uv_work_t
*
req
)
{
HandleScope
scope
;
TryCatch
try_catch
;
sass_file_context_wrapper
*
ctx_w
=
static_cast
<
sass_file_context_wrapper
*>
(
req
->
data
);
sass_file_context
*
ctx
=
static_cast
<
sass_file_context
*>
(
ctx_w
->
ctx
);
if
(
ctx
->
error_status
==
0
)
{
// if no error, do callback(null, result)
const
unsigned
argc
=
1
;
Local
<
Value
>
argv
[
argc
]
=
{
Local
<
Value
>::
New
(
String
::
New
(
ctx
->
output_string
))
};
ctx_w
->
callback
->
Call
(
Context
::
GetCurrent
()
->
Global
(),
argc
,
argv
);
}
else
{
// if error, do callback(error)
const
unsigned
argc
=
1
;
Local
<
Value
>
argv
[
argc
]
=
{
Local
<
Value
>::
New
(
String
::
New
(
ctx
->
error_message
))
};
ctx_w
->
errorCallback
->
Call
(
Context
::
GetCurrent
()
->
Global
(),
argc
,
argv
);
}
if
(
try_catch
.
HasCaught
())
{
node
::
FatalException
(
try_catch
);
}
sass_free_file_context_wrapper
(
ctx_w
);
}
Handle
<
Value
>
RenderFile
(
const
Arguments
&
args
)
{
HandleScope
scope
;
sass_file_context
*
ctx
=
sass_new_file_context
();
sass_file_context_wrapper
*
ctx_w
=
sass_new_file_context_wrapper
();
char
*
filename
;
String
::
AsciiValue
astr
(
args
[
0
]);
Local
<
Function
>
callback
=
Local
<
Function
>::
Cast
(
args
[
1
]);
Local
<
Function
>
errorCallback
=
Local
<
Function
>::
Cast
(
args
[
2
]);
String
::
AsciiValue
bstr
(
args
[
3
]);
filename
=
new
char
[
strlen
(
*
astr
)
+
1
];
strcpy
(
filename
,
*
astr
);
ctx
->
input_path
=
filename
;
ctx
->
options
.
include_paths
=
new
char
[
strlen
(
*
bstr
)
+
1
];
strcpy
(
ctx
->
options
.
include_paths
,
*
bstr
);
// ctx->options.output_style = SASS_STYLE_NESTED;
ctx
->
options
.
output_style
=
args
[
4
]
->
Int32Value
();
ctx_w
->
ctx
=
ctx
;
ctx_w
->
callback
=
Persistent
<
Function
>::
New
(
callback
);
ctx_w
->
errorCallback
=
Persistent
<
Function
>::
New
(
errorCallback
);
ctx_w
->
request
.
data
=
ctx_w
;
int
status
=
uv_queue_work
(
uv_default_loop
(),
&
ctx_w
->
request
,
WorkOnFileContext
,
(
uv_after_work_cb
)
MakeFileCallback
);
assert
(
status
==
0
);
return
scope
.
Close
(
Undefined
());
}
Handle
<
Value
>
RenderFileSync
(
const
Arguments
&
args
)
{
HandleScope
scope
;
sass_file_context
*
ctx
=
sass_new_file_context
();
char
*
filename
;
String
::
AsciiValue
astr
(
args
[
0
]);
String
::
AsciiValue
bstr
(
args
[
1
]);
filename
=
new
char
[
strlen
(
*
astr
)
+
1
];
strcpy
(
filename
,
*
astr
);
ctx
->
input_path
=
filename
;
ctx
->
options
.
include_paths
=
new
char
[
strlen
(
*
bstr
)
+
1
];
strcpy
(
ctx
->
options
.
include_paths
,
*
bstr
);
ctx
->
options
.
output_style
=
args
[
2
]
->
Int32Value
();
sass_compile_file
(
ctx
);
if
(
ctx
->
error_status
==
0
)
{
return
scope
.
Close
(
Local
<
Value
>::
New
(
String
::
New
(
ctx
->
output_string
)));
}
ThrowException
(
Exception
::
Error
(
String
::
New
(
ctx
->
error_message
)));
return
scope
.
Close
(
Undefined
());
}
void
RegisterModule
(
v8
::
Handle
<
v8
::
Object
>
target
)
{
NODE_SET_METHOD
(
target
,
"oldRender"
,
OldRender
);
NODE_SET_METHOD
(
target
,
"render"
,
Render
);
NODE_SET_METHOD
(
target
,
"renderSync"
,
RenderSync
);
NODE_SET_METHOD
(
target
,
"renderFile"
,
RenderFile
);
NODE_SET_METHOD
(
target
,
"renderFileSync"
,
RenderFileSync
);
}
NODE_MODULE
(
binding
,
RegisterModule
);
precompiled/darwin-x64/binding.node
View file @
45ad189a
This diff was suppressed by a .gitattributes entry.
sass.js
View file @
45ad189a
...
...
@@ -21,20 +21,61 @@ var SASS_OUTPUT_STYLE = {
compressed
:
3
};
exports
.
render
=
function
(
css
,
callback
,
options
)
{
var
prepareOptions
=
function
(
options
)
{
var
paths
,
style
;
options
=
typeof
options
!==
'object'
?
{}
:
options
;
paths
=
options
.
include_paths
||
options
.
includePaths
||
[];
style
=
SASS_OUTPUT_STYLE
[
options
.
output_style
||
options
.
outputStyle
]
||
0
;
return
binding
.
render
(
css
,
callback
,
paths
.
join
(
':'
),
style
);
return
{
paths
:
paths
,
style
:
style
};
}
var
deprecatedRender
=
function
(
css
,
callback
,
options
)
{
options
=
prepareOptions
(
options
);
return
binding
.
oldRender
(
css
,
callback
,
options
.
paths
.
join
(
':'
),
options
.
style
);
};
exports
.
renderSync
=
function
(
css
,
options
)
{
var
paths
,
style
;
options
=
typeof
options
!==
'object'
?
{}
:
options
;
paths
=
options
.
include_paths
||
options
.
includePaths
||
[];
style
=
SASS_OUTPUT_STYLE
[
options
.
output_style
||
options
.
outputStyle
]
||
0
;
return
binding
.
renderSync
(
css
,
paths
.
join
(
':'
),
style
);
var
deprecatedRenderSync
=
function
(
css
,
options
)
{
options
=
prepareOptions
(
options
);
return
binding
.
renderSync
(
css
,
options
.
paths
.
join
(
':'
),
options
.
style
);
};
exports
.
render
=
function
(
options
)
{
var
newOptions
;
if
(
typeof
arguments
[
0
]
===
'string'
)
{
return
deprecatedRender
.
apply
(
this
,
arguments
);
}
newOptions
=
prepareOptions
(
options
);
options
.
error
=
options
.
error
||
function
(){};
if
(
options
.
file
!==
undefined
&&
options
.
file
!==
null
)
{
return
binding
.
renderFile
(
options
.
file
,
options
.
success
,
options
.
error
,
newOptions
.
paths
.
join
(
':'
),
newOptions
.
style
);
}
//Assume data is present if file is not. binding/libsass will tell the user otherwise!
return
binding
.
render
(
options
.
data
,
options
.
success
,
options
.
error
,
newOptions
.
paths
.
join
(
":"
),
newOptions
.
style
);
};
exports
.
renderSync
=
function
(
options
)
{
var
newOptions
;
if
(
typeof
arguments
[
0
]
===
'string'
)
{
return
deprecatedRenderSync
.
apply
(
this
,
arguments
);
}
newOptions
=
prepareOptions
(
options
);
if
(
options
.
file
!==
undefined
&&
options
.
file
!==
null
)
{
return
binding
.
renderFileSync
(
options
.
file
,
newOptions
.
paths
.
join
(
':'
),
newOptions
.
style
);
}
//Assume data is present if file is not. binding/libsass will tell the user otherwise!
return
binding
.
renderSync
(
options
.
data
,
newOptions
.
paths
.
join
(
":"
),
newOptions
.
style
);
};
exports
.
middleware
=
require
(
'./lib/middleware'
);
sass_context_wrapper.cpp
View file @
45ad189a
...
...
@@ -15,4 +15,16 @@ extern "C" {
free
(
ctx_w
);
}
sass_file_context_wrapper
*
sass_new_file_context_wrapper
()
{
return
(
sass_file_context_wrapper
*
)
calloc
(
1
,
sizeof
(
sass_file_context_wrapper
));
}
void
sass_free_file_context_wrapper
(
sass_file_context_wrapper
*
ctx_w
)
{
if
(
ctx_w
->
ctx
)
sass_free_file_context
(
ctx_w
->
ctx
);
free
(
ctx_w
);
}
}
sass_context_wrapper.h
View file @
45ad189a
...
...
@@ -9,11 +9,22 @@ struct sass_context_wrapper {
sass_context
*
ctx
;
uv_work_t
request
;
v8
::
Persistent
<
v8
::
Function
>
callback
;
v8
::
Persistent
<
v8
::
Function
>
errorCallback
;
};
struct
sass_context_wrapper
*
sass_new_context_wrapper
(
void
);
void
sass_free_context_wrapper
(
struct
sass_context_wrapper
*
ctx
);
struct
sass_file_context_wrapper
{
sass_file_context
*
ctx
;
uv_work_t
request
;
v8
::
Persistent
<
v8
::
Function
>
callback
;
v8
::
Persistent
<
v8
::
Function
>
errorCallback
;
};
struct
sass_file_context_wrapper
*
sass_new_file_context_wrapper
(
void
);
void
sass_free_file_context_wrapper
(
struct
sass_file_context_wrapper
*
ctx
);
#ifdef __cplusplus
}
#endif
test/sample.scss
View file @
45ad189a
#h1
{
width
:
100%
;
span
{
color
:
red
;
&
.active
{
color
:
pink
;
}
#navbar
{
width
:
80%
;
height
:
23px
;
}
#navbar
ul
{
list-style-type
:
none
;
}
#navbar
li
{
float
:
left
;
a
{
font-weight
:
bold
;
}
}
test/test.js
View file @
45ad189a
...
...
@@ -28,8 +28,11 @@ var expectedRender = '#navbar {\n\
#navbar li a {
\
n
\
font-weight: bold; }
\
n'
;
var
badSampleFilename
=
'sample.scss'
;
var
sampleFilename
=
require
(
'path'
).
resolve
(
__dirname
,
'sample.scss'
);
describe
(
"compile scss"
,
function
()
{
describe
(
"DEPRECATED: compile scss"
,
function
()
{
it
(
"should compile with render"
,
function
(
done
)
{
sass
.
render
(
scssStr
,
function
(
err
,
css
)
{
done
(
err
);
...
...
@@ -60,3 +63,80 @@ describe("compile scss", function() {
}));
});
});
describe
(
"compile scss"
,
function
()
{
it
(
"should compile with render"
,
function
(
done
)
{
sass
.
render
({
data
:
scssStr
,
success
:
function
(
css
)
{
done
(
assert
.
ok
(
css
));
}
});
});
it
(
"should compile with renderSync"
,
function
(
done
)
{
done
(
assert
.
ok
(
sass
.
renderSync
({
data
:
scssStr
})));
});
it
(
"should match compiled string with render"
,
function
(
done
)
{
sass
.
render
({
data
:
scssStr
,
success
:
function
(
css
)
{
done
(
assert
.
equal
(
css
,
expectedRender
));
},
error
:
function
(
error
)
{
done
(
error
);
}
});
});
it
(
"should match compiled string with renderSync"
,
function
(
done
)
{
done
(
assert
.
equal
(
sass
.
renderSync
({
data
:
scssStr
}),
expectedRender
));
});
it
(
"should throw an exception for bad input"
,
function
(
done
)
{
done
(
assert
.
throws
(
function
()
{
sass
.
renderSync
({
data
:
badInput
});
}));
});
});
describe
(
"compile file"
,
function
()
{
it
(
"should compile with render"
,
function
(
done
)
{
sass
.
render
({
file
:
sampleFilename
,
success
:
function
(
css
)
{
done
(
assert
.
ok
(
css
));
},
error
:
function
(
error
)
{
done
(
error
);
}
});
});
it
(
"should compile with renderSync"
,
function
(
done
)
{
done
(
assert
.
ok
(
sass
.
renderSync
({
file
:
sampleFilename
})));
});
it
(
"should match compiled string with render"
,
function
(
done
)
{
sass
.
render
({
file
:
sampleFilename
,
success
:
function
(
css
)
{
done
(
assert
.
equal
(
css
,
expectedRender
));
},
error
:
function
(
error
)
{
done
(
error
);
}
});
});
it
(
"should match compiled string with renderSync"
,
function
(
done
)
{
done
(
assert
.
equal
(
sass
.
renderSync
({
file
:
sampleFilename
}),
expectedRender
));
});
it
(
"should throw an exception for bad input"
,
function
(
done
)
{
done
(
assert
.
throws
(
function
()
{
sass
.
renderSync
({
file
:
badSampleFilename
});
}));
});
});
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