class Osheet::Style
Constants
- BORDERS
- BORDER_POSITIONS
this class is essentially a set of collectors for style settings each setting collects any arguments passed to it and it is up to the writer to determine how to use the settings
- SETTINGS
Attributes
build[R]
selectors[R]
Public Class Methods
new(*selectors, &build)
click to toggle source
# File lib/osheet/style.rb, line 14 def initialize(*selectors, &build) @selectors = verify(selectors) @build = build || Proc.new {} SETTINGS.each { |s| instance_variable_set("@#{s}", []) } end
Public Instance Methods
align(*args)
click to toggle source
# File lib/osheet/style.rb, line 20 def align(*args); @align += args; end
bg(*args)
click to toggle source
# File lib/osheet/style.rb, line 22 def bg(*args); @bg += args; end
border(*args)
click to toggle source
# File lib/osheet/style.rb, line 29 def border(*args) BORDERS.each { |border| send(border, *args) } end
border_bottom(*args)
click to toggle source
# File lib/osheet/style.rb, line 26 def border_bottom(*args); @border_bottom += args; end
border_left(*args)
click to toggle source
# File lib/osheet/style.rb, line 27 def border_left(*args); @border_left += args; end
border_right(*args)
click to toggle source
# File lib/osheet/style.rb, line 25 def border_right(*args); @border_right += args; end
border_top(*args)
click to toggle source
# File lib/osheet/style.rb, line 24 def border_top(*args); @border_top += args; end
font(*args)
click to toggle source
# File lib/osheet/style.rb, line 21 def font(*args); @font += args; end
match?(style_class)
click to toggle source
# File lib/osheet/style.rb, line 33 def match?(style_class) selectors.inject(false) do |match, s| match ||= s.split('.').inject(true) do |result, part| result && (part.empty? || style_class.include?(part)) end end end
Private Instance Methods
invalid?(selector)
click to toggle source
# File lib/osheet/style.rb, line 51 def invalid?(selector) selector =~ /\s+/ || selector =~ /^[^.]/ || selector =~ />+/ end
verify(selectors)
click to toggle source
# File lib/osheet/style.rb, line 43 def verify(selectors) selectors.each do |selector| if !selector.kind_of?(::String) || invalid?(selector) raise ArgumentError, "invalid selector: '#{selector}', selectors must be strings that begin with '.' and con't have spaces or '>'." end end end