Class: Forma::Action

Inherits:
Object
  • Object
show all
Includes:
Html
Defined in:
lib/forma/action.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Html

attr, el

Constructor Details

#initialize(h = {}) ⇒ Action

Returns a new instance of Action.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/forma/action.rb', line 8

def initialize(h={})
  h = h.symbolize_keys
  @id = h[:id]
  @label = h[:label]
  @icon = h[:icon]
  @url = h[:url]
  @method = h[:method]
  @confirm = h[:confirm]
  @as = h[:as]
  @tooltip = h[:tooltip]
end

Instance Attribute Details

#urlObject (readonly)

attr_reader :label, :icon, :method, :confirm, :as



6
7
8
# File 'lib/forma/action.rb', line 6

def url
  @url
end

Instance Method Details

#to_html(model) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/forma/action.rb', line 20

def to_html(model)
  children = [ (el('img', attrs: { src: @icon }) if @icon.present?), el('span', text: eval_label(model)) ]
  button = (@as.to_s == 'button')
  el(
    'a',
    attrs: {
      id: @id,
      class: ['ff-action', ('btn' if button)],
      href: eval_url(model), 'data-method' => @method, 'data-confirm' => @confirm,
      'data-original-title' => @tooltip
    },
    children: children
  )
end