Ejemplo n.º 1
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;
  }
Ejemplo n.º 2
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();
 }
Ejemplo n.º 3
0
 void Emitter::append_scope_opener(AST_Node* node)
 {
   scheduled_linefeed = 0;
   append_optional_space();
   flush_schedules();
   if (node) add_open_mapping(node);
   append_string("{");
   append_optional_linefeed();
   // append_optional_space();
   ++ indentation;
 }
Ejemplo n.º 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();
  }
Ejemplo n.º 5
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();
      }
    }
  }
Ejemplo n.º 6
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();
 }
Ejemplo n.º 7
0
  void Inspect::operator()(List* list)
  {
    std::string sep(list->separator() == SASS_SPACE ? " " : ",");
    if (output_style() != COMPRESSED && sep == ",") sep += " ";
    else if (in_media_block && sep != " ") sep += " "; // verified
    if (list->empty()) return;
    bool items_output = false;

    bool was_space_array = in_space_array;
    bool was_comma_array = in_comma_array;
    if (!in_declaration && (
        (list->separator() == SASS_SPACE && in_space_array) ||
        (list->separator() == SASS_COMMA && in_comma_array)
    )) {
      append_string("(");
    }

    if (list->separator() == SASS_SPACE) in_space_array = true;
    else if (list->separator() == SASS_COMMA) in_comma_array = true;

    for (size_t i = 0, L = list->size(); i < L; ++i) {
      Expression* list_item = (*list)[i];
      if (list_item->is_invisible()) {
        continue;
      }
      if (items_output) {
        append_string(sep);
      }
      if (items_output && sep != " ")
        append_optional_space();
      list_item->perform(this);
      items_output = true;
    }

    in_comma_array = was_comma_array;
    in_space_array = was_space_array;
    if (!in_declaration && (
        (list->separator() == SASS_SPACE && in_space_array) ||
        (list->separator() == SASS_COMMA && in_comma_array)
    )) {
      append_string(")");
    }

  }
Ejemplo n.º 8
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;
 }
Ejemplo n.º 9
0
 void Emitter::append_colon_separator()
 {
   scheduled_space = 0;
   append_string(":");
   append_optional_space();
 }
Ejemplo n.º 10
0
 void Emitter::append_comma_separator()
 {
   // scheduled_space = 0;
   append_string(",");
   append_optional_space();
 }