Permalink
Browse files

Adding an option to emit comments pointing to the source file and lin…

…e number.
  • Loading branch information...
1 parent aaa65af commit 957e47252c47e6311e7ab3f14aae10e30d4ff02d Aaron Leung committed Nov 21, 2012
Showing with 23 additions and 16 deletions.
  1. +3 −2 context.cpp
  2. +2 −1 context.hpp
  3. +1 −1 document.cpp
  4. +1 −1 node.hpp
  5. +13 −9 node_emitters.cpp
  6. +2 −2 sass_interface.cpp
  7. +1 −0 sass_interface.h
View
@@ -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>()),
@@ -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);
View
@@ -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);
View
@@ -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, "");
View
@@ -239,7 +239,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);
View
@@ -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;
@@ -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 << " {";
@@ -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;
}
@@ -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?
}
}
}
@@ -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) {
@@ -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;
@@ -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);
}
}
}
@@ -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;
View
@@ -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));
@@ -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 + "/";
View
@@ -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
@am11

am11 Jul 12, 2014

Member

@akhleung, C99's <stdbool.h> is now supported by all compilers (including msvc 2013).
On this note, is it possible to generate source maps JSON without map comments in CSS file? This option is very useful for implementers (unfortunately we don't have it with node-sass; its either have both or have none!)

char* include_paths;
char* image_path;
};

0 comments on commit 957e472

Please sign in to comment.