Class: Action
- Inherits:
-
Object
- Object
- Action
- Includes:
- HasHelpers::Attributes, HasHelpers::UIAttributes
- Defined in:
- lib/has_helpers/utils/action.rb
Overview
Represents an action to be taken on a page or form in terms of either a link or an submit button which the user may click.
Link Actions
Link actions need only to set the service option.
NOTE: setting name or value will change the action to a submit
(see "Submit Actions" below).
Action.new(:service => "Click me".to_service("http://shadyurl.com"))
Submit Actions
For submit inputs set the input option.
Action.new(Input.new(:name => "find", :value => "Find", :label => "Seek"))
Action.new(:input => { :name => "find", :value => "Find", :label => "Seek" })
Automagical conversions
Service and Input objects may be converted to Action objcets by calling
to_action on them.
actions:
This should be set to a collection of Actions or objects which can be converted
using to_action. This convertibility greatly simplifies code like this
Action.new(
:actions => [
Service.new("http://example.com"),
Input.new(:name => "Export", :value => "pdf" )
# Could also nest an Action here!
]
)
which is equivalent to this much friendlier code:
Action.new(
:actions => {
"http://example.com".to_service,
{ :name => "Export", :value => "pdf" }.to_input
}
)
Constant Summary collapse
- DEFAULT_ICON =
Lawsuit
:caret_down
Instance Attribute Summary collapse
- #icon ⇒ Object
-
#label ⇒ Object
Returns the value of attribute label.
-
#nested ⇒ Object
Returns the value of attribute nested.
-
#render_object ⇒ Object
Returns the value of attribute render_object.
-
#service ⇒ Object
writeonly
Sets the attribute service.
Attributes included from HasHelpers::UIAttributes::HTMLAttributes
Instance Method Summary collapse
-
#cast_actions ⇒ Object
TODO: Implement a collection which guards appended elements *.
- #to_action ⇒ Object
-
#to_partial_path ⇒ Object
ActiveModel interface.
Methods included from HasHelpers::Attributes::GuardedAttributes
Methods included from HasHelpers::UIAttributes::HTMLAttributes
Methods included from HasHelpers::Attributes
Instance Attribute Details
#icon ⇒ Object
56 57 58 |
# File 'lib/has_helpers/utils/action.rb', line 56 def icon icon_or_default.try(:to_icon) end |
#label ⇒ Object
Returns the value of attribute label.
50 51 52 |
# File 'lib/has_helpers/utils/action.rb', line 50 def label @label end |
#nested ⇒ Object
Returns the value of attribute nested.
50 51 52 |
# File 'lib/has_helpers/utils/action.rb', line 50 def nested @nested end |
#render_object ⇒ Object
Returns the value of attribute render_object.
50 51 52 |
# File 'lib/has_helpers/utils/action.rb', line 50 def render_object @render_object end |
#service=(value) ⇒ Object (writeonly)
Sets the attribute service
49 50 51 |
# File 'lib/has_helpers/utils/action.rb', line 49 def service=(value) @service = value end |
Instance Method Details
#cast_actions ⇒ Object
TODO: Implement a collection which guards appended elements *
64 65 66 67 68 |
# File 'lib/has_helpers/utils/action.rb', line 64 def cast_actions # TODO: Implement a collection which guards appended elements * actions.map(&:to_action).tap do |a| a.each { |action| action.set_nested! } end end |
#to_action ⇒ Object
60 61 62 |
# File 'lib/has_helpers/utils/action.rb', line 60 def to_action self end |
#to_partial_path ⇒ Object
ActiveModel interface
71 72 73 |
# File 'lib/has_helpers/utils/action.rb', line 71 def to_partial_path "has_helpers/actions/action" end |