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
5c8e9615
Commit
5c8e9615
authored
Jun 11, 2012
by
Andrew Nesbitt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9 from deanmao/master
added callback support
parents
5669082b
9180b5c4
Show whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
73 additions
and
15 deletions
+73
-15
README.md
README.md
+2
-3
binding.cpp
binding.cpp
+44
-5
middleware.js
lib/middleware.js
+2
-2
context.cpp
libsass/context.cpp
+1
-0
context.hpp
libsass/context.hpp
+1
-0
document.cpp
libsass/document.cpp
+1
-0
document.hpp
libsass/document.hpp
+1
-0
document_parser.cpp
libsass/document_parser.cpp
+1
-0
error.hpp
libsass/error.hpp
+1
-0
eval_apply.cpp
libsass/eval_apply.cpp
+1
-0
eval_apply.hpp
libsass/eval_apply.hpp
+1
-0
functions.cpp
libsass/functions.cpp
+1
-0
functions.hpp
libsass/functions.hpp
+1
-0
node.cpp
libsass/node.cpp
+1
-0
node.hpp
libsass/node.hpp
+1
-0
node_emitters.cpp
libsass/node_emitters.cpp
+1
-0
node_factory.cpp
libsass/node_factory.cpp
+1
-0
node_factory.hpp
libsass/node_factory.hpp
+1
-0
prelexer.cpp
libsass/prelexer.cpp
+1
-0
prelexer.hpp
libsass/prelexer.hpp
+1
-0
sass_interface.cpp
libsass/sass_interface.cpp
+1
-0
sass_interface.h
libsass/sass_interface.h
+5
-0
test_node_factory.cpp
libsass/test_node_factory.cpp
+1
-0
sass.js
sass.js
+1
-5
No files found.
README.md
View file @
5c8e9615
...
@@ -6,13 +6,12 @@ Node bindings to libsass
...
@@ -6,13 +6,12 @@ Node bindings to libsass
## Install
## Install
cd libsass && make && cd ..
npm install
node-waf configure && node-waf build
## Usage
## Usage
var sass = require('./sass');
var sass = require('./sass');
sass.render('body{background:blue; a{color:black;}}', function(css){
sass.render('body{background:blue; a{color:black;}}', function(
err,
css){
console.log(css)
console.log(css)
});
});
...
...
binding.cpp
View file @
5c8e9615
#include <v8.h>
#include <v8.h>
#include <node.h>
#include <node.h>
#include <string>
#include <cstdlib>
#include "libsass/sass_interface.h"
#include "libsass/sass_interface.h"
using
namespace
v8
;
using
namespace
v8
;
void
WorkOnContext
(
uv_work_t
*
req
)
{
sass_context
*
ctx
=
static_cast
<
sass_context
*>
(
req
->
data
);
sass_compile
(
ctx
);
}
void
MakeCallback
(
uv_work_t
*
req
)
{
HandleScope
scope
;
TryCatch
try_catch
;
sass_context
*
ctx
=
static_cast
<
sass_context
*>
(
req
->
data
);
if
(
ctx
->
error_status
==
0
)
{
// if no error, do callback(null, result)
const
unsigned
argc
=
2
;
Local
<
Value
>
argv
[
argc
]
=
{
Local
<
Value
>::
New
(
Null
()),
Local
<
Value
>::
New
(
String
::
New
(
ctx
->
output_string
))
};
ctx
->
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
->
callback
->
Call
(
Context
::
GetCurrent
()
->
Global
(),
argc
,
argv
);
}
if
(
try_catch
.
HasCaught
())
{
node
::
FatalException
(
try_catch
);
}
}
Handle
<
Value
>
Render
(
const
Arguments
&
args
)
{
Handle
<
Value
>
Render
(
const
Arguments
&
args
)
{
HandleScope
scope
;
HandleScope
scope
;
s
truct
s
ass_context
*
ctx
=
sass_new_context
();
sass_context
*
ctx
=
sass_new_context
();
String
::
AsciiValue
astr
(
args
[
0
]);
String
::
AsciiValue
astr
(
args
[
0
]);
char
*
cs
=
*
astr
;
Local
<
Function
>
callback
=
Local
<
Function
>::
Cast
(
args
[
1
])
;
ctx
->
source_string
=
cs
;
ctx
->
source_string
=
new
char
[
strlen
(
*
astr
)
+
1
];
strcpy
(
ctx
->
source_string
,
*
astr
);
ctx
->
options
.
include_paths
=
0
;
ctx
->
options
.
include_paths
=
0
;
ctx
->
options
.
output_style
=
SASS_STYLE_NESTED
;
ctx
->
options
.
output_style
=
SASS_STYLE_NESTED
;
ctx
->
callback
=
Persistent
<
Function
>::
New
(
callback
);
ctx
->
request
.
data
=
ctx
;
sass_compile
(
ctx
);
int
status
=
uv_queue_work
(
uv_default_loop
(),
&
ctx
->
request
,
WorkOnContext
,
MakeCallback
);
assert
(
status
==
0
);
return
scope
.
Close
(
String
::
New
(
ctx
->
output_string
)
);
return
Undefined
(
);
}
}
void
RegisterModule
(
v8
::
Handle
<
v8
::
Object
>
target
)
{
void
RegisterModule
(
v8
::
Handle
<
v8
::
Object
>
target
)
{
...
...
lib/middleware.js
View file @
5c8e9615
...
@@ -99,8 +99,8 @@ module.exports = function(options){
...
@@ -99,8 +99,8 @@ module.exports = function(options){
var
style
=
options
.
compile
();
var
style
=
options
.
compile
();
var
paths
=
[];
var
paths
=
[];
delete
imports
[
sassPath
];
delete
imports
[
sassPath
];
style
.
render
(
str
,
function
(
css
){
style
.
render
(
str
,
function
(
err
,
css
){
//
if (err) return next(err);
if
(
err
)
return
next
(
err
);
if
(
debug
)
log
(
'render'
,
sassPath
);
if
(
debug
)
log
(
'render'
,
sassPath
);
imports
[
sassPath
]
=
paths
;
imports
[
sassPath
]
=
paths
;
mkdirp
(
dirname
(
cssPath
),
0700
,
function
(
err
){
mkdirp
(
dirname
(
cssPath
),
0700
,
function
(
err
){
...
...
libsass/context.cpp
View file @
5c8e9615
...
@@ -124,3 +124,4 @@ namespace Sass {
...
@@ -124,3 +124,4 @@ namespace Sass {
}
}
}
}
libsass/context.hpp
View file @
5c8e9615
...
@@ -63,3 +63,4 @@ namespace Sass {
...
@@ -63,3 +63,4 @@ namespace Sass {
};
};
}
}
libsass/document.cpp
View file @
5c8e9615
...
@@ -121,3 +121,4 @@ namespace Sass {
...
@@ -121,3 +121,4 @@ namespace Sass {
return
retval
;
return
retval
;
}
}
}
}
libsass/document.hpp
View file @
5c8e9615
...
@@ -173,3 +173,4 @@ namespace Sass {
...
@@ -173,3 +173,4 @@ namespace Sass {
};
};
}
}
libsass/document_parser.cpp
View file @
5c8e9615
...
@@ -976,3 +976,4 @@ namespace Sass {
...
@@ -976,3 +976,4 @@ namespace Sass {
}
}
}
}
libsass/error.hpp
View file @
5c8e9615
...
@@ -15,3 +15,4 @@ namespace Sass {
...
@@ -15,3 +15,4 @@ namespace Sass {
};
};
}
}
libsass/eval_apply.cpp
View file @
5c8e9615
...
@@ -855,3 +855,4 @@ namespace Sass {
...
@@ -855,3 +855,4 @@ namespace Sass {
{
return
selector_but
(
sel
,
new_Node
,
0
,
1
);
}
{
return
selector_but
(
sel
,
new_Node
,
0
,
1
);
}
}
}
libsass/eval_apply.hpp
View file @
5c8e9615
...
@@ -29,3 +29,4 @@ namespace Sass {
...
@@ -29,3 +29,4 @@ namespace Sass {
Node
selector_butlast
(
Node
sel
,
Node_Factory
&
new_Node
);
Node
selector_butlast
(
Node
sel
,
Node_Factory
&
new_Node
);
}
}
libsass/functions.cpp
View file @
5c8e9615
...
@@ -648,3 +648,4 @@ namespace Sass {
...
@@ -648,3 +648,4 @@ namespace Sass {
}
}
}
}
libsass/functions.hpp
View file @
5c8e9615
...
@@ -156,3 +156,4 @@ namespace Sass {
...
@@ -156,3 +156,4 @@ namespace Sass {
}
}
}
}
libsass/node.cpp
View file @
5c8e9615
...
@@ -319,3 +319,4 @@ namespace Sass {
...
@@ -319,3 +319,4 @@ namespace Sass {
}
}
}
}
libsass/node.hpp
View file @
5c8e9615
...
@@ -390,3 +390,4 @@ namespace Sass {
...
@@ -390,3 +390,4 @@ namespace Sass {
inline
bool
Node
::
is_null_ptr
()
const
{
return
!
ip_
;
}
inline
bool
Node
::
is_null_ptr
()
const
{
return
!
ip_
;
}
}
}
libsass/node_emitters.cpp
View file @
5c8e9615
...
@@ -406,3 +406,4 @@ namespace Sass {
...
@@ -406,3 +406,4 @@ namespace Sass {
void
Node
::
echo
(
stringstream
&
buf
,
size_t
depth
)
{
}
void
Node
::
echo
(
stringstream
&
buf
,
size_t
depth
)
{
}
void
Node
::
emit_expanded_css
(
stringstream
&
buf
,
const
string
&
prefix
)
{
}
void
Node
::
emit_expanded_css
(
stringstream
&
buf
,
const
string
&
prefix
)
{
}
}
}
libsass/node_factory.cpp
View file @
5c8e9615
...
@@ -85,3 +85,4 @@ namespace Sass {
...
@@ -85,3 +85,4 @@ namespace Sass {
{
for
(
size_t
i
=
0
,
S
=
pool_
.
size
();
i
<
S
;
++
i
)
delete
pool_
[
i
];
}
{
for
(
size_t
i
=
0
,
S
=
pool_
.
size
();
i
<
S
;
++
i
)
delete
pool_
[
i
];
}
}
}
libsass/node_factory.hpp
View file @
5c8e9615
...
@@ -35,3 +35,4 @@ namespace Sass {
...
@@ -35,3 +35,4 @@ namespace Sass {
};
};
}
}
libsass/prelexer.cpp
View file @
5c8e9615
...
@@ -368,3 +368,4 @@ namespace Sass {
...
@@ -368,3 +368,4 @@ namespace Sass {
}
}
}
}
}
}
libsass/prelexer.hpp
View file @
5c8e9615
...
@@ -436,3 +436,4 @@ namespace Sass {
...
@@ -436,3 +436,4 @@ namespace Sass {
}
}
}
}
libsass/sass_interface.cpp
View file @
5c8e9615
...
@@ -130,3 +130,4 @@ extern "C" {
...
@@ -130,3 +130,4 @@ extern "C" {
}
}
}
}
libsass/sass_interface.h
View file @
5c8e9615
#include <node.h>
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
#endif
#endif
...
@@ -18,6 +20,8 @@ struct sass_context {
...
@@ -18,6 +20,8 @@ struct sass_context {
struct
sass_options
options
;
struct
sass_options
options
;
int
error_status
;
int
error_status
;
char
*
error_message
;
char
*
error_message
;
uv_work_t
request
;
v8
::
Persistent
<
v8
::
Function
>
callback
;
};
};
struct
sass_file_context
{
struct
sass_file_context
{
...
@@ -51,3 +55,4 @@ int sass_compile_folder (struct sass_folder_context* ctx);
...
@@ -51,3 +55,4 @@ int sass_compile_folder (struct sass_folder_context* ctx);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
libsass/test_node_factory.cpp
View file @
5c8e9615
...
@@ -93,3 +93,4 @@ int main()
...
@@ -93,3 +93,4 @@ int main()
new_Node
.
free
();
new_Node
.
free
();
return
0
;
return
0
;
}
}
sass.js
View file @
5c8e9615
var
binding
=
require
(
'./build/Release/binding'
)
var
binding
=
require
(
'./build/Release/binding'
)
var
render
=
function
(
str
,
cb
){
exports
.
render
=
binding
.
render
cb
(
binding
.
render
(
str
))
}
exports
.
render
=
render
exports
.
middleware
=
require
(
'./lib/middleware'
);
exports
.
middleware
=
require
(
'./lib/middleware'
);
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