TinyCss

a ruby module to read and write .css stylesheets

Usage

# In your .css file H1 { color: blue } H2 { color: red; font-family: Arial } .this, .that { color: yellow }

# In your program require ‘tiny_css’

# Create a CSS stylesheet css = TinyCss.new

# Open a CSS stylesheet css = css.read(‘style.css’)

# Reading properties # (key is coverted to string, so you can access same value by symbol) header_color = css.style[‘color’] css.style.each { |property, value| p “#{ property }: #{ value }” } this_color = css.style[:color] that_color = css.style[:color]

# Changing styles and properties css.style[‘color’] = ‘#FFFFFF’ # Add a style css.style[‘color’] = ‘black’ # Change a property css.style.delete # Delete a style

# Save a CSS stylesheet css.write ‘style.css’ # Sort selectors and properties css.write ‘style.css’, false # Don’t sort

Install

git clone git://github.com/milk1000cc/tiny_css.git

or

sudo gem install tiny_css

Caution

TinyCss#style doesn’t return Hash object but TinyCss::OrderedHash, and TinyCss::OrderedHash class doesn’t inherit Hash object.

I’m Japanese, and I’m not goot at English and Ruby, so please see the source code and edit them.

Author

milk1000cc <[email protected]>