Skip to content

Commit

Permalink
Merge pull request #89 from dorny/master
Browse files Browse the repository at this point in the history
Looks good! Sorry for the long delay. I'll probably make some changes later so that source maps and comments aren't mutually exclusive.
  • Loading branch information
Aaron Leung committed May 13, 2013
2 parents a83ea46 + f5911c3 commit 4d44a4d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace Sass {
// }
}

Context::Context(const char* paths_str, const char* img_path_str, bool sc)
Context::Context(const char* paths_str, const char* img_path_str, int sc)
: global_env(Environment()),
function_env(map<string, Function>()),
extensions(multimap<Node, Node>()),
Expand Down
4 changes: 2 additions & 2 deletions context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ namespace Sass {
// string sass_path;
// string css_path;
bool has_extensions;
bool source_comments;
int source_comments;

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

void register_function(Signature sig, Primitive ip);
Expand Down
8 changes: 8 additions & 0 deletions node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ namespace Sass {
}
}

string Node::debug_info_path() const
{
char* c_abs_path = realpath( path().c_str(), NULL);
string abs_path(c_abs_path);
delete c_abs_path;
return abs_path;
}

bool Node::operator==(Node rhs) const
{
Type t = type(), u = rhs.type();
Expand Down
3 changes: 2 additions & 1 deletion node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ namespace Sass {
bool& is_splat() const;

string& path() const;
string debug_info_path() const;
size_t line() const;
size_t size() const;
bool empty() const;
Expand Down Expand Up @@ -247,7 +248,7 @@ namespace Sass {
bool operator>=(Node rhs) const;

string to_string(Type inside_of = none, const string space = " ", const bool in_media_feature = false) const;
void emit_nested_css(stringstream& buf, size_t depth, bool at_toplevel = false, bool in_media_query = false, bool source_comments = false);
void emit_nested_css(stringstream& buf, size_t depth, bool at_toplevel = false, bool in_media_query = false, int 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
14 changes: 12 additions & 2 deletions node_emitters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cmath>
#include <sstream>
#include "node.hpp"
#include "sass_interface.h"

using std::string;
using std::stringstream;
Expand Down Expand Up @@ -419,7 +420,7 @@ namespace Sass {
}
}

void Node::emit_nested_css(stringstream& buf, size_t depth, bool at_toplevel, bool in_media_query, bool source_comments)
void Node::emit_nested_css(stringstream& buf, size_t depth, bool at_toplevel, bool in_media_query, int source_comments)
{
switch (type())
{
Expand All @@ -438,7 +439,16 @@ namespace Sass {
if (block.has_statements() || block.has_comments()) {
if (source_comments) {
buf << string(2*depth, ' ');
buf << "/* line " << sel_group.line() << ", " << sel_group.path() << " */" << endl;
switch (source_comments)
{
case SASS_SOURCE_COMMENTS_DEFAULT: {
buf << "/* line " << sel_group.line() << ", " << sel_group.path() << " */" << endl;
} break;
case SASS_SOURCE_COMMENTS_MAP: {
buf << "@media -sass-debug-info{filename{font-family:file:" << sel_group.debug_info_path() << "}line{font-family:\\00003" << sel_group.line() << "}}" << endl;
} break;
default: break;
}
}
buf << string(2*depth, ' ');
buf << sel_group.to_string();
Expand Down
4 changes: 4 additions & 0 deletions sass_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ extern "C" {
#define SASS_STYLE_COMPACT 2
#define SASS_STYLE_COMPRESSED 3

#define SASS_SOURCE_COMMENTS_NONE 0
#define SASS_SOURCE_COMMENTS_DEFAULT 1
#define SASS_SOURCE_COMMENTS_MAP 2

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

0 comments on commit 4d44a4d

Please sign in to comment.