Class: Widget::Base

Inherits:
Object
  • Object
show all
Defined in:
app/widgets/widget/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view_context, options = {}, &block) ⇒ Base


17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/widgets/widget/base.rb', line 17

def initialize(view_context, options = {}, &block)
  options.reverse_merge!(frame: false, remote: false)

  @view_context = view_context
  @options      = options
  @block        = block
  @view_options = {}

  @remote = options.delete(:remote)
  @frame  = options.delete(:frame)

  add_helpers_to_view_context
end

Instance Attribute Details

#view_contextObject

Returns the value of attribute view_context


3
4
5
# File 'app/widgets/widget/base.rb', line 3

def view_context
  @view_context
end

Class Method Details

.default_actionObject


5
6
7
# File 'app/widgets/widget/base.rb', line 5

def self.default_action
  :show
end

.helper(helper) ⇒ Object


9
10
11
# File 'app/widgets/widget/base.rb', line 9

def self.helper(helper)
  helpers << helper
end

.helpersObject


13
14
15
# File 'app/widgets/widget/base.rb', line 13

def self.helpers
  @helpers ||= []
end

Instance Method Details

#render(action = nil) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
# File 'app/widgets/widget/base.rb', line 31

def render(action = nil)
  action ||= self.class.default_action
  send(action)
  output = ""
  output << @view_context.(:div, class: widget_classes, id: dom_id, :'data-widget' => widget_name, :'data-widgetaction' => action, :'data-container' => container_dom_id) do
    @view_context.render(partial: '/widget/base/widget_controls', formats: [:html], locals: { dom_id: dom_id}) +
    @view_context.render(partial: partial_path(action), formats: [:html], locals: view_locals) unless @remote
  end
  output << remote_load_code(action) if @remote
  output.html_safe
end