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
b5450464
Commit
b5450464
authored
Apr 11, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
C lib interface + necessary amendments.
parent
6980ee00
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
113 additions
and
21 deletions
+113
-21
context.cpp
context.cpp
+1
-0
context.hpp
context.hpp
+4
-1
document.cpp
document.cpp
+39
-0
document.hpp
document.hpp
+1
-0
interface.c
interface.c
+0
-20
sass_interface.cpp
sass_interface.cpp
+68
-0
No files found.
context.cpp
View file @
b5450464
...
@@ -9,6 +9,7 @@ namespace Sass {
...
@@ -9,6 +9,7 @@ namespace Sass {
:
global_env
(
Environment
()),
:
global_env
(
Environment
()),
function_env
(
map
<
pair
<
string
,
size_t
>
,
Function
>
()),
function_env
(
map
<
pair
<
string
,
size_t
>
,
Function
>
()),
source_refs
(
vector
<
char
*>
()),
source_refs
(
vector
<
char
*>
()),
include_paths
(
vector
<
string
>
()),
ref_count
(
0
)
ref_count
(
0
)
{
{
register_functions
();
register_functions
();
...
...
context.hpp
View file @
b5450464
...
@@ -39,9 +39,12 @@ namespace Sass {
...
@@ -39,9 +39,12 @@ namespace Sass {
};
};
struct
Context
{
struct
Context
{
string
sass_path
;
string
css_path
;
vector
<
string
>
include_paths
;
Environment
global_env
;
Environment
global_env
;
map
<
pair
<
string
,
size_t
>
,
Function
>
function_env
;
map
<
pair
<
string
,
size_t
>
,
Function
>
function_env
;
vector
<
char
*>
source_refs
;
vector
<
char
*>
source_refs
;
// all the source c-strings
size_t
ref_count
;
size_t
ref_count
;
Context
();
Context
();
...
...
document.cpp
View file @
b5450464
#include <cstdio>
#include <cstdio>
#include <cstring>
#include "document.hpp"
#include "document.hpp"
#include "eval_apply.hpp"
#include "eval_apply.hpp"
#include <iostream>
#include <iostream>
namespace
Sass
{
namespace
Sass
{
Document
::
Document
(
char
*
path_str
,
char
*
source_str
,
Context
&
ctx
)
:
path
(
string
()),
source
(
source_str
),
line_number
(
1
),
context
(
ctx
),
root
(
Node
(
Node
::
root
,
1
)),
lexed
(
Token
::
make
())
{
if
(
source_str
)
{
own_source
=
false
;
position
=
source
;
end
=
position
+
std
::
strlen
(
source
);
}
else
if
(
path_str
)
{
path
=
string
(
path_str
);
std
::
FILE
*
f
;
// TO DO: CHECK f AGAINST NULL/0
f
=
std
::
fopen
(
path
.
c_str
(),
"rb"
);
std
::
fseek
(
f
,
0
,
SEEK_END
);
int
len
=
std
::
ftell
(
f
);
std
::
rewind
(
f
);
// TO DO: WRAP THE new[] IN A TRY/CATCH BLOCK
source
=
new
char
[
len
+
1
];
std
::
fread
(
source
,
sizeof
(
char
),
len
,
f
);
source
[
len
]
=
'\0'
;
end
=
source
+
len
;
std
::
fclose
(
f
);
own_source
=
true
;
position
=
source
;
context
.
source_refs
.
push_back
(
source
);
}
else
{
// report an error
}
++
context
.
ref_count
;
}
Document
::
Document
(
string
path
,
char
*
source
)
Document
::
Document
(
string
path
,
char
*
source
)
:
path
(
path
),
source
(
source
),
:
path
(
path
),
source
(
source
),
...
...
document.hpp
View file @
b5450464
...
@@ -27,6 +27,7 @@ namespace Sass {
...
@@ -27,6 +27,7 @@ namespace Sass {
Node
root
;
Node
root
;
Token
lexed
;
Token
lexed
;
Document
(
char
*
path_str
,
char
*
source_str
,
Context
&
ctx
);
Document
(
string
path
,
char
*
source
=
0
);
Document
(
string
path
,
char
*
source
=
0
);
Document
(
string
path
,
Context
&
context
);
Document
(
string
path
,
Context
&
context
);
Document
(
size_t
line_number
,
Token
t
,
Context
&
context
);
Document
(
size_t
line_number
,
Token
t
,
Context
&
context
);
...
...
interface.c
deleted
100644 → 0
View file @
6980ee00
/*
This is when you want to compile a whole folder of stuff
*/
var
opts
=
sass_new_context
();
opts
->
sassPath
=
"/Users/hcatlin/dev/asset/stylesheet"
;
opts
->
cssPath
=
"/Users/hcatlin/dev/asset/stylesheets/.css"
;
opts
->
includePaths
=
"/Users/hcatlin/dev/asset/stylesheets:/Users/hcatlin/sasslib"
;
opts
->
outputStyle
=>
SASS_STYLE_COMPRESSED
;
sass_compile
(
opts
,
&
callbackfunction
);
/*
This is when you want to compile a string
*/
opts
=
sass_new_context
();
opts
->
inputString
=
"a { width: 50px; }"
;
opts
->
includePaths
=
"/Users/hcatlin/dev/asset/stylesheets:/Users/hcatlin/sasslib"
;
opts
->
outputStyle
=>
SASS_STYLE_EXPANDED
;
var
cssResult
=
sass_compile
(
opts
,
&
callbackfunction
);
\ No newline at end of file
sass_interface.cpp
0 → 100644
View file @
b5450464
#include <iostream>
#include <string>
#include <cstdlib>
#include <unistd.h>
#include "document.hpp"
#include "eval_apply.hpp"
#include "sass_interface.h"
using
namespace
std
;
extern
"C"
sass_context
*
sass_new_context
()
{
return
(
sass_context
*
)
malloc
(
sizeof
(
sass_context
));
}
extern
"C"
char
*
sass_compile
(
sass_context
*
c_ctx
)
{
using
namespace
Sass
;
// TO DO: CATCH ALL EXCEPTIONS
Context
cpp_ctx
;
cpp_ctx
.
sass_path
=
string
(
c_ctx
->
sass_path
);
cpp_ctx
.
css_path
=
string
(
c_ctx
->
css_path
);
const
size_t
wd_len
=
1024
;
char
wd
[
wd_len
];
cpp_ctx
.
include_paths
.
push_back
(
getcwd
(
wd
,
wd_len
));
if
(
c_ctx
->
include_paths
)
{
const
char
*
beg
=
c_ctx
->
include_paths
;
const
char
*
end
=
Prelexer
::
find_first
<
':'
>
(
beg
);
while
(
end
)
{
cpp_ctx
.
include_paths
.
push_back
(
string
(
beg
,
end
-
beg
));
beg
=
end
+
1
;
end
=
Prelexer
::
find_first
<
':'
>
(
beg
);
}
cpp_ctx
.
include_paths
.
push_back
(
beg
);
}
Document
doc
(
c_ctx
->
input_file
,
c_ctx
->
input_string
,
cpp_ctx
);
doc
.
parse_scss
();
eval
(
doc
.
root
,
doc
.
context
.
global_env
,
doc
.
context
.
function_env
);
string
output
(
doc
.
emit_css
(
static_cast
<
Document
::
CSS_Style
>
(
c_ctx
->
output_style
)));
char
*
c_output
=
(
char
*
)
malloc
(
output
.
size
()
+
1
);
strcpy
(
c_output
,
output
.
c_str
());
return
c_output
;
}
//
// This is when you want to compile a whole folder of stuff
//
// var opts = sass_new_context();
// opts->sassPath = "/Users/hcatlin/dev/asset/stylesheet";
// opts->cssPath = "/Users/hcatlin/dev/asset/stylesheets/.css";
// opts->includePaths = "/Users/hcatlin/dev/asset/stylesheets:/Users/hcatlin/sasslib";
// opts->outputStyle => SASS_STYLE_COMPRESSED;
// sass_compile(opts, &callbackfunction);
//
//
// This is when you want to compile a string
//
// opts = sass_new_context();
// opts->inputString = "a { width: 50px; }";
// opts->includePaths = "/Users/hcatlin/dev/asset/stylesheets:/Users/hcatlin/sasslib";
// opts->outputStyle => SASS_STYLE_EXPANDED;
//
var
cssResult
=
sass_compile
(
opts
,
&
callbackfunction
);
\ No newline at end of file
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