Skip to content

Commit

Permalink
Preserve the nested style output for bubbled media queries
Browse files Browse the repository at this point in the history
  • Loading branch information
xzyfer committed Jan 5, 2015
1 parent 5de59c0 commit c1eff65
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
12 changes: 7 additions & 5 deletions ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
};
Expand Down
22 changes: 21 additions & 1 deletion cssize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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();
Expand All @@ -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];
Expand Down Expand Up @@ -183,9 +198,11 @@ namespace Sass {
}
else {
previous_parent = static_cast<Has_Block*>(parent);
previous_parent->tabs(parent->tabs());

Has_Block* new_parent = static_cast<Has_Block*>(parent);
new_parent->block(slice);
new_parent->tabs(parent->tabs());

*result << new_parent;
}
Expand Down Expand Up @@ -216,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(),
Expand Down
4 changes: 3 additions & 1 deletion output_nested.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ namespace Sass {
return;
}

indentation += m->tabs();
indent();
ctx->source_map.add_mapping(m);
append_to_buffer("@media ");
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c1eff65

Please sign in to comment.