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
9180b5c4
Commit
9180b5c4
authored
Jun 11, 2012
by
Dean Mao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add callback support and add newlines at end of files
parent
c4ce49a4
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 @
9180b5c4
...
...
@@ -6,13 +6,12 @@ Node bindings to libsass
## Install
cd libsass && make && cd ..
node-waf configure && node-waf build
npm install
## Usage
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)
});
...
...
binding.cpp
View file @
9180b5c4
#include <v8.h>
#include <node.h>
#include <string>
#include <cstdlib>
#include "libsass/sass_interface.h"
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
)
{
HandleScope
scope
;
s
truct
s
ass_context
*
ctx
=
sass_new_context
();
sass_context
*
ctx
=
sass_new_context
();
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
.
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
)
{
...
...
lib/middleware.js
View file @
9180b5c4
...
...
@@ -99,8 +99,8 @@ module.exports = function(options){
var
style
=
options
.
compile
();
var
paths
=
[];
delete
imports
[
sassPath
];
style
.
render
(
str
,
function
(
css
){
//
if (err) return next(err);
style
.
render
(
str
,
function
(
err
,
css
){
if
(
err
)
return
next
(
err
);
if
(
debug
)
log
(
'render'
,
sassPath
);
imports
[
sassPath
]
=
paths
;
mkdirp
(
dirname
(
cssPath
),
0700
,
function
(
err
){
...
...
libsass/context.cpp
View file @
9180b5c4
...
...
@@ -124,3 +124,4 @@ namespace Sass {
}
}
libsass/context.hpp
View file @
9180b5c4
...
...
@@ -63,3 +63,4 @@ namespace Sass {
};
}
libsass/document.cpp
View file @
9180b5c4
...
...
@@ -121,3 +121,4 @@ namespace Sass {
return
retval
;
}
}
libsass/document.hpp
View file @
9180b5c4
...
...
@@ -173,3 +173,4 @@ namespace Sass {
};
}
libsass/document_parser.cpp
View file @
9180b5c4
...
...
@@ -976,3 +976,4 @@ namespace Sass {
}
}
libsass/error.hpp
View file @
9180b5c4
...
...
@@ -15,3 +15,4 @@ namespace Sass {
};
}
libsass/eval_apply.cpp
View file @
9180b5c4
...
...
@@ -855,3 +855,4 @@ namespace Sass {
{
return
selector_but
(
sel
,
new_Node
,
0
,
1
);
}
}
libsass/eval_apply.hpp
View file @
9180b5c4
...
...
@@ -29,3 +29,4 @@ namespace Sass {
Node
selector_butlast
(
Node
sel
,
Node_Factory
&
new_Node
);
}
libsass/functions.cpp
View file @
9180b5c4
...
...
@@ -648,3 +648,4 @@ namespace Sass {
}
}
libsass/functions.hpp
View file @
9180b5c4
...
...
@@ -156,3 +156,4 @@ namespace Sass {
}
}
libsass/node.cpp
View file @
9180b5c4
...
...
@@ -319,3 +319,4 @@ namespace Sass {
}
}
libsass/node.hpp
View file @
9180b5c4
...
...
@@ -390,3 +390,4 @@ namespace Sass {
inline
bool
Node
::
is_null_ptr
()
const
{
return
!
ip_
;
}
}
libsass/node_emitters.cpp
View file @
9180b5c4
...
...
@@ -406,3 +406,4 @@ namespace Sass {
void
Node
::
echo
(
stringstream
&
buf
,
size_t
depth
)
{
}
void
Node
::
emit_expanded_css
(
stringstream
&
buf
,
const
string
&
prefix
)
{
}
}
libsass/node_factory.cpp
View file @
9180b5c4
...
...
@@ -85,3 +85,4 @@ namespace Sass {
{
for
(
size_t
i
=
0
,
S
=
pool_
.
size
();
i
<
S
;
++
i
)
delete
pool_
[
i
];
}
}
libsass/node_factory.hpp
View file @
9180b5c4
...
...
@@ -35,3 +35,4 @@ namespace Sass {
};
}
libsass/prelexer.cpp
View file @
9180b5c4
...
...
@@ -368,3 +368,4 @@ namespace Sass {
}
}
}
libsass/prelexer.hpp
View file @
9180b5c4
...
...
@@ -436,3 +436,4 @@ namespace Sass {
}
}
libsass/sass_interface.cpp
View file @
9180b5c4
...
...
@@ -130,3 +130,4 @@ extern "C" {
}
}
libsass/sass_interface.h
View file @
9180b5c4
#include <node.h>
#ifdef __cplusplus
extern
"C"
{
#endif
...
...
@@ -18,6 +20,8 @@ struct sass_context {
struct
sass_options
options
;
int
error_status
;
char
*
error_message
;
uv_work_t
request
;
v8
::
Persistent
<
v8
::
Function
>
callback
;
};
struct
sass_file_context
{
...
...
@@ -51,3 +55,4 @@ int sass_compile_folder (struct sass_folder_context* ctx);
#ifdef __cplusplus
}
#endif
libsass/test_node_factory.cpp
View file @
9180b5c4
...
...
@@ -93,3 +93,4 @@ int main()
new_Node
.
free
();
return
0
;
}
sass.js
View file @
9180b5c4
var
binding
=
require
(
'./build/Release/binding'
)
var
render
=
function
(
str
,
cb
){
cb
(
binding
.
render
(
str
))
}
exports
.
render
=
render
exports
.
render
=
binding
.
render
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