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