Class: Puffer::Component::Base
- Inherits:
-
AbstractController::Base
- Object
- AbstractController::Base
- Puffer::Component::Base
- Extended by:
- ClassMethods
- Includes:
- AbstractController::Layouts, AbstractController::Logger, AbstractController::Rendering, AbstractController::Translation, ActionController::Helpers, ActionController::RequestForgeryProtection, ActionController::UrlFor
- Defined in:
- lib/puffer/component.rb
Overview
Puffer::Component::Base
is a base component low-level for puffer fields. It provides all the base functionality for rendering visual fields components. Every component belongs to field by field’s type Every component should have some basic actions, based on parent controller fieldsets, so they can be fallbacked as fieldsets.
Also, every component can have additional actions for ajax requests handling and component state changing
Direct Known Subclasses
BaseComponent, ReferencesManyComponent, ReferencesOneComponent, RenderComponent
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#identifer ⇒ Object
readonly
Returns the value of attribute identifer.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#parent_controller ⇒ Object
readonly
Returns the value of attribute parent_controller.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #component_id ⇒ Object
- #event_options(name) ⇒ Object
- #event_path(name, options = {}) ⇒ Object
- #event_url(name, options = {}) ⇒ Object
- #fallback_action(action_name) ⇒ Object
-
#initialize(field) ⇒ Base
constructor
A new instance of Base.
- #javascript_wrap(type, html) ⇒ Object
- #method_for_action(action_name) ⇒ Object
- #process(context, parent_controller, record, options = {}) ⇒ Object
- #render(*args, &block) ⇒ Object
- #replace(*args) ⇒ Object
Methods included from ClassMethods
Constructor Details
#initialize(field) ⇒ Base
Returns a new instance of Base.
41 42 43 44 |
# File 'lib/puffer/component.rb', line 41 def initialize field super() @field = field end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
37 38 39 |
# File 'lib/puffer/component.rb', line 37 def field @field end |
#identifer ⇒ Object (readonly)
Returns the value of attribute identifer.
37 38 39 |
# File 'lib/puffer/component.rb', line 37 def identifer @identifer end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
37 38 39 |
# File 'lib/puffer/component.rb', line 37 def opts @opts end |
#parent_controller ⇒ Object (readonly)
Returns the value of attribute parent_controller.
37 38 39 |
# File 'lib/puffer/component.rb', line 37 def parent_controller @parent_controller end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
37 38 39 |
# File 'lib/puffer/component.rb', line 37 def record @record end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
37 38 39 |
# File 'lib/puffer/component.rb', line 37 def records @records end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
37 38 39 |
# File 'lib/puffer/component.rb', line 37 def resource @resource end |
Instance Method Details
#component_id ⇒ Object
98 99 100 |
# File 'lib/puffer/component.rb', line 98 def component_id "component_#{identifer}" end |
#event_options(name) ⇒ Object
94 95 96 |
# File 'lib/puffer/component.rb', line 94 def name {:action => :event, :event => name, :field => field.to_s, :fieldset => field.field_set.name, :identifer => identifer} end |
#event_path(name, options = {}) ⇒ Object
90 91 92 |
# File 'lib/puffer/component.rb', line 90 def event_path name, = {} resource.collection_path ( || {}).merge((name)) end |
#event_url(name, options = {}) ⇒ Object
86 87 88 |
# File 'lib/puffer/component.rb', line 86 def event_url name, = {} resource.collection_url ( || {}).merge((name)) end |
#fallback_action(action_name) ⇒ Object
82 83 84 |
# File 'lib/puffer/component.rb', line 82 def fallback_action action_name ((parent_controller._fieldset_fallbacks[action_name] || []).detect {|name| action_method? name.to_s} || action_name).to_s end |
#javascript_wrap(type, html) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/puffer/component.rb', line 69 def javascript_wrap type, html case type when :replace then "$('#{component_id}').replace('#{view_context.escape_javascript html}')".html_safe else html end end |
#method_for_action(action_name) ⇒ Object
78 79 80 |
# File 'lib/puffer/component.rb', line 78 def method_for_action action_name super fallback_action(action_name) end |
#process(context, parent_controller, record, options = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/puffer/component.rb', line 46 def process context, parent_controller, record, = {} @parent_controller = parent_controller @record = record @opts = @identifer = params[:identifer] || generate_identifer resource_params = params resource_params.merge!(:id => record.id) if record && record.respond_to?(:id) @resource = Puffer::Resource.new(resource_params, parent_controller) super context end |
#render(*args, &block) ⇒ Object
59 60 61 62 63 |
# File 'lib/puffer/component.rb', line 59 def render *args, &block = _normalize_render(*args, &block) [:template] = fallback_action([:template]) render_to_body().html_safe end |
#replace(*args) ⇒ Object
65 66 67 |
# File 'lib/puffer/component.rb', line 65 def replace *args javascript_wrap :replace, render(*args) end |