Skip to content

Instantly share code, notes, and snippets.

@v2e4lisp
Last active April 28, 2020 11:12
Show Gist options
  • Save v2e4lisp/9202597 to your computer and use it in GitHub Desktop.
Save v2e4lisp/9202597 to your computer and use it in GitHub Desktop.
ruby dsl for css
css {
[nav, a, id(:user)].define {
}
group nav, a, id(:user) {
}
nav a id(:user) {
}
}
class Selector
attr_accessor :name, :id, :klass, :parent
def to_s
tag = [parent, name].join " "
tag << ".#{klass}" if klass
tag << "##{id}" if id
end
end
class Rule
def selectors
@selectors ||= []
end
def items
@items ||= []
end
def to_s
"#{selectors.join(',')}{#{items.join}}"
end
end
class Item
attr_accessor :property
def values
@values ||= []
end
alias_method :value, :values
def to_s
"#{property.gsub('_', '-')}:#{values.join(',')};"
end
end
class CSS
end
def myfont
font 18.px
end
item = Item.new
item.property = "margin"
item.value << "12px"
item.value << "30px"
puts item.to_s
def x *args
puts ["x"] + args
end
def y *args
puts ["y"] + args
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment