Module: Formtastic::Actions::Base

Includes:
LocalizedString
Included in:
ButtonAction, InputAction, LinkAction
Defined in:
lib/formtastic/actions/base.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from LocalizedString

#model_name

Instance Attribute Details

- (Object) builder

Returns the value of attribute builder



6
7
8
# File 'lib/formtastic/actions/base.rb', line 6

def builder
  @builder
end

- (Object) method

Returns the value of attribute method



6
7
8
# File 'lib/formtastic/actions/base.rb', line 6

def method
  @method
end

- (Object) object

Returns the value of attribute object



6
7
8
# File 'lib/formtastic/actions/base.rb', line 6

def object
  @object
end

- (Object) object_name

Returns the value of attribute object_name



6
7
8
# File 'lib/formtastic/actions/base.rb', line 6

def object_name
  @object_name
end

- (Object) options

Returns the value of attribute options



6
7
8
# File 'lib/formtastic/actions/base.rb', line 6

def options
  @options
end

- (Object) template

Returns the value of attribute template



6
7
8
# File 'lib/formtastic/actions/base.rb', line 6

def template
  @template
end

Instance Method Details

- (Object) accesskey



102
103
104
105
106
107
108
# File 'lib/formtastic/actions/base.rb', line 102

def accesskey
  # TODO could be cleaner and separated, remember that nil is an allowed value for all of these
  return options[:accesskey] if options.key?(:accesskey)
  return options[:button_html][:accesskey] if options.key?(:button_html) && options[:button_html].key?(:accesskey)
  # TODO might be different for cancel, etc?
  return builder.default_commit_button_accesskey
end

- (Object) button_html



86
87
88
# File 'lib/formtastic/actions/base.rb', line 86

def button_html
  default_button_html.merge(button_html_from_options || {}).merge(extra_button_html_options)
end

- (Object) button_html_from_options



90
91
92
# File 'lib/formtastic/actions/base.rb', line 90

def button_html_from_options
  options[:button_html]
end

- (Object) default_button_html



98
99
100
# File 'lib/formtastic/actions/base.rb', line 98

def default_button_html
  { :accesskey => accesskey }
end

- (Object) default_wrapper_classes



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

def default_wrapper_classes
  ["action", "#{options[:as]}_action"]
end

- (Object) default_wrapper_html_options



38
39
40
41
42
43
# File 'lib/formtastic/actions/base.rb', line 38

def default_wrapper_html_options
  {
    :class => wrapper_class,
    :id => wrapper_id
  }
end

- (Object) default_wrapper_id



71
72
73
# File 'lib/formtastic/actions/base.rb', line 71

def default_wrapper_id
  "#{object_name}_#{method}_action"
end

- (Object) extra_button_html_options



94
95
96
# File 'lib/formtastic/actions/base.rb', line 94

def extra_button_html_options
  {}
end

- (Object) initialize(builder, template, object, object_name, method, options)



8
9
10
11
12
13
14
15
16
17
# File 'lib/formtastic/actions/base.rb', line 8

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

- (Object) supported_methods

Raises:

  • (NotImplementedError)


75
76
77
# File 'lib/formtastic/actions/base.rb', line 75

def supported_methods
  raise NotImplementedError
end

- (Object) text



79
80
81
82
83
84
# File 'lib/formtastic/actions/base.rb', line 79

def text
  text = options[:label]
  text = (localized_string(i18n_key, text, :action, :model => sanitized_object_name) ||
         Formtastic::I18n.t(i18n_key, :model => sanitized_object_name)) unless text.is_a?(::String)
  text
end

- (Object) to_html

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/formtastic/actions/base.rb', line 19

def to_html
  raise NotImplementedError
end

- (Object) wrapper(&block)



23
24
25
26
27
28
# File 'lib/formtastic/actions/base.rb', line 23

def wrapper(&block)
  template.(:li, 
    template.capture(&block), 
    wrapper_html_options
  )
end

- (Object) wrapper_class



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

def wrapper_class
  (default_wrapper_classes << wrapper_classes_from_options).join(" ")
end

- (Object) wrapper_classes_from_options



53
54
55
56
57
# File 'lib/formtastic/actions/base.rb', line 53

def wrapper_classes_from_options
  classes = wrapper_html_options_from_options[:class] || []
  classes = classes.split(" ") if classes.is_a? String
  classes
end

- (Object) wrapper_html_options



30
31
32
# File 'lib/formtastic/actions/base.rb', line 30

def wrapper_html_options
  wrapper_html_options_from_options.merge(default_wrapper_html_options)
end

- (Object) wrapper_html_options_from_options



34
35
36
# File 'lib/formtastic/actions/base.rb', line 34

def wrapper_html_options_from_options
  options[:wrapper_html] || {}
end

- (Object) wrapper_id



63
64
65
# File 'lib/formtastic/actions/base.rb', line 63

def wrapper_id
  wrapper_id_from_options || default_wrapper_id
end

- (Object) wrapper_id_from_options



67
68
69
# File 'lib/formtastic/actions/base.rb', line 67

def wrapper_id_from_options
  wrapper_html_options_from_options[:id]
end