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