Created
July 4, 2009 16:07
-
-
Save porras/140614 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
def yacss(data) | |
YAML.load(data).map do |item| | |
item.map do |selector, properties| | |
"#{selector} {\n" + | |
properties.map do |property, value| | |
" #{property}: #{value};\n" | |
end.join + | |
"}\n" | |
end.join | |
end.join | |
end | |
YAML_TEXT = <<-YAML_TEXT | |
- body: &body # setting a label | |
height: 20px | |
width: &width 30px # setting another label | |
- .wadus span: | |
width: *width # using a label as a variable | |
- p: | |
<<: *body # using a label as a mixin | |
color: "#fff" # need to quote this as # opens a comment in YAML | |
# full reference at YAML.org =;-) | |
YAML_TEXT | |
puts yacss(YAML_TEXT) | |
# Output: | |
# | |
# body { | |
# height: 20px; | |
# width: 30px; | |
# } | |
# .wadus span { | |
# width: 30px; | |
# } | |
# p { | |
# color: #fff; | |
# height: 20px; | |
# width: 30px; | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment