Class: Action

Inherits:
Object
  • Object
show all
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 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

Attributes included from HasHelpers::UIAttributes::HTMLAttributes

#data, #skin

Instance Method Summary collapse

Methods included from HasHelpers::Attributes::GuardedAttributes

included

Methods included from HasHelpers::UIAttributes::HTMLAttributes

#raw_html_attrs

Methods included from HasHelpers::Attributes

included

Instance Attribute Details

#iconObject



56
57
58
# File 'lib/has_helpers/utils/action.rb', line 56

def icon
  icon_or_default.try(:to_icon)
end

#labelObject

Returns the value of attribute label.



50
51
52
# File 'lib/has_helpers/utils/action.rb', line 50

def label
  @label
end

#nestedObject

Returns the value of attribute nested.



50
51
52
# File 'lib/has_helpers/utils/action.rb', line 50

def nested
  @nested
end

#render_objectObject

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

Parameters:

  • value

    the value to set the attribute service to.



49
50
51
# File 'lib/has_helpers/utils/action.rb', line 49

def service=(value)
  @service = value
end

Instance Method Details

#cast_actionsObject

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_actionObject



60
61
62
# File 'lib/has_helpers/utils/action.rb', line 60

def to_action
  self
end

#to_partial_pathObject

ActiveModel interface



71
72
73
# File 'lib/has_helpers/utils/action.rb', line 71

def to_partial_path
  "has_helpers/actions/action"
end