Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 731 Bytes

README.md

File metadata and controls

51 lines (35 loc) · 731 Bytes

CSSTree

Ultra-simple CSS parser.

Install

gem install csstree

Usage

Parsing CSS

tree = CSSTree.parse("body { background-color: #FFFFFF; color: #000000; }")
# => #<CSSTree:0x123456>

Finding Rules For A Selector

tree.find("body")
# => #<OpenStruct background_color="#FFFFFF" color="#000000">

Access Properties

tree.find("body").color
# => "#000000"

Access Dashed Property Names Using Underscores

tree.find("body").background_color
# => "#FFFFFF"

Manipulating the Tree

tree.find("body").color = "#A3A3A3"
# => "#A3A3A3"

Rendering Normal CSS

tree.render
# => "body { background-color: #FFFFFF; color: #A3A3A3; }