Beispiel #1
0
bool Selector::match(const Selector &selector) const {
  const_iterator it;
  
  for (it = selector.begin();
       it != selector.end();
       it++) {
    if (match(*it))
      return true;
  }
  return false;
}
Beispiel #2
0
bool Mixin::parse(const Selector &selector) {
  
  TokenList::const_iterator i = selector.begin();
  
  for (; i != selector.end() &&
         (*i).type != Token::PAREN_OPEN; i++) {
    this->name.push_back(*i);
  }

  this->name.rtrim();

  parseArguments(i, selector);

  return true;
}
Beispiel #3
0
void MediaQueryRuleset::process(Stylesheet &s, Selector* prefix, ProcessingContext &context) {
  MediaQuery* query;
  Ruleset* target;
  Selector selector;

#ifdef WITH_LIBGLOG
  VLOG(2) << "Processing Less Ruleset: " <<
    getSelector().toString();
#endif
  
  query = s.createMediaQuery();
  selector = getSelector();
  context.interpolate(selector);

  if (query->getSelector().size() > 0) {
    selector.pop_front();

    query->getSelector().push_back(Token(" ", Token::WHITESPACE));
    query->getSelector().push_back(Token("and", Token::IDENTIFIER));
    query->getSelector().insert(query->getSelector().end(),
                                 selector.begin(),
                                 selector.end());
  } else
    query->setSelector(selector);

  if (prefix != NULL) {
    target = query->createRuleset();
    target->setSelector(*prefix);

#ifdef WITH_LIBGLOG
    VLOG(3) << "Interpolating selector " <<
    target->getSelector().toString();
#endif
    context.interpolate(target->getSelector());
  
    insert(NULL, *target, context);
  } else
    insert(NULL, *query, context);
}
Beispiel #4
0
void Selector::addPrefix(const Selector &prefix) {
  iterator it;
  const_iterator it2;
  TokenList tl;
  TokenList *inserted;

  const TokenList* tmp;
  TokenList::const_iterator tmp_it;
  
  
  bool containsAmp;

  for (it = begin(); it != end(); ) {
    tmp = &(*it);
    containsAmp = tmp->contains(Token::OTHER, "&");
    
    for (it2 = prefix.begin();
         it2 != prefix.end();
         it2++) {
      inserted = &(*insert(it, tl));
      
      if (containsAmp) {
        for (tmp_it = tmp->begin(); tmp_it != tmp->end(); tmp_it++) {
          if (*tmp_it == "&")
            inserted->insert(inserted->end(), (*it2).begin(), (*it2).end());
          else
            inserted->push_back(*tmp_it);
        }
      } else {
        inserted->insert(inserted->end(), (*it2).begin(), (*it2).end());
        inserted->push_back(Token::BUILTIN_SPACE);
        inserted->insert(inserted->end(), tmp->begin(), tmp->end());
      }
    }
    it = erase(it);
  }

}
Beispiel #5
0
void Selector::appendSelector(const Selector &selector) {
  insert(end(), selector.begin(), selector.end());
}
Beispiel #6
0
void Mixin::parseArguments(TokenList::const_iterator i, const Selector &selector) {
  TokenList::const_iterator j;
  string delimiter = ",";

  TokenList argument;
  size_t nestedParenthesis = 0;
  string argName;

  if (i != selector.end() &&
      (*i).type == Token::PAREN_OPEN) {
    i++;
  }
    
  // if a ';' token occurs then that is the delimiter instead of the ','.
  for(j = i; j != selector.end(); j++) {
    if (*j == ";") {
      delimiter = ";";
      break;
    }
  }

  while (i != selector.end() && (*i).type != Token::PAREN_CLOSED) {
    while (i != selector.end() &&
           (*i).type == Token::WHITESPACE) {
      i++;
    }

    if ((*i).type == Token::ATKEYWORD) {
      argName = (*i);
      i++;
      if (i != selector.end() &&
          (*i).type == Token::COLON) {
        i++;
      } else {
        argName = "";
        i--;
      }
    }

    while (i != selector.end() &&
           (nestedParenthesis > 0 ||
            ((*i) != delimiter &&
             (*i).type != Token::PAREN_CLOSED))) {
      
      if ((*i).type == Token::PAREN_OPEN)
        nestedParenthesis++;
      
      if ((*i).type == Token::PAREN_CLOSED)
        nestedParenthesis--;
      
      argument.push_back(*i);
      
      i++;
    }

    if (*i == delimiter)
      i++;

    if (argName == "")
      this->arguments.push_back(argument);
    else {
      this->namedArguments.insert(pair<string,
                                  TokenList>(argName,argument));
      argName = "";
    }
    argument.clear();
  }
}