1 | #ifndef SASS_FILE_H |
2 | #define SASS_FILE_H |
3 | |
4 | // sass.hpp must go before all system headers to get the |
5 | // __EXTENSIONS__ fix on Solaris. |
6 | #include "sass.hpp" |
7 | |
8 | #include <string> |
9 | #include <vector> |
10 | |
11 | #include "sass/context.h" |
12 | #include "ast_fwd_decl.hpp" |
13 | |
14 | namespace Sass { |
15 | |
16 | namespace File { |
17 | |
18 | // return the current directory |
19 | // always with forward slashes |
20 | sass::string get_cwd(); |
21 | |
22 | // test if path exists and is a file |
23 | bool file_exists(const sass::string& file); |
24 | |
25 | // return if given path is absolute |
26 | // works with *nix and windows paths |
27 | bool is_absolute_path(const sass::string& path); |
28 | |
29 | // return only the directory part of path |
30 | sass::string dir_name(const sass::string& path); |
31 | |
32 | // return only the filename part of path |
33 | sass::string base_name(const sass::string&); |
34 | |
35 | // do a locigal clean up of the path |
36 | // no physical check on the filesystem |
37 | sass::string make_canonical_path (sass::string path); |
38 | |
39 | // join two path segments cleanly together |
40 | // but only if right side is not absolute yet |
41 | sass::string join_paths(sass::string root, sass::string name); |
42 | |
43 | // if the relative path is outside of the cwd we want want to |
44 | // show the absolute path in console messages |
45 | sass::string path_for_console(const sass::string& rel_path, const sass::string& abs_path, const sass::string& orig_path); |
46 | |
47 | // create an absolute path by resolving relative paths with cwd |
48 | sass::string rel2abs(const sass::string& path, const sass::string& base = "." , const sass::string& cwd = get_cwd()); |
49 | |
50 | // create a path that is relative to the given base directory |
51 | // path and base will first be resolved against cwd to make them absolute |
52 | sass::string abs2rel(const sass::string& path, const sass::string& base = "." , const sass::string& cwd = get_cwd()); |
53 | |
54 | // helper function to resolve a filename |
55 | // searching without variations in all paths |
56 | sass::string find_file(const sass::string& file, struct Sass_Compiler* options); |
57 | sass::string find_file(const sass::string& file, const sass::vector<sass::string> paths); |
58 | |
59 | // helper function to resolve a include filename |
60 | // this has the original resolve logic for sass include |
61 | sass::string find_include(const sass::string& file, const sass::vector<sass::string> paths); |
62 | |
63 | // split a path string delimited by semicolons or colons (OS dependent) |
64 | sass::vector<sass::string> split_path_list(const char* paths); |
65 | |
66 | // try to load the given filename |
67 | // returned memory must be freed |
68 | // will auto convert .sass files |
69 | char* read_file(const sass::string& file); |
70 | |
71 | } |
72 | |
73 | // requested import |
74 | class Importer { |
75 | public: |
76 | // requested import path |
77 | sass::string imp_path; |
78 | // parent context path |
79 | sass::string ctx_path; |
80 | // base derived from context path |
81 | // this really just acts as a cache |
82 | sass::string base_path; |
83 | public: |
84 | Importer(sass::string imp_path, sass::string ctx_path) |
85 | : imp_path(File::make_canonical_path(path: imp_path)), |
86 | ctx_path(File::make_canonical_path(path: ctx_path)), |
87 | base_path(File::dir_name(path: ctx_path)) |
88 | { } |
89 | }; |
90 | |
91 | // a resolved include (final import) |
92 | class Include : public Importer { |
93 | public: |
94 | // resolved absolute path |
95 | sass::string abs_path; |
96 | public: |
97 | Include(const Importer& imp, sass::string abs_path) |
98 | : Importer(imp), abs_path(abs_path) |
99 | { } |
100 | }; |
101 | |
102 | // a loaded resource |
103 | class Resource { |
104 | public: |
105 | // the file contents |
106 | char* contents; |
107 | // connected sourcemap |
108 | char* srcmap; |
109 | public: |
110 | Resource(char* contents, char* srcmap) |
111 | : contents(contents), srcmap(srcmap) |
112 | { } |
113 | }; |
114 | |
115 | namespace File { |
116 | |
117 | sass::vector<Include> resolve_includes(const sass::string& root, const sass::string& file, |
118 | const sass::vector<sass::string>& exts = { ".scss" , ".sass" , ".css" }); |
119 | |
120 | } |
121 | |
122 | } |
123 | |
124 | #endif |
125 | |