9 #include "b64/encode.h"
11 #include "ast_fwd_decl.hpp"
12 #include "kwd_arg_macros.hpp"
13 #include "ast_fwd_decl.hpp"
14 #include "sass_context.hpp"
15 #include "environment.hpp"
16 #include "source_map.hpp"
17 #include "subset_map.hpp"
19 #include "plugins.hpp"
29 void import_url (Import_Ptr imp, std::string load_path, const std::string& ctx_path);
30 bool call_headers(const std::string& load_path, const char* ctx_path, ParserState& pstate, Import_Ptr imp)
31 { return call_loader(load_path, ctx_path, pstate, imp, c_headers, false); };
32 bool call_importers(const std::string& load_path, const char* ctx_path, ParserState& pstate, Import_Ptr imp)
33 { return call_loader(load_path, ctx_path, pstate, imp, c_importers, true); };
36 bool call_loader(const std::string& load_path, const char* ctx_path, ParserState& pstate, Import_Ptr imp, std::vector<Sass_Importer_Entry> importers, bool only_one = true);
39 const std::string CWD;
40 struct Sass_Options& c_options;
41 std::string entry_path;
46 // resources add under our control
47 // these are guaranteed to be freed
48 std::vector<char*> strings;
49 std::vector<Resource> resources;
50 std::map<const std::string, StyleSheet> sheets;
51 Subset_Map subset_map;
52 std::vector<Sass_Import_Entry> import_stack;
53 std::vector<Sass_Callee> callee_stack;
55 struct Sass_Compiler* c_compiler;
57 // absolute paths to includes
58 std::vector<std::string> included_files;
59 // relative includes for sourcemap
60 std::vector<std::string> srcmap_links;
61 // vectors above have same size
63 std::vector<std::string> plugin_paths; // relative paths to load plugins
64 std::vector<std::string> include_paths; // lookup paths for includes
70 void apply_custom_headers(Block_Obj root, const char* path, ParserState pstate);
72 std::vector<Sass_Importer_Entry> c_headers;
73 std::vector<Sass_Importer_Entry> c_importers;
74 std::vector<Sass_Function_Entry> c_functions;
76 void add_c_header(Sass_Importer_Entry header);
77 void add_c_importer(Sass_Importer_Entry importer);
78 void add_c_function(Sass_Function_Entry function);
80 const std::string indent; // String to be used for indentation
81 const std::string linefeed; // String to be used for line feeds
82 const std::string input_path; // for relative paths in src-map
83 const std::string output_path; // for relative paths to the output
84 const std::string source_map_file; // path to source map file (enables feature)
85 const std::string source_map_root; // path for sourceRoot property (pass-through)
88 Context(struct Sass_Context&);
89 virtual Block_Obj parse() = 0;
90 virtual Block_Obj compile();
91 virtual char* render(Block_Obj root);
92 virtual char* render_srcmap();
94 void register_resource(const Include&, const Resource&, ParserState* = 0);
95 std::vector<Include> find_includes(const Importer& import);
96 Include load_import(const Importer&, ParserState pstate);
98 Sass_Output_Style output_style() { return c_options.output_style; };
99 std::vector<std::string> get_included_files(bool skip = false, size_t headers = 0);
102 void collect_plugin_paths(const char* paths_str);
103 void collect_plugin_paths(string_list* paths_array);
104 void collect_include_paths(const char* paths_str);
105 void collect_include_paths(string_list* paths_array);
106 std::string format_embedded_source_map();
107 std::string format_source_mapping_url(const std::string& out_path);
110 // void register_built_in_functions(Env* env);
111 // void register_function(Signature sig, Native_Function f, Env* env);
112 // void register_function(Signature sig, Native_Function f, size_t arity, Env* env);
113 // void register_overload_stub(std::string name, Env* env);
116 const std::string& cwd() { return CWD; };
119 class File_Context : public Context {
121 File_Context(struct Sass_File_Context& ctx)
124 virtual ~File_Context();
125 virtual Block_Obj parse();
128 class Data_Context : public Context {
132 Data_Context(struct Sass_Data_Context& ctx)
135 source_c_str = ctx.source_string;
136 srcmap_c_str = ctx.srcmap_string;
137 ctx.source_string = 0; // passed away
138 ctx.srcmap_string = 0; // passed away
140 virtual ~Data_Context();
141 virtual Block_Obj parse();