Class: UiHelpers::Element

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Callbacks
Defined in:
lib/ui_helpers/elements/element.rb

Direct Known Subclasses

Button::Text, DialogContent, DialogOver, Icon, Overlay, Widget

Defined Under Namespace

Classes: Classes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Element

Returns a new instance of Element.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ui_helpers/elements/element.rb', line 25

def initialize(*args)
  params = args.extract_options!
  @template = args.first||ActionView::Base.new(Rails.configuration.paths["app/views"].first) ## fake      
  @html_options = Hash.new do |h,k|
    h[k] = case k
    when :class, "class" then Classes.new
    else []
    end
  end
  run_callbacks(:init) do      
    params.each do |key, value|
      send("#{key}=", value)
    end
  end
end

Instance Attribute Details

#html_optionsObject (readonly)

Returns the value of attribute html_options.



23
24
25
# File 'lib/ui_helpers/elements/element.rb', line 23

def html_options
  @html_options
end

Instance Method Details

#capture(content = nil, &block) ⇒ Object



53
54
55
56
57
# File 'lib/ui_helpers/elements/element.rb', line 53

def capture(content = nil, &block)
  ActiveSupport::SafeBuffer.new(content||"").tap do |buffer|
    yield buffer if block_given?
  end
end

#classesObject



49
50
51
# File 'lib/ui_helpers/elements/element.rb', line 49

def classes
  @html_options[:class]
end

#classes=(*values) ⇒ Object



45
46
47
# File 'lib/ui_helpers/elements/element.rb', line 45

def classes=(*values)
  classes.commit(*values)
end

#style=(*value) ⇒ Object



41
42
43
# File 'lib/ui_helpers/elements/element.rb', line 41

def style=(*value)
  @html_options[:style] << value
end

#tag(tag_name, content = nil, &block) ⇒ Object



59
60
61
# File 'lib/ui_helpers/elements/element.rb', line 59

def tag(tag_name, content = nil, &block)
  @template. tag_name, capture(content, &block), @html_options
end

#with_html_options(hash = {}) ⇒ Object



63
64
65
66
67
# File 'lib/ui_helpers/elements/element.rb', line 63

def with_html_options(hash = {})
  self.tap do |element|
    element.html_options.merge!(hash)
  end
end