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
55c191c2
Commit
55c191c2
authored
Jul 12, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #28 from QuLogic/import_tweaks
Import tweaks
parents
cdb98139
fff6118b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
23 deletions
+28
-23
document.cpp
document.cpp
+24
-18
document_parser.cpp
document_parser.cpp
+4
-5
No files found.
document.cpp
View file @
55c191c2
...
...
@@ -5,6 +5,7 @@
#include "error.hpp"
#include <iostream>
#include <sstream>
#include <sys/stat.h>
namespace
Sass
{
...
...
@@ -30,28 +31,28 @@ namespace Sass {
{
std
::
FILE
*
f
;
const
char
*
path_str
=
path
.
c_str
();
f
=
std
::
fopen
(
path_str
,
"rb"
);
if
(
!
f
)
{
string
path_with_extension
(
path
+
".scss"
);
f
=
std
::
fopen
(
path_with_extension
.
c_str
(),
"rb"
);
if
(
!
f
)
{
const
char
*
file_name_str
=
Prelexer
::
folders
(
path_str
);
string
path_with_underscore
(
Token
::
make
(
path_str
,
file_name_str
).
to_string
()
+
struct
stat
st
;
string
tmp
;
if
(
stat
(
path_str
,
&
st
)
==
-
1
||
S_ISDIR
(
st
.
st_mode
))
{
tmp
=
path
+
".scss"
;
path_str
=
tmp
.
c_str
();
if
(
stat
(
path_str
,
&
st
)
==
-
1
||
S_ISDIR
(
st
.
st_mode
))
{
const
char
*
full_path_str
=
path
.
c_str
();
const
char
*
file_name_str
=
Prelexer
::
folders
(
full_path_str
);
tmp
=
Token
::
make
(
full_path_str
,
file_name_str
).
to_string
()
+
"_"
+
Token
::
make
(
file_name_str
).
to_string
());
f
=
std
::
fopen
(
path_with_underscore
.
c_str
(),
"rb"
);
if
(
!
f
)
{
string
path_with_underscore_and_extension
(
path_with_underscore
+
".scss"
);
f
=
std
::
fopen
(
path_with_underscore_and_extension
.
c_str
(),
"rb"
);
if
(
!
f
)
throw
path
;
string
(
file_name_str
);
path_str
=
tmp
.
c_str
();
if
(
stat
(
path_str
,
&
st
)
==
-
1
||
S_ISDIR
(
st
.
st_mode
))
{
tmp
=
tmp
+
".scss"
;
path_str
=
tmp
.
c_str
();
if
(
stat
(
path_str
,
&
st
)
==
-
1
||
S_ISDIR
(
st
.
st_mode
))
throw
path
;
}
}
}
if
(
std
::
fseek
(
f
,
0
,
SEEK_END
))
throw
path
;
int
status
=
std
::
ftell
(
f
);
if
(
status
<
0
)
throw
path
;
size_t
len
=
status
;
std
::
rewind
(
f
);
f
=
std
::
fopen
(
path_str
,
"rb"
);
size_t
len
=
st
.
st_size
;
char
*
source
=
new
char
[
len
+
1
];
size_t
bytes_read
=
std
::
fread
(
source
,
sizeof
(
char
),
len
,
f
);
if
(
bytes_read
!=
len
)
{
...
...
@@ -61,6 +62,8 @@ namespace Sass {
source
[
len
]
=
'\0'
;
char
*
end
=
source
+
len
;
if
(
std
::
fclose
(
f
))
throw
path
;
const
char
*
file_name_str
=
Prelexer
::
folders
(
path_str
);
string
include_path
(
path_str
,
file_name_str
-
path_str
);
Document
doc
(
ctx
);
doc
.
path
=
path
;
...
...
@@ -72,6 +75,9 @@ namespace Sass {
doc
.
end
=
end
;
doc
.
position
=
source
;
doc
.
context
.
source_refs
.
push_back
(
source
);
if
(
!
include_path
.
empty
())
{
doc
.
context
.
include_paths
.
push_back
(
include_path
);
}
return
doc
;
}
...
...
document_parser.cpp
View file @
55c191c2
...
...
@@ -101,17 +101,16 @@ namespace Sass {
if
(
!
lex
<
string_constant
>
())
throw_syntax_error
(
"@import directive requires a url or quoted path"
);
// TO DO: BETTER PATH HANDLING
string
import_path
(
lexed
.
unquote
());
const
char
*
curr_path_start
=
path
.
c_str
();
const
char
*
curr_path_end
=
folders
(
curr_path_start
);
string
current_path
(
curr_path_start
,
curr_path_end
-
curr_path_start
);
for
(
vector
<
string
>::
iterator
path
=
context
.
include_paths
.
begin
();
path
<
context
.
include_paths
.
end
();
++
path
)
{
try
{
Document
importee
(
Document
::
make_from_file
(
context
,
current_
path
+
import_path
));
Document
importee
(
Document
::
make_from_file
(
context
,
*
path
+
import_path
));
importee
.
parse_scss
();
return
importee
.
root
;
}
catch
(
string
&
path
)
{
throw_read_error
(
"error reading file
\"
"
+
path
+
"
\"
"
);
}
}
throw_read_error
(
"error reading file
\"
"
+
import_path
+
"
\"
"
);
// unreached statement
return
Node
();
}
...
...
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