Пример #1
0
void UnprocessedStatement::process(Ruleset &r) {
  Extension extension;
  Mixin mixin;
  Declaration* declaration;

#ifdef WITH_LIBGLOG
  VLOG(2) << "Statement: " << getTokens()->toString();
#endif
  
  // process extends statement
  if (getExtension(extension.getTarget())) {
    extension.setExtension(r.getSelector());
    getLessRuleset()->getContext()->addExtension(extension);
    return;
  }
  
  mixin.setStylesheet(getLessRuleset()->getLessStylesheet());
  
  // process mixin
  if (mixin.parse(*getTokens()) &&
      mixin.insert(*r.getStylesheet(), *getLessRuleset()->getContext(),
                   &r, getLessRuleset())) {

  } else {
    declaration = r.createDeclaration();
    
    if (processDeclaration(declaration)) {
    
#ifdef WITH_LIBGLOG
      VLOG(2) << "Declaration: " <<
        declaration->getProperty() << ": " << declaration->getValue().toString();
#endif
    
      getLessRuleset()->getContext()->processValue(declaration->getValue());

#ifdef WITH_LIBGLOG
      VLOG(2) << "Processed declaration: " <<
        declaration->getProperty() << ": " << declaration->getValue().toString();
#endif
    
    } else {
      r.deleteDeclaration(*declaration);
      throw new ParseException(getTokens()->toString(),
                               "variable, mixin or declaration.",
                               getTokens()->front().line,
                               getTokens()->front().column,
                               getTokens()->front().source);
    }
  }

#ifdef WITH_LIBGLOG
  VLOG(3) << "Statement done";
#endif
}
Пример #2
0
void LessDeclaration::process(Ruleset &r, void* context) const {
  Declaration *d = r.createDeclaration();
  d->setProperty(property);
  d->setValue(value);

  ((ProcessingContext*)context)->interpolate(d->getProperty());
  ((ProcessingContext*)context)->processValue(d->getValue());

  // If the `important` flag is set, append '!important'
  if(((ProcessingContext*)context)->isImportant()) {
    
    if (d->getValue().size() < 3 ||
        d->getValue().back() == "important") {
      d->getValue().push_back(Token::BUILTIN_SPACE);
      d->getValue().push_back(Token::BUILTIN_IMPORTANT);
    }
    
  }
}
Пример #3
0
void ParameterRuleset::addDeclarations(ValueProcessor* valueProcessor,
                                       Ruleset* ruleset) {
  vector<Declaration*>* declarations;
  vector<Declaration*>::iterator di;
  Declaration* declaration;

  declarations = getDeclarations();  
  for (di = declarations->begin(); di < declarations->end(); di++) {
    declaration = (*di)->clone();
    valueProcessor->processValue(declaration->getValue());
    ruleset->addDeclaration(declaration);
  }
}
Пример #4
0
// block in value
TEST(CssParserTest, BlockValue) {
  istringstream in("selector {key: {value}}");
    
  CssTokenizer t(&in);
  CssParser p(&t);
  Stylesheet s;
  Declaration* d;

  p.parseStylesheet(&s);
  ASSERT_EQ(1, s.getRulesets()->size());
  ASSERT_EQ(1, s.getRulesets()->at(0)->getDeclarations()->size());

  d = s.getRulesets()->at(0)->getDeclarations()->at(0);
  ASSERT_STREQ("key", d->getProperty()->c_str());
  ASSERT_STREQ("{value}", d->getValue()->toString()->c_str());
}
Пример #5
0
// Rulesets
TEST(CssParserTest, Ruleset) {
  istringstream in("selector {key: value;}");
    
  CssTokenizer t(&in);
  CssParser p(&t);
  Stylesheet s;
  Ruleset* set;
  Declaration* d;

  p.parseStylesheet(&s);
  ASSERT_EQ(1, s.getRulesets()->size());
  set = s.getRulesets()->at(0);
  ASSERT_STREQ("selector", set->getSelector()->toString()->c_str());
  ASSERT_EQ(1, set->getDeclarations()->size());

  d = set->getDeclarations()->at(0);
  ASSERT_STREQ("key", d->getProperty()->c_str());
  ASSERT_STREQ("value", d->getValue()->toString()->c_str());
}