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
a5792b84
Commit
a5792b84
authored
Apr 12, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More fine-grained C interface. Reasonably well factored.
parent
14dd0037
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
123 additions
and
81 deletions
+123
-81
context.cpp
context.cpp
+35
-1
context.hpp
context.hpp
+2
-1
sass_interface.cpp
sass_interface.cpp
+53
-63
sass_interface.h
sass_interface.h
+25
-7
sassc.c
sassc.c
+8
-9
No files found.
context.cpp
View file @
a5792b84
...
...
@@ -5,7 +5,40 @@ using std::cerr; using std::endl;
namespace
Sass
{
using
std
::
pair
;
Context
::
Context
()
void
Context
::
collect_include_paths
(
const
char
*
paths_str
)
{
const
size_t
wd_len
=
1024
;
char
wd
[
wd_len
];
include_paths
.
push_back
(
getcwd
(
wd
,
wd_len
));
if
(
*
include_paths
.
back
().
rbegin
()
!=
'/'
)
include_paths
.
back
()
+=
'/'
;
if
(
paths_str
)
{
const
char
*
beg
=
paths_str
;
const
char
*
end
=
Prelexer
::
find_first
<
':'
>
(
beg
);
while
(
end
)
{
string
path
(
beg
,
end
-
beg
);
if
(
!
path
.
empty
())
{
if
(
*
path
.
rbegin
()
!=
'/'
)
path
+=
'/'
;
include_paths
.
push_back
(
path
);
}
beg
=
end
+
1
;
end
=
Prelexer
::
find_first
<
':'
>
(
beg
);
}
string
path
(
beg
);
if
(
!
path
.
empty
())
{
if
(
*
path
.
rbegin
()
!=
'/'
)
path
+=
'/'
;
include_paths
.
push_back
(
path
);
}
}
for
(
int
i
=
0
;
i
<
include_paths
.
size
();
++
i
)
{
cerr
<<
include_paths
[
i
]
<<
endl
;
}
}
Context
::
Context
(
const
char
*
paths_str
)
:
global_env
(
Environment
()),
function_env
(
map
<
pair
<
string
,
size_t
>
,
Function
>
()),
source_refs
(
vector
<
char
*>
()),
...
...
@@ -13,6 +46,7 @@ namespace Sass {
ref_count
(
0
)
{
register_functions
();
collect_include_paths
(
paths_str
);
}
Context
::~
Context
()
...
...
context.hpp
View file @
a5792b84
...
...
@@ -47,7 +47,8 @@ namespace Sass {
vector
<
char
*>
source_refs
;
// all the source c-strings
size_t
ref_count
;
Context
();
void
collect_include_paths
(
const
char
*
paths_str
);
Context
(
const
char
*
paths_str
=
0
);
~
Context
();
void
register_function
(
Function_Descriptor
d
,
Implementation
ip
);
...
...
sass_interface.cpp
View file @
a5792b84
...
...
@@ -6,74 +6,64 @@
#include "eval_apply.hpp"
#include "sass_interface.h"
using
namespace
std
;
extern
"C"
{
extern
"C"
sass_context
*
sass_new_context
()
{
return
(
sass_context
*
)
malloc
(
sizeof
(
sass_context
));
}
using
namespace
std
;
extern
"C"
char
*
sass_compile
(
sass_context
*
c_ctx
)
{
using
namespace
Sass
;
// TO DO: CATCH ALL EXCEPTIONS
Context
cpp_ctx
;
sass_context
*
sass_new_context
()
{
return
(
sass_context
*
)
malloc
(
sizeof
(
sass_context
));
}
cpp_ctx
.
sass_path
=
string
(
c_ctx
->
sass_path
?
c_ctx
->
sass_path
:
""
);
cpp_ctx
.
css_path
=
string
(
c_ctx
->
css_path
?
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
(
*
cpp_ctx
.
include_paths
.
back
().
rbegin
()
!=
'/'
)
cpp_ctx
.
include_paths
.
back
()
+=
'/'
;
void
sass_free_context
(
sass_context
*
ctx
)
{
free
(
ctx
->
output_string
);
free
(
ctx
);
}
if
(
c_ctx
->
include_paths
)
{
const
char
*
beg
=
c_ctx
->
include_paths
;
const
char
*
end
=
Prelexer
::
find_first
<
':'
>
(
beg
);
sass_file_context
*
sass_new_file_context
()
{
return
(
sass_file_context
*
)
malloc
(
sizeof
(
sass_file_context
));
}
while
(
end
)
{
string
path
(
beg
,
end
-
beg
);
if
(
!
path
.
empty
())
{
if
(
*
path
.
rbegin
()
!=
'/'
)
path
+=
'/'
;
cpp_ctx
.
include_paths
.
push_back
(
path
);
}
beg
=
end
+
1
;
end
=
Prelexer
::
find_first
<
':'
>
(
beg
);
}
string
path
(
beg
);
if
(
!
path
.
empty
())
{
if
(
*
path
.
rbegin
()
!=
'/'
)
path
+=
'/'
;
cpp_ctx
.
include_paths
.
push_back
(
path
);
}
for
(
int
i
=
0
;
i
<
cpp_ctx
.
include_paths
.
size
();
++
i
)
{
cerr
<<
cpp_ctx
.
include_paths
[
i
]
<<
endl
;
}
void
sass_free_file_context
(
sass_file_context
*
ctx
)
{
free
(
ctx
->
output_string
);
free
(
ctx
);
}
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
)));
sass_folder_context
*
sass_new_folder_context
()
{
return
(
sass_folder_context
*
)
malloc
(
sizeof
(
sass_folder_context
));
}
static
char
*
process_document
(
Sass
::
Document
&
doc
,
int
style
)
{
using
namespace
Sass
;
doc
.
parse_scss
();
eval
(
doc
.
root
,
doc
.
context
.
global_env
,
doc
.
context
.
function_env
);
string
output
(
doc
.
emit_css
(
static_cast
<
Document
::
CSS_Style
>
(
style
)));
char
*
c_output
=
(
char
*
)
malloc
(
output
.
size
()
+
1
);
strcpy
(
c_output
,
output
.
c_str
());
return
c_output
;
}
int
sass_compile
(
sass_context
*
c_ctx
)
{
using
namespace
Sass
;
// TO DO: CATCH ALL EXCEPTIONS
Context
cpp_ctx
(
c_ctx
->
options
.
include_paths
);
Document
doc
(
0
,
c_ctx
->
input_string
,
cpp_ctx
);
c_ctx
->
output_string
=
process_document
(
doc
,
c_ctx
->
options
.
output_style
);
return
0
;
}
char
*
c_output
=
(
char
*
)
malloc
(
output
.
size
()
+
1
);
strcpy
(
c_output
,
output
.
c_str
());
return
c_output
;
}
int
sass_compile_file
(
sass_file_context
*
c_ctx
)
{
using
namespace
Sass
;
// TO DO: CATCH ALL EXCEPTIONS
Context
cpp_ctx
(
c_ctx
->
options
.
include_paths
);
Document
doc
(
c_ctx
->
input_path
,
0
,
cpp_ctx
);
c_ctx
->
output_string
=
process_document
(
doc
,
c_ctx
->
options
.
output_style
);
return
0
;
}
//
// 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
}
\ No newline at end of file
sass_interface.h
View file @
a5792b84
...
...
@@ -7,18 +7,36 @@ extern "C" {
#define SASS_STYLE_COMPACT 2;
#define SASS_STYLE_COMPRESSED 3;
struct
sass_context
{
char
*
sass_path
;
char
*
css_path
;
struct
sass_options
{
int
output_style
;
char
*
include_paths
;
char
*
input_file
;
};
struct
sass_context
{
char
*
input_string
;
unsigned
int
output_style
;
char
*
output_string
;
struct
sass_options
options
;
};
struct
sass_folder_context
{
char
*
search_path
;
char
*
output_path
;
struct
sass_options
options
;
};
struct
sass_file_context
{
char
*
input_path
;
char
*
output_string
;
struct
sass_options
options
;
};
struct
sass_context
*
sass_new_context
();
struct
sass_context
*
sass_new_context
();
struct
sass_folder_context
*
sass_new_folder_context
();
struct
sass_file_context
*
sass_new_file_context
();
char
*
sass_compile
(
struct
sass_context
*
);
int
sass_compile
(
struct
sass_context
*
);
// int sass_folder_compile (struct sass_folder_context*);
int
sass_file_compile
(
struct
sass_file_context
*
);
#ifdef __cplusplus
}
...
...
sassc.c
View file @
a5792b84
...
...
@@ -27,17 +27,15 @@ int main(int argc, char** argv)
return
0
;
}
struct
sass_context
*
ctx
=
sass_new_context
();
ctx
->
sass_path
=
NULL
;
ctx
->
css_path
=
NULL
;
ctx
->
include_paths
=
"::/blah/bloo/fuzz:/slub/flub/chub::/Users/Aaron/dev/libsass/::::/huzz/buzz:::"
;
ctx
->
output_style
=
SASS_STYLE_NESTED
;
ctx
->
input_file
=
argv
[
1
];
ctx
->
input_string
=
NULL
;
struct
sass_file_context
*
ctx
=
sass_new_file_context
();
ctx
->
options
.
include_paths
=
"::/blah/bloo/fuzz:/slub/flub/chub::/Users/Aaron/dev/libsass/::::/huzz/buzz:::"
;
ctx
->
options
.
output_style
=
SASS_STYLE_NESTED
;
ctx
->
input_path
=
argv
[
1
];
char
*
output
=
sass_comp
ile
(
ctx
);
sass_compile_f
ile
(
ctx
);
printf
(
"%s"
,
output
);
printf
(
"%s"
,
ctx
->
output_string
);
sass_free_file_context
(
ctx
);
return
0
;
}
\ 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