Beispiel #1
0
  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();
      }
    }
  }
Beispiel #2
0
 void Output::operator()(String_Quoted* s)
 {
   if (s->quote_mark()) {
     append_token(quote(s->value(), s->quote_mark()), s);
   } else if (!in_comment) {
     append_token(string_to_output(s->value()), s);
   } else {
     append_token(s->value(), s);
   }
 }
Beispiel #3
0
 void Output::operator()(String_Constant* s)
 {
   std::string value(s->value());
   if (s->can_compress_whitespace() && output_style() == COMPRESSED) {
     value.erase(std::remove_if(value.begin(), value.end(), ::isspace), value.end());
   }
   if (!in_comment) {
     append_token(string_to_output(value), s);
   } else {
     append_token(value, s);
   }
 }
Beispiel #4
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();
  }
Beispiel #5
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);
 }
Beispiel #6
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();
  }
Beispiel #7
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();

  }
Beispiel #8
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();

  }
Beispiel #9
0
 void Inspect::operator()(Null* n)
 {
   // use values to_string facility
   bool compressed = ctx->output_style == COMPRESSED;
   std::string res = n->to_string(compressed, (int)ctx->precision);
   // output the final token
   append_token(res, n);
 }
Beispiel #10
0
 void Inspect::operator()(Import_Stub* import)
 {
   append_indentation();
   append_token("@import", import);
   append_mandatory_space();
   append_string(import->file_name());
   append_delimiter();
 }
Beispiel #11
0
 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(")");
 }
Beispiel #12
0
void Inspect::operator()(Boolean* b)
{
    // use values to_string facility
    bool compressed = ctx->output_style == SASS_STYLE_COMPRESSED;
    std::string res(b->to_string(compressed, (int)ctx->precision));
    // output the final token
    append_token(res, b);
}
Beispiel #13
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);
 }
Beispiel #14
0
 void Inspect::operator()(Extension* extend)
 {
   append_indentation();
   append_token("@extend", extend);
   append_mandatory_space();
   extend->selector()->perform(this);
   append_delimiter();
 }
Beispiel #15
0
 void Inspect::operator()(Return* ret)
 {
   append_indentation();
   append_token("@return", ret);
   append_mandatory_space();
   ret->value()->perform(this);
   append_delimiter();
 }
Beispiel #16
0
 void Inspect::operator()(While* loop)
 {
   append_indentation();
   append_token("@while", loop);
   append_mandatory_space();
   loop->predicate()->perform(this);
   loop->block()->perform(this);
 }
Beispiel #17
0
 void Inspect::operator()(Debug* debug)
 {
   append_indentation();
   append_token("@debug", debug);
   append_mandatory_space();
   debug->value()->perform(this);
   append_delimiter();
 }
Beispiel #18
0
 void Inspect::operator()(Error* error)
 {
   append_indentation();
   append_token("@error", error);
   append_mandatory_space();
   error->message()->perform(this);
   append_delimiter();
 }
Beispiel #19
0
 void Inspect::operator()(Warning* warning)
 {
   append_indentation();
   append_token("@warn", warning);
   append_mandatory_space();
   warning->message()->perform(this);
   append_delimiter();
 }
Beispiel #20
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);
 }
Beispiel #21
0
 void Inspect::operator()(Bubble* bubble)
 {
   append_indentation();
   append_token("::BUBBLE", bubble);
   append_scope_opener();
   bubble->node()->perform(this);
   append_scope_closer();
 }
Beispiel #22
0
 void Inspect::operator()(Pseudo_Selector* s)
 {
   append_token(s->ns_name(), s);
   if (s->expression()) {
     append_string("(");
     s->expression()->perform(this);
     append_string(")");
   }
 }
Beispiel #23
0
 void Inspect::operator()(String_Quoted* s)
 {
   // get options from optional? context
   int precision = ctx ? (int)ctx->precision : 5;
   bool compressed = ctx ? ctx->output_style == COMPRESSED : false;
   // use values to_string facility
   std::string res(s->to_string(compressed, precision));
   // output the final token
   append_token(res, s);
 }
Beispiel #24
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);
 }
Beispiel #25
0
 // parameters and arguments
 void Inspect::operator()(Parameter* p)
 {
   append_token(p->name(), p);
   if (p->default_value()) {
     append_colon_separator();
     p->default_value()->perform(this);
   }
   else if (p->is_rest_parameter()) {
     append_string("...");
   }
 }
Beispiel #26
0
 void Inspect::operator()(Assignment* assn)
 {
   append_token(assn->variable(), assn);
   append_colon_separator();
   assn->value()->perform(this);
   if (assn->is_default()) {
     append_optional_space();
     append_string("!default");
   }
   append_delimiter();
 }
Beispiel #27
0
  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(")");
  }
Beispiel #28
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);
 }
Beispiel #29
0
 void Output::operator()(Number* n)
 {
   // use values to_string facility
   std::string res = n->to_string(opt);
   // check for a valid unit here
   // includes result for reporting
   if (!n->is_valid_css_unit()) {
     throw Exception::InvalidValue(*n);
   }
   // output the final token
   append_token(res, n);
 }
Beispiel #30
0
 void Inspect::operator()(Wrapped_Selector* s)
 {
   bool was = in_wrapped;
   in_wrapped = true;
   append_token(s->name(), s);
   append_string("(");
   bool was_comma_array = in_comma_array;
   in_comma_array = false;
   s->selector()->perform(this);
   in_comma_array = was_comma_array;
   append_string(")");
   in_wrapped = was;
 }