Module: GenericFormFor::Actions::Base

Extended by:
ActiveSupport::Autoload
Includes:
I18n
Included in:
ButtonAction, InputAction
Defined in:
lib/generic_form_for/actions/base.rb,
lib/generic_form_for/actions/base/icon.rb

Defined Under Namespace

Modules: Icon

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from I18n

#translate, #translate_action, #translate_hint, #translate_label, #translate_legend, #translate_placeholder

Instance Attribute Details

#builderObject

Returns the value of attribute builder.



15
16
17
# File 'lib/generic_form_for/actions/base.rb', line 15

def builder
  @builder
end

#methodObject

Returns the value of attribute method.



15
16
17
# File 'lib/generic_form_for/actions/base.rb', line 15

def method
  @method
end

#objectObject

Returns the value of attribute object.



15
16
17
# File 'lib/generic_form_for/actions/base.rb', line 15

def object
  @object
end

#object_nameObject

Returns the value of attribute object_name.



15
16
17
# File 'lib/generic_form_for/actions/base.rb', line 15

def object_name
  @object_name
end

#optionsObject

Returns the value of attribute options.



15
16
17
# File 'lib/generic_form_for/actions/base.rb', line 15

def options
  @options
end

#templateObject

Returns the value of attribute template.



15
16
17
# File 'lib/generic_form_for/actions/base.rb', line 15

def template
  @template
end

Instance Method Details

#action_html_optionsObject



37
38
39
# File 'lib/generic_form_for/actions/base.rb', line 37

def action_html_options
  default_action_options.merge(options[:html] || {}).merge(action_options)
end

#action_optionsObject



45
46
47
# File 'lib/generic_form_for/actions/base.rb', line 45

def action_options
  options.except(*form_builder_options)
end

#button_textObject



53
54
55
# File 'lib/generic_form_for/actions/base.rb', line 53

def button_text
  translate_action(options[:label] || method)
end

#default_action_optionsObject



41
42
43
# File 'lib/generic_form_for/actions/base.rb', line 41

def default_action_options
  {:name => method, :type => method }
end

#form_builder_optionsObject



49
50
51
# File 'lib/generic_form_for/actions/base.rb', line 49

def form_builder_options
  [:as, :url, :icon, :icon_html]
end

#initialize(builder, template, object, object_name, method, options) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/generic_form_for/actions/base.rb', line 17

def initialize(builder, template, object, object_name, method, options)
  @output_buffer = ""
  @builder = builder
  @template = template
  @object = object
  @object_name = object_name
  @method = method
  @options = options.dup
end

#merge_action_html_options(runtime_options, config_options) ⇒ Object



32
33
34
35
# File 'lib/generic_form_for/actions/base.rb', line 32

def merge_action_html_options(runtime_options,config_options)
  runtime_options[:class] = [*runtime_options[:class], *config_options[:class]].compact.join(' ').strip
  config_options.merge(runtime_options)
end

#to_htmlObject



27
28
29
30
# File 'lib/generic_form_for/actions/base.rb', line 27

def to_html
  instance_exec &builder.action_wrapper_proc
  ""
end

#wrap_in(*args, &block) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/generic_form_for/actions/base.rb', line 6

def wrap_in(*args, &block)
  wrap_options = args.last.is_a?(Hash) ? args.pop : {}
  wrap_options[:class] = [*"#{options[:as]}-action", *wrap_options[:class], *(options[:wrapper_html]||{})[:class]].join(' ').strip
  wrap_options.merge!((options[:wrapper_html] || {}).except(:class))
  template.concat( template.(wrap_options.delete(:tag) || :div, wrap_options) do
    template.capture(&block) if block_given?
  end.html_safe)
end