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
574d19b5
Commit
574d19b5
authored
Apr 19, 2013
by
Brett Wilkins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding renderSync function, updating tests and docs
parent
4de3ba00
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
4 deletions
+68
-4
README.md
README.md
+5
-1
binding.cpp
binding.cpp
+26
-1
binding.node
precompiled/darwin-x64/binding.node
+0
-0
sass.js
sass.js
+8
-0
test.js
test/test.js
+29
-2
No files found.
README.md
View file @
574d19b5
...
...
@@ -17,9 +17,11 @@ Find it on npm: <https://npmjs.org/package/node-sass>
```
javascript
var
sass
=
require
(
'node-sass'
);
sass
.
render
(
scss_content
,
callback
[,
options
]);
// OR
var
css
=
sass
.
renderSync
(
scss_content
);
```
Especially, the options argument is optional. It support two attribute
:
`includePaths`
and
`outputStyle`
, both of them
are optional.
Especially, the options argument is optional. It support two attribute
s:
`includePaths`
and
`outputStyle`
, both of which
are optional.
`includePaths`
is an
`Array`
, you can add a sass import path.
...
...
@@ -33,6 +35,8 @@ var sass = require('node-sass');
sass
.
render
(
'body{background:blue; a{color:black;}}'
,
function
(
err
,
css
){
console
.
log
(
css
)
}
/*, { includePaths: [ 'lib/', 'mod/' ], outputStyle: 'compressed' }*/
);
// OR
console
.
log
(
sass
.
renderSync
(
'body{background:blue; a{color:black;}}'
));
```
## Connect/Express middleware
...
...
binding.cpp
View file @
574d19b5
...
...
@@ -69,11 +69,36 @@ Handle<Value> Render(const Arguments& args) {
int
status
=
uv_queue_work
(
uv_default_loop
(),
&
ctx_w
->
request
,
WorkOnContext
,
(
uv_after_work_cb
)
MakeCallback
);
assert
(
status
==
0
);
return
Undefined
();
return
scope
.
Close
(
Undefined
());
}
Handle
<
Value
>
RenderSync
(
const
Arguments
&
args
)
{
HandleScope
scope
;
TryCatch
try_catch
;
sass_context
*
ctx
=
sass_new_context
();
char
*
source
;
String
::
AsciiValue
astr
(
args
[
0
]);
String
::
AsciiValue
bstr
(
args
[
1
]);
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
=
args
[
2
]
->
Int32Value
();
sass_compile
(
ctx
);
if
(
ctx
->
error_status
==
0
)
{
return
scope
.
Close
(
Local
<
Value
>::
New
(
String
::
New
(
ctx
->
output_string
)));
}
else
{
ThrowException
(
Exception
::
Error
(
String
::
New
(
"Input does not appear to be valid SCSS."
)));
}
return
scope
.
Close
(
Undefined
());
}
void
RegisterModule
(
v8
::
Handle
<
v8
::
Object
>
target
)
{
NODE_SET_METHOD
(
target
,
"render"
,
Render
);
NODE_SET_METHOD
(
target
,
"renderSync"
,
RenderSync
);
}
NODE_MODULE
(
binding
,
RegisterModule
);
precompiled/darwin-x64/binding.node
View file @
574d19b5
This diff was suppressed by a .gitattributes entry.
sass.js
View file @
574d19b5
...
...
@@ -29,4 +29,12 @@ exports.render = function(css, callback, options) {
return
binding
.
render
(
css
,
callback
,
paths
.
join
(
':'
),
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
);
};
exports
.
middleware
=
require
(
'./lib/middleware'
);
test/test.js
View file @
574d19b5
...
...
@@ -12,6 +12,10 @@ var scssStr = '#navbar {\
a {
\
font-weight: bold; }}'
;
// Note that the bad
var
badInput
=
'#navbar
\
n
\
width: 80%'
;
var
expectedRender
=
'#navbar {
\
n
\
width: 80%;
\
n
\
height: 23px; }
\
n
\
...
...
@@ -41,4 +45,28 @@ describe("compile scss", function() {
}
});
});
});
\ No newline at end of file
it
(
"should execute asynchronously"
,
function
(
done
)
{
var
inside
,
outside
;
inside
=
outside
=
false
;
sass
.
render
(
scssStr
,
function
(
err
,
css
)
{
inside
=
Date
.
now
();
});
outside
=
Date
.
now
();
done
(
assert
.
ok
(
!
inside
)
&&
assert
.
notEqual
(
outside
,
false
));
});
it
(
"should execute synchronously"
,
function
(
done
)
{
var
output
=
sass
.
renderSync
(
scssStr
);
done
(
assert
.
ok
(
output
));
});
it
(
"should throw an exception for bad input"
,
function
(
done
)
{
done
(
assert
.
throws
(
function
()
{
sass
.
renderSync
(
badInput
);
}));
});
});
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