diff --git a/ast.hpp b/ast.hpp index a6225ca651..d40fcfe413 100644 --- a/ast.hpp +++ b/ast.hpp @@ -173,6 +173,7 @@ namespace Sass { virtual ~Vectorized() = 0; size_t length() const { return elements_.size(); } bool empty() const { return elements_.empty(); } + T last() { return elements_.back(); } T& operator[](size_t i) { return elements_[i]; } const T& operator[](size_t i) const { return elements_[i]; } Vectorized& operator<<(T element) @@ -275,10 +276,12 @@ namespace Sass { private: ADD_PROPERTY(Block*, block); ADD_PROPERTY(Statement_Type, statement_type); + ADD_PROPERTY(size_t, tabs); + ADD_PROPERTY(bool, group_end); public: - Statement(string path, Position position, Statement_Type st = NONE) + Statement(string path, Position position, Statement_Type st = NONE, size_t t = 0) : AST_Node(path, position), - statement_type_(st) + statement_type_(st), tabs_(t), group_end_(false) { } virtual ~Statement() = 0; // needed for rearranging nested rulesets during CSS emission @@ -362,11 +365,10 @@ namespace Sass { class Bubble : public Statement { ADD_PROPERTY(Statement*, node); ADD_PROPERTY(Statement*, group_end); - ADD_PROPERTY(size_t, tabs); public: Bubble(string path, Position position, Statement* n, Statement* g = 0, size_t t = 0) - : Statement(path, position), node_(n), group_end_(g), tabs_(t) - { statement_type(BUBBLE); } + : Statement(path, position, Statement::BUBBLE, t), node_(n), group_end_(g) + { } bool bubbles() { return true; } ATTACH_OPERATIONS(); }; diff --git a/cssize.cpp b/cssize.cpp index cc41dc38eb..1b32487ba4 100644 --- a/cssize.cpp +++ b/cssize.cpp @@ -62,13 +62,25 @@ namespace Sass { { Block* bb = new Block(rr->block()->path(), rr->block()->position()); *bb += props; - // rules.each {|r| r.tabs += 1} if node.style == :nested rr->block(bb); + + for (size_t i = 0, L = rules->length(); i < L; i++) + { + (*rules)[i]->tabs((*rules)[i]->tabs() + 1); + } + rules->unshift(rr); } rules = debubble(rules)->block(); + if (!(!rules->length() || + !bubblable(rules->last()) || + parent()->statement_type() == Statement::RULESET)) + { + rules->last()->group_end(true); + } + return rules; } @@ -86,6 +98,8 @@ namespace Sass { m->position(), m->media_queries(), m->block()->perform(this)->block()); + mm->tabs(m->tabs()); + p_stack.pop_back(); return debubble(mm->block(), mm)->block(); @@ -100,6 +114,7 @@ namespace Sass { parent->position(), parent->selector(), bb); + new_rule->tabs(parent->tabs()); for (size_t i = 0, L = m->block()->length(); i < L; ++i) { *new_rule->block() << (*m->block())[i]; @@ -183,8 +198,11 @@ namespace Sass { } else { previous_parent = static_cast(parent); + previous_parent->tabs(parent->tabs()); + Has_Block* new_parent = static_cast(parent); new_parent->block(slice); + new_parent->tabs(parent->tabs()); *result << new_parent; } @@ -215,6 +233,9 @@ namespace Sass { ss = b->node(); } + ss->tabs(ss->tabs() + b->tabs()); + ss->group_end(b->group_end()); + if (!ss) continue; Block* bb = new (ctx.mem) Block(children->block()->path(), diff --git a/output_nested.cpp b/output_nested.cpp index 4b458f75ad..d50aa6c877 100644 --- a/output_nested.cpp +++ b/output_nested.cpp @@ -229,6 +229,7 @@ namespace Sass { return; } + indentation += m->tabs(); indent(); ctx->source_map.add_mapping(m); append_to_buffer("@media "); @@ -286,7 +287,8 @@ namespace Sass { buffer.erase(buffer.length()-1); if (ctx) ctx->source_map.remove_line(); - append_to_buffer(" }" + ctx->linefeed); + append_to_buffer(" }"); + if (m->group_end()) append_to_buffer(ctx->linefeed); } void Output_Nested::operator()(At_Rule* a)