Commit b3e8d772 by Aaron Leung

Properly handling the image-url function.

parent e2f54e2f
#include "context.hpp" #include "context.hpp"
#include <cstring>
#include <iostream> #include <iostream>
#include <unistd.h> #include <unistd.h>
#include "prelexer.hpp" #include "prelexer.hpp"
...@@ -41,7 +42,7 @@ namespace Sass { ...@@ -41,7 +42,7 @@ namespace Sass {
// } // }
} }
Context::Context(const char* paths_str) Context::Context(const char* paths_str, const char* img_path_str)
: global_env(Environment()), : global_env(Environment()),
function_env(map<string, Function>()), function_env(map<string, Function>()),
extensions(multimap<Node, Node>()), extensions(multimap<Node, Node>()),
...@@ -58,6 +59,11 @@ namespace Sass { ...@@ -58,6 +59,11 @@ namespace Sass {
register_functions(); register_functions();
collect_include_paths(paths_str); collect_include_paths(paths_str);
setup_color_map(); setup_color_map();
string path_string(img_path_str);
path_string = "'" + path_string + "/'";
image_path = new char[path_string.length() + 1];
std::strcpy(image_path, path_string.c_str());
} }
Context::~Context() Context::~Context()
...@@ -65,6 +71,7 @@ namespace Sass { ...@@ -65,6 +71,7 @@ namespace Sass {
for (size_t i = 0; i < source_refs.size(); ++i) { for (size_t i = 0; i < source_refs.size(); ++i) {
delete[] source_refs[i]; delete[] source_refs[i];
} }
delete[] image_path;
new_Node.free(); new_Node.free();
// cerr << "Deallocated " << i << " source string(s)." << endl; // cerr << "Deallocated " << i << " source string(s)." << endl;
} }
......
...@@ -57,7 +57,7 @@ namespace Sass { ...@@ -57,7 +57,7 @@ namespace Sass {
bool has_extensions; bool has_extensions;
void collect_include_paths(const char* paths_str); void collect_include_paths(const char* paths_str);
Context(const char* paths_str = 0); Context(const char* paths_str = 0, const char* img_path_str = 0);
~Context(); ~Context();
void register_function(Function_Descriptor d, Primitive ip); void register_function(Function_Descriptor d, Primitive ip);
......
...@@ -813,9 +813,11 @@ namespace Sass { ...@@ -813,9 +813,11 @@ namespace Sass {
const char* value = position; const char* value = position;
const char* rparen = find_first< exactly<')'> >(position); const char* rparen = find_first< exactly<')'> >(position);
if (!rparen) throw_syntax_error("URI is missing ')'"); if (!rparen) throw_syntax_error("URI is missing ')'");
Token contents(Token::make(value, rparen)); Token content_tok(Token::make(value, rparen));
Node content_node(context.new_Node(Node::string_constant, path, line, content_tok));
// lex< string_constant >(); // lex< string_constant >();
Node result(context.new_Node(Node::uri, path, line, contents)); Node result(context.new_Node(Node::uri, path, line, 1));
result << content_node;
position = rparen; position = rparen;
lex< exactly<')'> >(); lex< exactly<')'> >();
return result; return result;
......
...@@ -293,8 +293,10 @@ namespace Sass { ...@@ -293,8 +293,10 @@ namespace Sass {
Node base(eval(expr[0], prefix, env, f_env, new_Node, ctx)); Node base(eval(expr[0], prefix, env, f_env, new_Node, ctx));
Node prefix(new_Node(Node::identifier, base.path(), base.line(), Token::make(ctx.image_path))); Node prefix(new_Node(Node::identifier, base.path(), base.line(), Token::make(ctx.image_path)));
Node fullpath(new_Node(Node::concatenation, base.path(), base.line(), 2)); Node fullpath(new_Node(Node::concatenation, base.path(), base.line(), 2));
Node url(new_Node(Node::uri, base.path(), base.line(), 1));
fullpath << prefix << base; fullpath << prefix << base;
return fullpath; url << fullpath;
return url;
} break; } break;
case Node::function_call: { case Node::function_call: {
......
...@@ -268,7 +268,8 @@ namespace Sass { ...@@ -268,7 +268,8 @@ namespace Sass {
case uri: { case uri: {
string result("url("); string result("url(");
result += token().to_string(); // result += token().to_string();
result += at(0).to_string();
result += ")"; result += ")";
return result; return result;
} break; } break;
......
...@@ -58,8 +58,8 @@ extern "C" { ...@@ -58,8 +58,8 @@ extern "C" {
{ {
using namespace Sass; using namespace Sass;
try { try {
Context cpp_ctx(c_ctx->options.include_paths); Context cpp_ctx(c_ctx->options.include_paths, c_ctx->options.image_path);
cpp_ctx.image_path = c_ctx->options.image_path; // cpp_ctx.image_path = c_ctx->options.image_path;
// Document doc(0, c_ctx->input_string, cpp_ctx); // Document doc(0, c_ctx->input_string, cpp_ctx);
Document doc(Document::make_from_source_chars(cpp_ctx, c_ctx->source_string)); Document doc(Document::make_from_source_chars(cpp_ctx, c_ctx->source_string));
c_ctx->output_string = process_document(doc, c_ctx->options.output_style); c_ctx->output_string = process_document(doc, c_ctx->options.output_style);
...@@ -94,9 +94,11 @@ extern "C" { ...@@ -94,9 +94,11 @@ extern "C" {
{ {
using namespace Sass; using namespace Sass;
try { try {
Context cpp_ctx(c_ctx->options.include_paths); Context cpp_ctx(c_ctx->options.include_paths, c_ctx->options.image_path);
// Document doc(c_ctx->input_path, 0, cpp_ctx); // Document doc(c_ctx->input_path, 0, cpp_ctx);
cpp_ctx.image_path = c_ctx->options.image_path; // string path_string(c_ctx->options.image_path);
// path_string = "'" + path_string + "/";
// cpp_ctx.image_path = c_ctx->options.image_path;
Document doc(Document::make_from_file(cpp_ctx, string(c_ctx->input_path))); Document doc(Document::make_from_file(cpp_ctx, string(c_ctx->input_path)));
// cerr << "MADE A DOC AND CONTEXT OBJ" << endl; // cerr << "MADE A DOC AND CONTEXT OBJ" << endl;
// cerr << "REGISTRY: " << doc.context.registry.size() << endl; // cerr << "REGISTRY: " << doc.context.registry.size() << endl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment