class UiHelpers::Element

Attributes

html_options[R]

Public Class Methods

new(*args) click to toggle source
# 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

Public Instance Methods

capture(content = nil) { |buffer| ... } click to toggle source
# 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
classes() click to toggle source
# File lib/ui_helpers/elements/element.rb, line 49
def classes
  @html_options[:class]
end
classes=(*values) click to toggle source
# File lib/ui_helpers/elements/element.rb, line 45
def classes=(*values)
  classes.commit(*values)
end
style=(*value) click to toggle source
# File lib/ui_helpers/elements/element.rb, line 41
def style=(*value)
  @html_options[:style] << value
end
tag(tag_name, content = nil, &block) click to toggle source
# File lib/ui_helpers/elements/element.rb, line 59
def tag(tag_name, content = nil, &block)
  @template.content_tag tag_name, capture(content, &block), @html_options
end
with_html_options(hash = {}) click to toggle source
# 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