class Hermes::Css
Example¶ ↑
require "hermes/css" require "hermes/color" class MyCss < Css COL1 = "904f02".to_rgb COL2 = COL1.edit_hsv { |h,s,v| [h+15,s,v] } ATTR_COL1 = { color: COL1 } ATTR_COL2 = { color: COL2 } ATTR_DECON = { text_decoration: "none" } ATTR_DECOU = { text_decoration: "underline" } def build a ":link", ATTR_COL1, ATTR_DECON a ":visited", ATTR_COL2, ATTR_DECON a ":active", ATTR_COL1, ATTR_DECON a ":focus", ATTR_COL1, ATTR_DECOU space body "#dummy" do properties :background_color => "f7f7f7".to_rgb div ".child", :background_color => "e7e7e7".to_rgb @b = selector td do @bt = selector end end selectors @b, @bt, :fon_size => :large end end Hermes::Css.document
Constants
- INDENT
Attributes
main[RW]
Public Class Methods
new()
click to toggle source
# File lib/hermes/css.rb, line 110 def initialize @selector = Selector.new end
Public Instance Methods
comment(str)
click to toggle source
# File lib/hermes/css.rb, line 126 def comment str @out << "/*" str = mask_comment str ml = str =~ %r(#$/) if ml then @out << $/ str.each_line { |l| l.chomp! @out << " * " << l << $/ } else @out << " " << str end @out << " */" ml and @out << $/ end
document(out = nil)
click to toggle source
# File lib/hermes/css.rb, line 51 def document out = nil open_out out do |o| @main.new.document o end end
inherited(cls)
click to toggle source
# File lib/hermes/css.rb, line 48 def inherited cls Css.main = cls end
method_missing(sym, *args, &block)
click to toggle source
Calls superclass method
# File lib/hermes/css.rb, line 166 def method_missing sym, *args, &block if Html::TAGS[ sym] then if args.any? and not Hash === args.first then sub = args.shift end if args.any? and not Hash === args.first then desc, sub = sub, args.shift elsif sub !~ /[a-z]/i or Symbol === sub then desc, sub = sub, nil end tag desc, sym, sub, *args, &block else super end end
path()
click to toggle source
# File lib/hermes/css.rb, line 121 def path @out.path rescue NoMethodError end
properties(*args)
click to toggle source
# File lib/hermes/css.rb, line 182 def properties *args write @selector.to_s, *args end
selector()
click to toggle source
# File lib/hermes/css.rb, line 186 def selector @selector.dup end
selectors(*args)
click to toggle source
# File lib/hermes/css.rb, line 190 def selectors *args s = [] while Selector === args.first do s.push args.shift end t = s.join ", " write t, *args end
space()
click to toggle source
# File lib/hermes/css.rb, line 143 def space @out << $/ end
tag(*args) { || ... }
click to toggle source
# File lib/hermes/css.rb, line 147 def tag *args p = [] while Hash === args.last do p.unshift args.pop end @selector.tag *args do if p.empty? then yield else properties *p end end end
Private Instance Methods
mask_comment(str)
click to toggle source
# File lib/hermes/css.rb, line 201 def mask_comment str str.gsub /\*\//, "* /" end
open_out(out) { |out| ... }
click to toggle source
# File lib/hermes/css.rb, line 57 def open_out out if out or $*.empty? then yield out else File.open $*.shift, "w" do |f| yield f end end end
write(sel, *args)
click to toggle source
# File lib/hermes/css.rb, line 207 def write sel, *args p = {} args.each { |a| p.update a } @out << sel << " {" nl, ind = if p.size > 1 then @out << $/ [ $/, INDENT] else [ " ", " "] end p.each { |k,v| if Symbol === k then k = k.new_string ; k.gsub! /_/, "-" end if Array === v then v = v.join " " end @out << ind << k << ": " << v << ";" << nl } @out << "}" << $/ end