Commit b3e8d772 by Aaron Leung

Properly handling the image-url function.

parent e2f54e2f
#include "context.hpp"
#include <cstring>
#include <iostream>
#include <unistd.h>
#include "prelexer.hpp"
......@@ -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()),
function_env(map<string, Function>()),
extensions(multimap<Node, Node>()),
......@@ -58,6 +59,11 @@ namespace Sass {
register_functions();
collect_include_paths(paths_str);
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()
......@@ -65,6 +71,7 @@ namespace Sass {
for (size_t i = 0; i < source_refs.size(); ++i) {
delete[] source_refs[i];
}
delete[] image_path;
new_Node.free();
// cerr << "Deallocated " << i << " source string(s)." << endl;
}
......
......@@ -57,7 +57,7 @@ namespace Sass {
bool has_extensions;
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();
void register_function(Function_Descriptor d, Primitive ip);
......
......@@ -813,9 +813,11 @@ namespace Sass {
const char* value = position;
const char* rparen = find_first< exactly<')'> >(position);
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 >();
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;
lex< exactly<')'> >();
return result;
......
......@@ -293,8 +293,10 @@ namespace Sass {
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 fullpath(new_Node(Node::concatenation, base.path(), base.line(), 2));
Node url(new_Node(Node::uri, base.path(), base.line(), 1));
fullpath << prefix << base;
return fullpath;
url << fullpath;
return url;
} break;
case Node::function_call: {
......
......@@ -268,7 +268,8 @@ namespace Sass {
case uri: {
string result("url(");
result += token().to_string();
// result += token().to_string();
result += at(0).to_string();
result += ")";
return result;
} break;
......
......@@ -58,8 +58,8 @@ extern "C" {
{
using namespace Sass;
try {
Context cpp_ctx(c_ctx->options.include_paths);
cpp_ctx.image_path = c_ctx->options.image_path;
Context cpp_ctx(c_ctx->options.include_paths, 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(Document::make_from_source_chars(cpp_ctx, c_ctx->source_string));
c_ctx->output_string = process_document(doc, c_ctx->options.output_style);
......@@ -94,9 +94,11 @@ extern "C" {
{
using namespace Sass;
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);
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)));
// cerr << "MADE A DOC AND CONTEXT OBJ" << 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