CSS-Sass

 view release on metacpan or  search on metacpan

libsass/expand.cpp  view on Meta::CPAN

    in_at_root = false;

    if (in_keyframes) {
      To_String to_string;
      Keyframe_Rule* k = new (ctx.mem) Keyframe_Rule(r->pstate(), r->block()->perform(this)->block());
      if (r->selector()) k->selector(r->selector()->perform(contextualize_eval->with(0, env, backtrace)));
      in_at_root = old_in_at_root;
      old_in_at_root = false;
      return k;
    }

    Contextualize_Eval* contextual = contextualize_eval->with(selector_stack.back(), env, backtrace);
    if (old_in_at_root && !r->selector()->has_reference())
      contextual = contextualize_eval->with(at_root_selector_stack.back(), env, backtrace);

    Selector* sel_ctx = r->selector()->perform(contextual);
    if (sel_ctx == 0) throw "Cannot expand null selector";

    Emitter emitter(&ctx);
    Inspect isp(emitter);
    sel_ctx->perform(&isp);
    string str = isp.get_buffer();
    str += ";";

    Parser p(ctx, r->pstate());
    p.block_stack.push_back(r->selector() ? r->selector()->last_block() : 0);
    p.last_media_block = r->selector() ? r->selector()->media_block() : 0;
    p.source   = str.c_str();
    p.position = str.c_str();
    p.end      = str.c_str() + strlen(str.c_str());
    Selector_List* sel_lst = p.parse_selector_group();
    // sel_lst->pstate(isp.remap(sel_lst->pstate()));

    for(size_t i = 0; i < sel_lst->length(); i++) {

      Complex_Selector* pIter = (*sel_lst)[i];
      while (pIter) {
        Compound_Selector* pHead = pIter->head();
        // pIter->pstate(isp.remap(pIter->pstate()));
        if (pHead) {
          // pHead->pstate(isp.remap(pHead->pstate()));
          // (*pHead)[0]->pstate(isp.remap((*pHead)[0]->pstate()));
        }
        pIter = pIter->tail();
      }
    }
    sel_ctx = sel_lst;

    selector_stack.push_back(sel_ctx);
    Block* blk = r->block()->perform(this)->block();
    Ruleset* rr = new (ctx.mem) Ruleset(r->pstate(),
                                        sel_ctx,
                                        blk);
    rr->tabs(r->tabs());
    selector_stack.pop_back();
    in_at_root = old_in_at_root;
    old_in_at_root = false;
    return rr;
  }

  Statement* Expand::operator()(Propset* p)
  {
    property_stack.push_back(p->property_fragment());
    Block* expanded_block = p->block()->perform(this)->block();

    Block* current_block = block_stack.back();
    for (size_t i = 0, L = expanded_block->length(); i < L; ++i) {
      Statement* stm = (*expanded_block)[i];
      if (typeid(*stm) == typeid(Declaration)) {
        Declaration* dec = static_cast<Declaration*>(stm);
        String_Schema* combined_prop = new (ctx.mem) String_Schema(p->pstate());
        if (!property_stack.empty()) {
          *combined_prop << property_stack.back()
                         << new (ctx.mem) String_Constant(p->pstate(), "-")
                         << dec->property(); // TODO: eval the prop into a string constant
        }
        else {
          *combined_prop << dec->property();
        }
        dec->property(combined_prop);
        *current_block << dec;
      }
      else if (typeid(*stm) == typeid(Comment)) {
        // drop comments in propsets
      }
      else {
        error("contents of namespaced properties must result in style declarations only", stm->pstate(), backtrace);
      }
    }

    property_stack.pop_back();

    return 0;
  }

  Statement* Expand::operator()(Feature_Block* f)
  {
    Expression* feature_queries = f->feature_queries()->perform(eval->with(env, backtrace));
    Feature_Block* ff = new (ctx.mem) Feature_Block(f->pstate(),
                                                    static_cast<Feature_Query*>(feature_queries),
                                                    f->block()->perform(this)->block());
    ff->selector(selector_stack.back());
    return ff;
  }

  Statement* Expand::operator()(Media_Block* m)
  {
    To_String to_string(&ctx);
    Expression* mq = m->media_queries()->perform(eval->with(env, backtrace));
    mq = Parser::from_c_str(mq->perform(&to_string).c_str(), ctx, mq->pstate()).parse_media_queries();
    Media_Block* mm = new (ctx.mem) Media_Block(m->pstate(),
                                                static_cast<List*>(mq),
                                                m->block()->perform(this)->block(),
                                                selector_stack.back());
    mm->tabs(m->tabs());
    return mm;
  }

  Statement* Expand::operator()(At_Root_Block* a)
  {
    in_at_root = true;
    at_root_selector_stack.push_back(0);
    Block* ab = a->block();
    Expression* ae = a->expression();
    if (ae) ae = ae->perform(eval->with(env, backtrace));
    else ae = new (ctx.mem) At_Root_Expression(a->pstate());
    Block* bb = ab ? ab->perform(this)->block() : 0;
    At_Root_Block* aa = new (ctx.mem) At_Root_Block(a->pstate(),
                                                    bb,
                                                    static_cast<At_Root_Expression*>(ae));
    at_root_selector_stack.pop_back();
    in_at_root = false;
    return aa;
  }

  Statement* Expand::operator()(At_Rule* a)
  {
    bool old_in_keyframes = in_keyframes;
    in_keyframes = a->is_keyframes();
    Block* ab = a->block();
    Selector* as = a->selector();
    Expression* av = a->value();
    if (as) as = as->perform(contextualize_eval->with(0, env, backtrace));
    else if (av) av = av->perform(eval->with(env, backtrace));



( run in 0.694 second using v1.01-cache-2.11-cpan-71847e10f99 )