def set_declaration(self, selector, decl_name, value_as_str): # Remove an existing declaration.. for some reason if they # get modified, they become invalid (or I'm doing something wrong) self.remove_declaration(selector, decl_name) rs = self.get_ruleset(selector) value_token = tokenizer.tokenize_flat(value_as_str) # Make a new declaration, add it to the ruleset new_decl = tinycss.css21.Declaration(decl_name, value_token, None, None, None) rs.declarations.append(new_decl)
def get_ruleset(self, selector_css): """ Gets the current ruleset for selector_css, If it isn't currently defined, returns an empty one. """ for rs in self.stylesheet.rules: if rs.selector.as_css() == selector_css: return rs new_ruleset = tinycss.css21.RuleSet( tokenizer.tokenize_flat(selector_css), [], None, None) self.stylesheet.rules.append(new_ruleset) return new_ruleset