#ifndef SASS_CONTEXT_H #define SASS_CONTEXT_H #include #include #include #define BUFFERSIZE 255 #include "b64/encode.h" #include "ast_fwd_decl.hpp" #include "kwd_arg_macros.hpp" #include "memory_manager.hpp" #include "ast_fwd_decl.hpp" #include "sass_context.hpp" #include "environment.hpp" #include "source_map.hpp" #include "subset_map.hpp" #include "output.hpp" #include "plugins.hpp" #include "file.hpp" struct Sass_Function; namespace Sass { class Context { public: void import_url (Import* imp, std::string load_path, const std::string& ctx_path); bool call_headers(const std::string& load_path, const char* ctx_path, ParserState& pstate, Import* imp) { return call_loader(load_path, ctx_path, pstate, imp, c_headers, false); }; bool call_importers(const std::string& load_path, const char* ctx_path, ParserState& pstate, Import* imp) { return call_loader(load_path, ctx_path, pstate, imp, c_importers, true); }; private: bool call_loader(const std::string& load_path, const char* ctx_path, ParserState& pstate, Import* imp, std::vector importers, bool only_one = true); public: const std::string CWD; std::string entry_path; size_t head_imports; Memory_Manager mem; Plugins plugins; Output emitter; // resources add under our control // these are guaranteed to be freed std::vector strings; std::vector resources; std::map sheets; Subset_Map > subset_map; std::vector import_stack; struct Sass_Compiler* c_compiler; struct Sass_Options* c_options; // absolute paths to includes std::vector included_files; // relative includes for sourcemap std::vector srcmap_links; // vectors above have same size std::vector plugin_paths; // relative paths to load plugins std::vector include_paths; // lookup paths for includes void apply_custom_headers(Block* root, const char* path, ParserState pstate); std::vector c_headers; std::vector c_importers; std::vector c_functions; void add_c_header(Sass_Importer_Entry header); void add_c_importer(Sass_Importer_Entry importer); void add_c_function(Sass_Function_Entry function); const std::string indent; // String to be used for indentation const std::string linefeed; // String to be used for line feeds const std::string input_path; // for relative paths in src-map const std::string output_path; // for relative paths to the output const std::string source_map_file; // path to source map file (enables feature) const std::string source_map_root; // path for sourceRoot property (pass-through) virtual ~Context(); Context(struct Sass_Context*); virtual Block* parse() = 0; virtual Block* compile(); virtual char* render(Block* root); virtual char* render_srcmap(); void register_resource(const Include&, const Resource&); std::vector find_includes(const Importer& import); Include load_import(const Importer&, ParserState pstate); Sass_Output_Style output_style() { return c_options->output_style; }; std::vector get_included_files(bool skip = false, size_t headers = 0); private: void collect_plugin_paths(const char* paths_str); void collect_plugin_paths(const char** paths_array); void collect_include_paths(const char* paths_str); void collect_include_paths(const char** paths_array); std::string format_embedded_source_map(); std::string format_source_mapping_url(const std::string& out_path); // void register_built_in_functions(Env* env); // void register_function(Signature sig, Native_Function f, Env* env); // void register_function(Signature sig, Native_Function f, size_t arity, Env* env); // void register_overload_stub(std::string name, Env* env); public: const std::string& cwd() { return CWD; }; }; class File_Context : public Context { public: File_Context(struct Sass_File_Context* ctx) : Context(ctx) { } virtual ~File_Context(); virtual Block* parse(); }; class Data_Context : public Context { public: char* source_c_str; char* srcmap_c_str; Data_Context(struct Sass_Data_Context* ctx) : Context(ctx) { source_c_str = ctx->source_string; srcmap_c_str = ctx->srcmap_string; ctx->source_string = 0; // passed away ctx->srcmap_string = 0; // passed away } virtual ~Data_Context(); virtual Block* parse(); }; } #endif