Skip to content

Commit

Permalink
Merge branch 'master' into mixin-content
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Leung committed Nov 22, 2012
2 parents 5605be0 + 957e472 commit c062aee
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
5 changes: 3 additions & 2 deletions context.cpp
Expand Up @@ -51,7 +51,7 @@ namespace Sass {
// }
}

Context::Context(const char* paths_str, const char* img_path_str)
Context::Context(const char* paths_str, const char* img_path_str, bool sc)
: global_env(Environment()),
function_env(map<string, Function>()),
extensions(multimap<Node, Node>()),
Expand All @@ -63,7 +63,8 @@ namespace Sass {
new_Node(Node_Factory()),
image_path(0),
ref_count(0),
has_extensions(false)
has_extensions(false),
source_comments(sc)
{
register_functions();
collect_include_paths(paths_str);
Expand Down
3 changes: 2 additions & 1 deletion context.hpp
Expand Up @@ -33,9 +33,10 @@ namespace Sass {
// string sass_path;
// string css_path;
bool has_extensions;
bool source_comments;

void collect_include_paths(const char* paths_str);
Context(const char* paths_str = 0, const char* img_path_str = 0);
Context(const char* paths_str = 0, const char* img_path_str = 0, bool sc = false);
~Context();

void register_function(Signature sig, Primitive ip);
Expand Down
2 changes: 1 addition & 1 deletion document.cpp
Expand Up @@ -146,7 +146,7 @@ namespace Sass {
root.echo(output);
break;
case nested:
root.emit_nested_css(output, 0, true);
root.emit_nested_css(output, 0, true, false, context.source_comments);
break;
case expanded:
root.emit_expanded_css(output, "");
Expand Down
2 changes: 1 addition & 1 deletion node.hpp
Expand Up @@ -240,7 +240,7 @@ namespace Sass {
bool operator>=(Node rhs) const;

string to_string(Type inside_of = none, const string space = " ") const;
void emit_nested_css(stringstream& buf, size_t depth, bool at_toplevel = false, bool in_media_query = false);
void emit_nested_css(stringstream& buf, size_t depth, bool at_toplevel = false, bool in_media_query = false, bool source_comments = false);
void emit_propset(stringstream& buf, size_t depth, const string& prefix, const bool compressed = false);
void echo(stringstream& buf, size_t depth = 0);
void emit_expanded_css(stringstream& buf, const string& prefix);
Expand Down
22 changes: 13 additions & 9 deletions node_emitters.cpp
Expand Up @@ -369,14 +369,14 @@ namespace Sass {
}
}

void Node::emit_nested_css(stringstream& buf, size_t depth, bool at_toplevel, bool in_media_query)
void Node::emit_nested_css(stringstream& buf, size_t depth, bool at_toplevel, bool in_media_query, bool source_comments)
{
switch (type())
{
case root: {
if (has_expansions()) flatten();
for (size_t i = 0, S = size(); i < S; ++i) {
at(i).emit_nested_css(buf, depth, true);
at(i).emit_nested_css(buf, depth, true, false, source_comments);
}
} break;

Expand All @@ -386,6 +386,10 @@ namespace Sass {

if (block.has_expansions()) block.flatten();
if (block.has_statements() || block.has_comments()) {
if (source_comments) {
buf << string(2*depth, ' ');
buf << "/* line " << sel_group.line() << ", " << sel_group.path() << " */" << endl;
}
buf << string(2*depth, ' ');
buf << sel_group.to_string();
buf << " {";
Expand All @@ -401,7 +405,7 @@ namespace Sass {
case block_directive:
case blockless_directive:
case warning: {
block[i].emit_nested_css(buf, depth+1);
block[i].emit_nested_css(buf, depth+1, false, false, source_comments);
} break;
default: break;
}
Expand All @@ -413,7 +417,7 @@ namespace Sass {
if (block.has_blocks()) {
for (size_t i = 0, S = block.size(); i < S; ++i) {
if (block[i].type() == ruleset || block[i].type() == media_query) {
block[i].emit_nested_css(buf, depth, false, false); // last arg should be in_media_query?
block[i].emit_nested_css(buf, depth, false, false, source_comments); // last arg should be in_media_query?
}
}
}
Expand All @@ -435,7 +439,7 @@ namespace Sass {
// just print out the comments without a block
for (size_t i = 0, S = block.size(); i < S; ++i) {
if (block[i].type() == comment)
block[i].emit_nested_css(buf, depth+1);
block[i].emit_nested_css(buf, depth+1, false, false, source_comments);
}
}
if (has_statements) {
Expand All @@ -457,7 +461,7 @@ namespace Sass {
case blockless_directive:
case warning: {
// if (stm_type != comment) buf << endl;
block[i].emit_nested_css(buf, depth+1);
block[i].emit_nested_css(buf, depth+1, false, false, source_comments);
} break;

default: break;
Expand All @@ -470,15 +474,15 @@ namespace Sass {
Type stm_type = block[i].type();
if (stm_type == comment && !has_statements) {
if (i > 0 && block[i-1].type() == ruleset) buf << endl;
block[i].emit_nested_css(buf, depth+1, false, true);
block[i].emit_nested_css(buf, depth+1, false, true, source_comments);
}
if (stm_type == ruleset || stm_type == media_query) {
buf << endl;
if (i > 0 &&
block[i-1].type() == ruleset &&
!block[i-1][1].has_blocks())
{ buf << endl; }
block[i].emit_nested_css(buf, depth+1, false, true);
block[i].emit_nested_css(buf, depth+1, false, true, source_comments);
}
}
}
Expand Down Expand Up @@ -510,7 +514,7 @@ namespace Sass {
default:
break;
}
block[i].emit_nested_css(buf, depth+1, false, in_media_query);
block[i].emit_nested_css(buf, depth+1, false, in_media_query, source_comments);
}
buf << " }" << endl;
if ((depth == 0) && at_toplevel && !in_media_query) buf << endl;
Expand Down
4 changes: 2 additions & 2 deletions sass_interface.cpp
Expand Up @@ -66,7 +66,7 @@ extern "C" {
{
using namespace Sass;
try {
Context cpp_ctx(c_ctx->options.include_paths, c_ctx->options.image_path);
Context cpp_ctx(c_ctx->options.include_paths, c_ctx->options.image_path, c_ctx->options.source_comments);
// 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));
Expand Down Expand Up @@ -102,7 +102,7 @@ extern "C" {
{
using namespace Sass;
try {
Context cpp_ctx(c_ctx->options.include_paths, c_ctx->options.image_path);
Context cpp_ctx(c_ctx->options.include_paths, c_ctx->options.image_path, c_ctx->options.source_comments);
// Document doc(c_ctx->input_path, 0, cpp_ctx);
// string path_string(c_ctx->options.image_path);
// path_string = "'" + path_string + "/";
Expand Down
1 change: 1 addition & 0 deletions sass_interface.h
Expand Up @@ -11,6 +11,7 @@ extern "C" {

struct sass_options {
int output_style;
int source_comments; // really want a bool, but C doesn't have them
char* include_paths;
char* image_path;
};
Expand Down

0 comments on commit c062aee

Please sign in to comment.