Skip to content

Instantly share code, notes, and snippets.

@denysonique
Created March 26, 2011 14:07
Show Gist options
  • Save denysonique/888302 to your computer and use it in GitHub Desktop.
Save denysonique/888302 to your computer and use it in GitHub Desktop.
Example given by Apeiros, how to use his css parser to edit CSS.
css = Browsr::CSS.new
css.append_external_stylesheet(
"#example-id { font-size: 12px; }", # the css definitions
:author_style_sheet, # origin of the definitions (relevant for specificity)
Browsr::CSS::Media::AllMedia, # media these rules apply for
"(demofile)", # file to report for definitions & errors
1 # line to report for definitions & errors
)
ruleset = css.first # normally you'd ask for all rulesets for a given medium
rule = ruleset.rules["#example-id"]
puts rule.to_css # prints the rule
rule['font-weight'] = "bold"
puts rule.to_css # prints the rule with the update applied
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment