Commit 7fdf5765 by Aaron Leung

Changing the echo emitter to return a string instead of writing to stdout.

parent 0782af78
...@@ -10,7 +10,7 @@ namespace Sass { ...@@ -10,7 +10,7 @@ namespace Sass {
for (int i = 0; i < statements.size(); ++i) { for (int i = 0; i < statements.size(); ++i) {
switch (style) { switch (style) {
case echo: case echo:
statements[i].echo(); statements[i].echo(output);
break; break;
case nested: case nested:
statements[i].emit_nested_css(output, 0, vector<string>()); statements[i].emit_nested_css(output, 0, vector<string>());
......
...@@ -12,47 +12,47 @@ namespace Sass { ...@@ -12,47 +12,47 @@ namespace Sass {
size_t Node::fresh = 0; size_t Node::fresh = 0;
size_t Node::copied = 0; size_t Node::copied = 0;
void Node::echo(size_t depth) { void Node::echo(stringstream& buf, size_t depth) {
string indentation(2*depth, ' '); string indentation(2*depth, ' ');
switch (type) { switch (type) {
case comment: case comment:
cout << indentation << string(token) << endl; buf << indentation << string(token) << endl;
break; break;
case ruleset: case ruleset:
cout << indentation; buf << indentation;
children->at(0).echo(depth); children->at(0).echo(buf, depth);
children->at(1).echo(depth); children->at(1).echo(buf, depth);
break; break;
case selector_group: case selector_group:
children->at(0).echo(depth); children->at(0).echo(buf, depth);
for (int i = 1; i < children->size(); ++i) { for (int i = 1; i < children->size(); ++i) {
cout << ", "; buf << ", ";
children->at(i).echo(depth); children->at(i).echo(buf, depth);
} }
break; break;
case selector: case selector:
cout << string(token); buf << string(token);
break; break;
case block: case block:
cout << " {" << endl; buf << " {" << endl;
for (int i = 0; i < children->size(); children->at(i++).echo(depth+1)) ; for (int i = 0; i < children->size(); children->at(i++).echo(buf, depth+1)) ;
cout << indentation << "}" << endl; buf << indentation << "}" << endl;
break; break;
case rule: case rule:
cout << indentation; buf << indentation;
children->at(0).echo(depth); children->at(0).echo(buf, depth);
cout << ':'; buf << ':';
children->at(1).echo(depth); children->at(1).echo(buf, depth);
cout << ';' << endl; buf << ';' << endl;
break; break;
case property: case property:
cout << string(token); buf << string(token);
break; break;
case values: case values:
for (int i = 0; i < children->size(); children->at(i++).echo(depth)) ; for (int i = 0; i < children->size(); children->at(i++).echo(buf, depth)) ;
break; break;
case value: case value:
cout << ' ' << string(token); buf << ' ' << string(token);
break; break;
} }
} }
......
...@@ -155,7 +155,7 @@ namespace Sass { ...@@ -155,7 +155,7 @@ namespace Sass {
void release() const { children = 0; } void release() const { children = 0; }
void echo(size_t depth = 0); void echo(stringstream& buf, size_t depth = 0);
void emit_nested_css(stringstream& buf, void emit_nested_css(stringstream& buf,
size_t depth, size_t depth,
const vector<string>& prefixes); const vector<string>& prefixes);
......
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