Module: MithrilHelper

Defined in:
app/helpers/mithril_helper.rb

Instance Method Summary collapse

Instance Method Details

#mithril_component(name, args = {}, options = {}, &block) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'app/helpers/mithril_helper.rb', line 2

def mithril_component(name, args = {}, options = {}, &block)
  options = {:tag => options} if options.is_a?(Symbol)

  html_options = options.reverse_merge(:data => {})
  html_options[:data].tap do |data|
    data[:mithril_class] = name
    data[:mithril_props] = args.to_json unless args.empty?
  end
  html_tag = html_options.delete(:tag) || :div

  (html_tag, '', html_options, &block)
end