7 #include "sass/context.h"
8 #include "ast_fwd_decl.hpp"
14 // return the current directory
15 // always with forward slashes
16 std::string get_cwd();
18 // test if path exists and is a file
19 bool file_exists(const std::string& file);
21 // return if given path is absolute
22 // works with *nix and windows paths
23 bool is_absolute_path(const std::string& path);
25 // return only the directory part of path
26 std::string dir_name(const std::string& path);
28 // return only the filename part of path
29 std::string base_name(const std::string&);
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);
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);
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);
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());
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());
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);
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);
59 // split a path string delimited by semicolons or colons (OS dependent)
60 std::vector<std::string> split_path_list(const char* paths);
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);
72 // requested import path
74 // parent context path
76 // base derived from context path
77 // this really just acts as a cache
78 std::string base_path;
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))
87 // a resolved include (final import)
88 class Include : public Importer {
90 // resolved absolute path
93 Include(const Importer& imp, std::string abs_path)
94 : Importer(imp), abs_path(abs_path)
103 // conected sourcemap
106 Resource(char* contents, char* srcmap)
107 : contents(contents), srcmap(srcmap)
111 // parsed stylesheet from loaded resource
112 class StyleSheet : public Resource {
117 StyleSheet(const Resource& res, Block_Obj root)
118 : Resource(res), root(root)
124 static std::vector<std::string> defaultExtensions = { ".scss", ".sass", ".css" };
126 std::vector<Include> resolve_includes(const std::string& root, const std::string& file,
127 const std::vector<std::string>& exts = defaultExtensions);