Module: ApplicationHelper

Defined in:
app/helpers/application_helper.rb

Instance Method Summary collapse

Instance Method Details

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



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/application_helper.rb', line 4

def widget(name, options={}, &block)
  id = Guid.new.to_s
  partial = File.join 'widgets', name.to_s
  attributes = {:id => id, :'data-widget' => name, :style => options.delete(:style), :class => options.delete(:effects)}
  options = {widget_id: id, widget_name: name}.merge options

  html = if block_given?
           render :layout => partial, :inline => capture(&block), :locals => options, :formats => [:html]
         else
           render :template => partial, :locals => options, :formats => [:html]
         end

  javascript = render :template => partial, :locals => options, :formats => [:js] rescue ActionView::MissingTemplate

  content =  :div, html, attributes
  if javascript
    content +=  :script, javascript, :type => 'text/javascript'
  end

  content
end