Example #1
0
 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);
   }
 }
Example #2
0
  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();
  }
Example #3
0
  void Inspect::operator()(Selector_Placeholder* s)
  {
    append_token(s->name(), s);
    if (s->has_line_break()) append_optional_linefeed();
    if (s->has_line_break()) append_indentation();

  }
Example #4
0
  void Inspect::operator()(Selector_List* g)
  {
    if (g->empty()) return;

    bool was_comma_array = in_comma_array;
    if (!in_declaration && in_comma_array) {
      append_string("(");
    }

    if (in_declaration) in_comma_array = true;

    for (size_t i = 0, L = g->length(); i < L; ++i) {
      if (!in_wrapped && i == 0) append_indentation();
      if ((*g)[i] == 0) continue;
      (*g)[i]->perform(this);
      if (i < L - 1) {
        scheduled_space = 0;
        append_comma_separator();
      }
    }

    in_comma_array = was_comma_array;
    if (!in_declaration && in_comma_array) {
      append_string(")");
    }

  }
Example #5
0
  void Inspect::operator()(Declaration* dec)
  {
    if (dec->value()->concrete_type() == Expression::NULL_VAL) return;
    bool was_decl = in_declaration;
    in_declaration = true;
    if (output_style() == NESTED)
      indentation += dec->tabs();
    append_indentation();
    dec->property()->perform(this);
    append_colon_separator();

    if (dec->value()->concrete_type() == Expression::SELECTOR) {
      Listize listize(*ctx);
      dec->value()->perform(&listize)->perform(this);
    } else {
      dec->value()->perform(this);
    }

    if (dec->is_important()) {
      append_optional_space();
      append_string("!important");
    }
    append_delimiter();
    if (output_style() == NESTED)
      indentation -= dec->tabs();
    in_declaration = was_decl;
  }
Example #6
0
  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();

  }
Example #7
0
 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);
 }
Example #8
0
 void Inspect::operator()(Extension* extend)
 {
   append_indentation();
   append_token("@extend", extend);
   append_mandatory_space();
   extend->selector()->perform(this);
   append_delimiter();
 }
Example #9
0
 void Inspect::operator()(Return* ret)
 {
   append_indentation();
   append_token("@return", ret);
   append_mandatory_space();
   ret->value()->perform(this);
   append_delimiter();
 }
Example #10
0
 void Inspect::operator()(While* loop)
 {
   append_indentation();
   append_token("@while", loop);
   append_mandatory_space();
   loop->predicate()->perform(this);
   loop->block()->perform(this);
 }
Example #11
0
 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);
 }
Example #12
0
 void Inspect::operator()(Bubble* bubble)
 {
   append_indentation();
   append_token("::BUBBLE", bubble);
   append_scope_opener();
   bubble->node()->perform(this);
   append_scope_closer();
 }
Example #13
0
 void Inspect::operator()(Debug* debug)
 {
   append_indentation();
   append_token("@debug", debug);
   append_mandatory_space();
   debug->value()->perform(this);
   append_delimiter();
 }
Example #14
0
 void Inspect::operator()(Error* error)
 {
   append_indentation();
   append_token("@error", error);
   append_mandatory_space();
   error->message()->perform(this);
   append_delimiter();
 }
Example #15
0
 void Inspect::operator()(Warning* warning)
 {
   append_indentation();
   append_token("@warn", warning);
   append_mandatory_space();
   warning->message()->perform(this);
   append_delimiter();
 }
Example #16
0
 void Inspect::operator()(Import_Stub* import)
 {
   append_indentation();
   append_token("@import", import);
   append_mandatory_space();
   append_string(import->file_name());
   append_delimiter();
 }
Example #17
0
  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();
      }
    }
  }
Example #18
0
 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);
 }
Example #19
0
 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);
 }
Example #20
0
  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();
  }
Example #21
0
 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);
 }
Example #22
0
 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);
 }
Example #23
0
 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();
 }
Example #24
0
 void Emitter::append_scope_closer(AST_Node* node)
 {
   -- indentation;
   scheduled_linefeed = 0;
   if (output_style() == COMPRESSED)
     scheduled_delimiter = false;
   if (output_style() == EXPANDED) {
     append_optional_linefeed();
     append_indentation();
   } else {
     append_optional_space();
   }
   append_string("}");
   if (node) add_close_mapping(node);
   append_optional_linefeed();
   if (indentation != 0) return;
   if (output_style() != COMPRESSED)
     scheduled_linefeed = 2;
 }
Example #25
0
 void Output::operator()(Comment* c)
 {
   std::string txt = c->text()->to_string(opt);
   // if (indentation && txt == "/**/") return;
   bool important = c->is_important();
   if (output_style() != COMPRESSED || important) {
     if (buffer().size() == 0) {
       top_nodes.push_back(c);
     } else {
       in_comment = true;
       append_indentation();
       c->text()->perform(this);
       in_comment = false;
       if (indentation == 0) {
         append_mandatory_linefeed();
       } else {
         append_optional_linefeed();
       }
     }
   }
 }
Example #26
0
 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();
   }
 }
Example #27
0
  void Output::operator()(Ruleset* r)
  {
    Selector* s     = r->selector();
    Block*    b     = r->block();
    bool      decls = false;

    // Filter out rulesets that aren't printable (process its children though)
    if (!Util::isPrintable(r, 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 (b->has_non_hoistable()) {
      decls = true;
      if (output_style() == NESTED) indentation += r->tabs();
      if (opt.source_comments) {
        std::stringstream ss;
        append_indentation();
        ss << "/* line " << r->pstate().line + 1 << ", " << r->pstate().path << " */";
        append_string(ss.str());
        append_optional_linefeed();
      }
      s->perform(this);
      append_scope_opener(b);
      for (size_t i = 0, L = b->length(); i < L; ++i) {
        Statement* stm = (*b)[i];
        bool bPrintExpression = true;
        // Check print conditions
        if (typeid(*stm) == typeid(Declaration)) {
          Declaration* dec = static_cast<Declaration*>(stm);
          if (dec->value()->concrete_type() == Expression::STRING) {
            String_Constant* valConst = static_cast<String_Constant*>(dec->value());
            std::string val(valConst->value());
            if (auto qstr = dynamic_cast<String_Quoted*>(valConst)) {
              if (!qstr->quote_mark() && val.empty()) {
                bPrintExpression = false;
              }
            }
          }
          else if (dec->value()->concrete_type() == Expression::LIST) {
            List* list = static_cast<List*>(dec->value());
            bool all_invisible = true;
            for (size_t list_i = 0, list_L = list->length(); list_i < list_L; ++list_i) {
              Expression* item = (*list)[list_i];
              if (!item->is_invisible()) all_invisible = false;
            }
            if (all_invisible) bPrintExpression = false;
          }
        }
        // Print if OK
        if (!stm->is_hoistable() && bPrintExpression) {
          stm->perform(this);
        }
      }
      if (output_style() == NESTED) indentation -= r->tabs();
      append_scope_closer(b);
    }

    if (b->has_hoistable()) {
      if (decls) ++indentation;
      for (size_t i = 0, L = b->length(); i < L; ++i) {
        Statement* stm = (*b)[i];
        if (stm->is_hoistable()) {
          stm->perform(this);
        }
      }
      if (decls) --indentation;
    }
  }
Example #28
0
 void Inspect::operator()(Content* content)
 {
   append_indentation();
   append_token("@content", content);
   append_delimiter();
 }