1#ifndef SASS_CONTEXT_H
2#define SASS_CONTEXT_H
3
4// sass.hpp must go before all system headers to get the
5// __EXTENSIONS__ fix on Solaris.
6#include "sass.hpp"
7#include "ast.hpp"
8
9
10#define BUFFERSIZE 255
11#include "b64/encode.h"
12
13#include "sass_context.hpp"
14#include "stylesheet.hpp"
15#include "plugins.hpp"
16#include "output.hpp"
17
18namespace Sass {
19
20 class Context {
21 public:
22 void import_url (Import* imp, sass::string load_path, const sass::string& ctx_path);
23 bool call_headers(const sass::string& load_path, const char* ctx_path, SourceSpan& pstate, Import* imp)
24 { return call_loader(load_path, ctx_path, pstate, imp, importers: c_headers, only_one: false); };
25 bool call_importers(const sass::string& load_path, const char* ctx_path, SourceSpan& pstate, Import* imp)
26 { return call_loader(load_path, ctx_path, pstate, imp, importers: c_importers, only_one: true); };
27
28 private:
29 bool call_loader(const sass::string& load_path, const char* ctx_path, SourceSpan& pstate, Import* imp, sass::vector<Sass_Importer_Entry> importers, bool only_one = true);
30
31 public:
32 const sass::string CWD;
33 struct Sass_Options& c_options;
34 sass::string entry_path;
35 size_t head_imports;
36 Plugins plugins;
37 Output emitter;
38
39 // generic ast node garbage container
40 // used to avoid possible circular refs
41 CallStack ast_gc;
42 // resources add under our control
43 // these are guaranteed to be freed
44 sass::vector<char*> strings;
45 sass::vector<Resource> resources;
46 std::map<const sass::string, StyleSheet> sheets;
47 ImporterStack import_stack;
48 sass::vector<Sass_Callee> callee_stack;
49 sass::vector<Backtrace> traces;
50 Extender extender;
51
52 struct Sass_Compiler* c_compiler;
53
54 // absolute paths to includes
55 sass::vector<sass::string> included_files;
56 // relative includes for sourcemap
57 sass::vector<sass::string> srcmap_links;
58 // vectors above have same size
59
60 sass::vector<sass::string> plugin_paths; // relative paths to load plugins
61 sass::vector<sass::string> include_paths; // lookup paths for includes
62
63 void apply_custom_headers(Block_Obj root, const char* path, SourceSpan pstate);
64
65 sass::vector<Sass_Importer_Entry> c_headers;
66 sass::vector<Sass_Importer_Entry> c_importers;
67 sass::vector<Sass_Function_Entry> c_functions;
68
69 void add_c_header(Sass_Importer_Entry header);
70 void add_c_importer(Sass_Importer_Entry importer);
71 void add_c_function(Sass_Function_Entry function);
72
73 const sass::string indent; // String to be used for indentation
74 const sass::string linefeed; // String to be used for line feeds
75 const sass::string input_path; // for relative paths in src-map
76 const sass::string output_path; // for relative paths to the output
77 const sass::string source_map_file; // path to source map file (enables feature)
78 const sass::string source_map_root; // path for sourceRoot property (pass-through)
79
80 virtual ~Context();
81 Context(struct Sass_Context&);
82 virtual Block_Obj parse() = 0;
83 virtual Block_Obj compile();
84 virtual char* render(Block_Obj root);
85 virtual char* render_srcmap();
86
87 void register_resource(const Include&, const Resource&);
88 void register_resource(const Include&, const Resource&, SourceSpan&);
89 sass::vector<Include> find_includes(const Importer& import);
90 Include load_import(const Importer&, SourceSpan pstate);
91
92 Sass_Output_Style output_style() { return c_options.output_style; };
93 sass::vector<sass::string> get_included_files(bool skip = false, size_t headers = 0);
94
95 private:
96 void collect_plugin_paths(const char* paths_str);
97 void collect_plugin_paths(string_list* paths_array);
98 void collect_include_paths(const char* paths_str);
99 void collect_include_paths(string_list* paths_array);
100 sass::string format_embedded_source_map();
101 sass::string format_source_mapping_url(const sass::string& out_path);
102
103
104 // void register_built_in_functions(Env* env);
105 // void register_function(Signature sig, Native_Function f, Env* env);
106 // void register_function(Signature sig, Native_Function f, size_t arity, Env* env);
107 // void register_overload_stub(sass::string name, Env* env);
108
109 public:
110 const sass::string& cwd() { return CWD; };
111 };
112
113 class File_Context : public Context {
114 public:
115 File_Context(struct Sass_File_Context& ctx)
116 : Context(ctx)
117 { }
118 virtual ~File_Context();
119 virtual Block_Obj parse();
120 };
121
122 class Data_Context : public Context {
123 public:
124 char* source_c_str;
125 char* srcmap_c_str;
126 Data_Context(struct Sass_Data_Context& ctx)
127 : Context(ctx)
128 {
129 source_c_str = ctx.source_string;
130 srcmap_c_str = ctx.srcmap_string;
131 ctx.source_string = 0; // passed away
132 ctx.srcmap_string = 0; // passed away
133 }
134 virtual ~Data_Context();
135 virtual Block_Obj parse();
136 };
137
138}
139
140#endif
141

source code of gtk/subprojects/libsass/src/context.hpp