Skip to content

Instantly share code, notes, and snippets.

@porras
Created July 4, 2009 16:07
Show Gist options
  • Save porras/140614 to your computer and use it in GitHub Desktop.
Save porras/140614 to your computer and use it in GitHub Desktop.
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