Initial commit
[yaffs-website] / node_modules / node-sass / src / libsass / src / context.hpp
1 #ifndef SASS_CONTEXT_H
2 #define SASS_CONTEXT_H
3
4 #include <string>
5 #include <vector>
6 #include <map>
7
8 #define BUFFERSIZE 255
9 #include "b64/encode.h"
10
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"
18 #include "output.hpp"
19 #include "plugins.hpp"
20 #include "file.hpp"
21
22
23 struct Sass_Function;
24
25 namespace Sass {
26
27   class Context {
28   public:
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); };
34
35   private:
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);
37
38   public:
39     const std::string CWD;
40     struct Sass_Options& c_options;
41     std::string entry_path;
42     size_t head_imports;
43     Plugins plugins;
44     Output emitter;
45
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;
54
55     struct Sass_Compiler* c_compiler;
56
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
62
63     std::vector<std::string> plugin_paths; // relative paths to load plugins
64     std::vector<std::string> include_paths; // lookup paths for includes
65
66
67
68
69
70     void apply_custom_headers(Block_Obj root, const char* path, ParserState pstate);
71
72     std::vector<Sass_Importer_Entry> c_headers;
73     std::vector<Sass_Importer_Entry> c_importers;
74     std::vector<Sass_Function_Entry> c_functions;
75
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);
79
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)
86
87     virtual ~Context();
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();
93
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);
97
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);
100
101   private:
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);
108
109
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);
114
115   public:
116     const std::string& cwd() { return CWD; };
117   };
118
119   class File_Context : public Context {
120   public:
121     File_Context(struct Sass_File_Context& ctx)
122     : Context(ctx)
123     { }
124     virtual ~File_Context();
125     virtual Block_Obj parse();
126   };
127
128   class Data_Context : public Context {
129   public:
130     char* source_c_str;
131     char* srcmap_c_str;
132     Data_Context(struct Sass_Data_Context& ctx)
133     : Context(ctx)
134     {
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
139     }
140     virtual ~Data_Context();
141     virtual Block_Obj parse();
142   };
143
144 }
145
146 #endif