void Inspect::operator()(Import* import) { if (!import->urls().empty()) { append_token("@import", import); append_mandatory_space(); if (String_Quoted* strq = dynamic_cast<String_Quoted*>(import->urls().front())) { strq->is_delayed(false); } import->urls().front()->perform(this); if (import->media_queries()) { append_mandatory_space(); import->media_queries()->perform(this); } append_delimiter(); for (size_t i = 1, S = import->urls().size(); i < S; ++i) { append_mandatory_linefeed(); append_token("@import", import); append_mandatory_space(); if (String_Quoted* strq = dynamic_cast<String_Quoted*>(import->urls()[i])) { strq->is_delayed(false); } import->urls()[i]->perform(this); if (import->media_queries()) { append_mandatory_space(); import->media_queries()->perform(this); } append_delimiter(); } } }
void Output::operator()(Directive* a) { std::string kwd = a->keyword(); Selector* s = a->selector(); Expression* v = a->value(); Block* b = a->block(); append_indentation(); append_token(kwd, a); if (s) { append_mandatory_space(); in_wrapped = true; s->perform(this); in_wrapped = false; } if (v) { append_mandatory_space(); // ruby sass bug? should use options? append_token(v->to_string(/* opt */), v); } if (!b) { append_delimiter(); return; } if (b->is_invisible() || b->length() == 0) { append_optional_space(); return append_string("{}"); } append_scope_opener(); bool format = kwd != "@font-face";; for (size_t i = 0, L = b->length(); i < L; ++i) { Statement* stm = (*b)[i]; if (!stm->is_hoistable()) { stm->perform(this); if (i < L - 1 && format) append_special_linefeed(); } } for (size_t i = 0, L = b->length(); i < L; ++i) { Statement* stm = (*b)[i]; if (stm->is_hoistable()) { stm->perform(this); if (i < L - 1 && format) append_special_linefeed(); } } append_scope_closer(); }
void Inspect::operator()(Definition* def) { append_indentation(); if (def->type() == Definition::MIXIN) { append_token("@mixin", def); append_mandatory_space(); } else { append_token("@function", def); append_mandatory_space(); } append_string(def->name()); def->parameters()->perform(this); def->block()->perform(this); }
void Output::operator()(Media_Block* m) { if (m->is_invisible()) return; List* q = m->media_queries(); Block* b = m->block(); // Filter out media blocks that aren't printable (process its children though) if (!Util::isPrintable(m, output_style())) { for (size_t i = 0, L = b->length(); i < L; ++i) { Statement* stm = (*b)[i]; if (dynamic_cast<Has_Block*>(stm)) { stm->perform(this); } } return; } if (output_style() == NESTED) indentation += m->tabs(); append_indentation(); append_token("@media", m); append_mandatory_space(); in_media_block = true; q->perform(this); in_media_block = false; append_scope_opener(); for (size_t i = 0, L = b->length(); i < L; ++i) { if ((*b)[i]) (*b)[i]->perform(this); if (i < L - 1) append_special_linefeed(); } if (output_style() == NESTED) indentation -= m->tabs(); append_scope_closer(); }
void Output::operator()(Supports_Block* f) { if (f->is_invisible()) return; Supports_Condition* c = f->condition(); Block* b = f->block(); // Filter out feature blocks that aren't printable (process its children though) if (!Util::isPrintable(f, output_style())) { for (size_t i = 0, L = b->length(); i < L; ++i) { Statement* stm = (*b)[i]; if (dynamic_cast<Has_Block*>(stm)) { stm->perform(this); } } return; } if (output_style() == NESTED) indentation += f->tabs(); append_indentation(); append_token("@supports", f); append_mandatory_space(); c->perform(this); append_scope_opener(); if (b->has_non_hoistable()) { // JMA - hoisted, output the non-hoistable in a nested block, followed by the hoistable append_scope_opener(); for (size_t i = 0, L = b->length(); i < L; ++i) { Statement* stm = (*b)[i]; if (!stm->is_hoistable()) { stm->perform(this); } } append_scope_closer(); for (size_t i = 0, L = b->length(); i < L; ++i) { Statement* stm = (*b)[i]; if (stm->is_hoistable()) { stm->perform(this); } } } else { // JMA - not hoisted, just output in order for (size_t i = 0, L = b->length(); i < L; ++i) { Statement* stm = (*b)[i]; stm->perform(this); if (i < L - 1) append_special_linefeed(); } } if (output_style() == NESTED) indentation -= f->tabs(); append_scope_closer(); }
void Inspect::operator()(Extension* extend) { append_indentation(); append_token("@extend", extend); append_mandatory_space(); extend->selector()->perform(this); append_delimiter(); }
void Inspect::operator()(Supports_Negation* sn) { append_token("not", sn); append_mandatory_space(); if (sn->needs_parens(sn->condition())) append_string("("); sn->condition()->perform(this); if (sn->needs_parens(sn->condition())) append_string(")"); }
void Inspect::operator()(While* loop) { append_indentation(); append_token("@while", loop); append_mandatory_space(); loop->predicate()->perform(this); loop->block()->perform(this); }
void Inspect::operator()(Supports_Block* feature_block) { append_indentation(); append_token("@supports", feature_block); append_mandatory_space(); feature_block->condition()->perform(this); feature_block->block()->perform(this); }
void Inspect::operator()(At_Root_Block* at_root_block) { append_indentation(); append_token("@at-root ", at_root_block); append_mandatory_space(); if(at_root_block->expression()) at_root_block->expression()->perform(this); at_root_block->block()->perform(this); }
void Inspect::operator()(Debug* debug) { append_indentation(); append_token("@debug", debug); append_mandatory_space(); debug->value()->perform(this); append_delimiter(); }
void Inspect::operator()(Error* error) { append_indentation(); append_token("@error", error); append_mandatory_space(); error->message()->perform(this); append_delimiter(); }
void Inspect::operator()(Warning* warning) { append_indentation(); append_token("@warn", warning); append_mandatory_space(); warning->message()->perform(this); append_delimiter(); }
void Inspect::operator()(Import_Stub* import) { append_indentation(); append_token("@import", import); append_mandatory_space(); append_string(import->file_name()); append_delimiter(); }
void Inspect::operator()(Return* ret) { append_indentation(); append_token("@return", ret); append_mandatory_space(); ret->value()->perform(this); append_delimiter(); }
void Emitter::append_optional_space() { if (output_style() != COMPRESSED && buffer().size()) { char lst = buffer().at(buffer().length() - 1); if (!isspace(lst) || scheduled_delimiter) { append_mandatory_space(); } } }
void Emitter::append_optional_linefeed() { if (in_declaration && in_comma_array) return; if (output_style() == COMPACT) { append_mandatory_space(); } else { append_mandatory_linefeed(); } }
void Inspect::operator()(Media_Block* media_block) { append_indentation(); append_token("@media", media_block); append_mandatory_space(); in_media_block = true; media_block->media_queries()->perform(this); in_media_block = false; media_block->block()->perform(this); }
void Inspect::operator()(For* loop) { append_indentation(); append_token("@for", loop); append_mandatory_space(); append_string(loop->variable()); append_string(" from "); loop->lower_bound()->perform(this); append_string(loop->is_inclusive() ? " through " : " to "); loop->upper_bound()->perform(this); loop->block()->perform(this); }
void Inspect::operator()(Supports_Operator* so) { if (so->needs_parens(so->left())) append_string("("); so->left()->perform(this); if (so->needs_parens(so->left())) append_string(")"); if (so->operand() == Supports_Operator::AND) { append_mandatory_space(); append_token("and", so); append_mandatory_space(); } else if (so->operand() == Supports_Operator::OR) { append_mandatory_space(); append_token("or", so); append_mandatory_space(); } if (so->needs_parens(so->right())) append_string("("); so->right()->perform(this); if (so->needs_parens(so->right())) append_string(")"); }
void Inspect::operator()(At_Rule* at_rule) { append_indentation(); append_token(at_rule->keyword(), at_rule); if (at_rule->selector()) { append_mandatory_space(); bool was_wrapped = in_wrapped; in_wrapped = true; at_rule->selector()->perform(this); in_wrapped = was_wrapped; } if (at_rule->value()) { append_mandatory_space(); at_rule->value()->perform(this); } if (at_rule->block()) { at_rule->block()->perform(this); } else { append_delimiter(); } }
void Emitter::append_delimiter() { scheduled_delimiter = true; if (output_style() == COMPACT) { if (indentation == 0) { append_mandatory_linefeed(); } else { append_mandatory_space(); } } else if (output_style() != COMPRESSED) { append_optional_linefeed(); } }
void Inspect::operator()(If* cond) { append_indentation(); append_token("@if", cond); append_mandatory_space(); cond->predicate()->perform(this); cond->block()->perform(this); if (cond->alternative()) { append_optional_linefeed(); append_indentation(); append_string("else"); cond->alternative()->perform(this); } }
void Inspect::operator()(Each* loop) { append_indentation(); append_token("@each", loop); append_mandatory_space(); append_string(loop->variables()[0]); for (size_t i = 1, L = loop->variables().size(); i < L; ++i) { append_comma_separator(); append_string(loop->variables()[i]); } append_string(" in "); loop->list()->perform(this); loop->block()->perform(this); }
void Inspect::operator()(Complex_Selector* c) { Compound_Selector* head = c->head(); Complex_Selector* tail = c->tail(); Complex_Selector::Combinator comb = c->combinator(); if (c->has_line_feed()) { if (!(c->has_parent_ref())) { append_optional_linefeed(); append_indentation(); } } if (head && head->length() != 0) head->perform(this); bool is_empty = !head || head->length() == 0 || head->is_empty_reference(); bool is_tail = head && !head->is_empty_reference() && tail; if (output_style() == COMPRESSED && comb != Complex_Selector::ANCESTOR_OF) scheduled_space = 0; switch (comb) { case Complex_Selector::ANCESTOR_OF: if (is_tail) append_mandatory_space(); break; case Complex_Selector::PARENT_OF: append_optional_space(); append_string(">"); append_optional_space(); break; case Complex_Selector::ADJACENT_TO: append_optional_space(); append_string("+"); append_optional_space(); break; case Complex_Selector::REFERENCE: append_mandatory_space(); append_string("/"); c->reference()->perform(this); append_string("/"); append_mandatory_space(); break; case Complex_Selector::PRECEDES: if (is_empty) append_optional_space(); else append_mandatory_space(); append_string("~"); if (tail) append_mandatory_space(); else append_optional_space(); break; } if (tail && comb != Complex_Selector::ANCESTOR_OF) { if (c->has_line_break()) append_optional_linefeed(); } if (tail) tail->perform(this); if (!tail && c->has_line_break()) { if (output_style() == COMPACT) { append_mandatory_space(); } } }
void Inspect::operator()(Mixin_Call* call) { append_indentation(); append_token("@include", call); append_mandatory_space(); append_string(call->name()); if (call->arguments()) { call->arguments()->perform(this); } if (call->block()) { append_optional_space(); call->block()->perform(this); } if (!call->block()) append_delimiter(); }