class Gtk2HTML::Render

Public Class Methods

new(x, width, height) click to toggle source
Calls superclass method
# File lib/gtk2html.rb, line 16
def initialize(x, width, height)
  
  @width, @height = width.to_i, height.to_i
  super x
  
end

Public Instance Methods

b(e, attributes, raw_style)
Alias for: strong
body(e, attributes, raw_style) click to toggle source
# File lib/gtk2html.rb, line 23
def body(e, attributes, raw_style)

  style = style_filter(attributes).merge(raw_style)
  margin = style[:margin].values
  coords = [nil, nil, nil, nil]
  padding = style[:padding].values
  
  [[:draw_box, margin, coords, padding, style], render_all(e)]
end
div(e, attributes, raw_style) click to toggle source
# File lib/gtk2html.rb, line 45
def div(e, attributes, raw_style)

  style = style_filter(attributes).merge(raw_style)
  margin = style[:margin].values
  coords = [nil, nil, nil, nil]
  padding = style[:padding].values
  
  [[:draw_box, margin, coords, padding, style], render_all(e)]
end
html(e, attributes, style) click to toggle source
# File lib/gtk2html.rb, line 55
def html(e, attributes, style)   

  margin = [0, 0, 0, 0] # style[:margin].values
  coords = [0, 0, @width, @height]
  padding = [0, 0, 0, 0] # style[:padding].values

  [[:draw_box, margin, coords, padding, style], render_all(e)]
end
input(e, attributes, style) click to toggle source
# File lib/gtk2html.rb, line 64
def input(e, attributes, style)   

  margin = [0, 0, 0, 0] # style[:margin].values
  coords = [0, 0, @width, @height]
  padding = [0, 0, 0, 0] # style[:padding].values

  [[:add_inputbox, margin, coords, padding, style], render_all(e)]
end
strong(e, attributes, raw_style) click to toggle source
# File lib/gtk2html.rb, line 33
def strong(e, attributes, raw_style)

  style = style_filter(attributes).merge(raw_style)
  margin = style[:margin].values
  coords = [nil, nil, nil, nil]
  padding = style[:padding].values
  
  [[:draw_box, margin, coords, padding, style], render_all(e)]
end
Also aliased as: b
style(*args) click to toggle source
# File lib/gtk2html.rb, line 73
def style(*args)
  
end

Private Instance Methods

fetch_style(attribute) click to toggle source
Calls superclass method
# File lib/gtk2html.rb, line 79
def fetch_style(attribute)
  
  h = super attribute

  r2 = %i(margin padding).inject(h) do |r,x|

    if h.has_key? x then

      a = expand_shorthand(h[x]) 

      a.map! do |v|
        # note: there is 16px in 1em, see http://pxtoem.com/
        v =~ /em$/i ? v.to_f * 16 : v.to_f
      end

      r.merge!(x => Hash[%i(top right bottom left).zip(a)])
    else
      r
    end

  end

  r3 =  %i(height width).inject(r2) do |r,x|

    if r.has_key? x then

      v = r[x]

      # note: there is 16px in 1em, see http://pxtoem.com/
      r[x] = v =~ /em$/i ? v.to_f * 16 : v.to_f          
      r

    else
      r
    end

  end      
  
  r3
  
end
style_filter(attributes) click to toggle source
# File lib/gtk2html.rb, line 121
def style_filter(attributes)
  
  %i(bgcolor).inject({}) do |r,x|
    attributes.has_key?(x) ? r.merge(x => attributes[x]) : r          
  end
  
end