Module: IndexFor::Helper
- Includes:
- ShareHelper
- Defined in:
- lib/index_for/helper.rb
Instance Method Summary collapse
-
#index_for(objects, html_options = {}, &block) ⇒ Object
Creates a table around the objects and yields a builder.
-
#index_for_actions(object, *action_names, &block) ⇒ Object
Create action links and yields a builder.
-
#show_for(object, html_options = {}, &block) ⇒ Object
Creates a desc list around the object and yields a builder.
- #wice_index_for(objects, html_options = {}, &block) ⇒ Object
Instance Method Details
#index_for(objects, html_options = {}, &block) ⇒ Object
Creates a table around the objects and yields a builder.
Example:
index_for @users do |t|
t.attribute :name
t.attribute :email
end
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/index_for/helper.rb', line 14 def index_for objects, = {}, &block = .dup objects = fetch_objects objects, tag = [:table_tag] || IndexFor.table_tag klass = [:klass] || objects.try(:klass) || objects.first.class [:id] ||= index_for_id(klass) [:class] = index_for_class(klass, ) head = index_for_head(klass.new, , &block) body = index_for_body(objects, , &block) content = head + body content_tag(tag, content, ) end |
#index_for_actions(object, *action_names, &block) ⇒ Object
Create action links and yields a builder.
Example:
index_for_actions @user do |a|
a.action_link :show
a.action_link :edit
end
index_for_actions @user, :show, :edit
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/index_for/helper.rb', line 60 def index_for_actions object, *action_names, &block = action_names. action_names = [:show, :edit, :destroy] if action_names == [:all] builder = [:action_builder] || IndexFor::ActionBuilder builder = builder.new(object, , self) content = capture(builder) do |a| action_names.map do |action_name| a.action_link action_name end.join.html_safe end content += capture(builder, &block) if block content end |
#show_for(object, html_options = {}, &block) ⇒ Object
Creates a desc list around the object and yields a builder.
Example:
show_for @user do |l|
l.attribute :name
l.attribute :email
end
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/index_for/helper.rb', line 87 def show_for object, = {}, &block = .dup tag = [:list_tag] || IndexFor.list_tag [:id] ||= show_for_id(object) [:class] = show_for_class(object, ) builder = [:builder] || IndexFor::ListColumnBuilder content = capture(builder.new(object, , self), &block) content_tag(tag, content, ) end |
#wice_index_for(objects, html_options = {}, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/index_for/helper.rb', line 32 def wice_index_for objects, = {}, &block = .dup objects = fetch_objects objects, builder = [:builder] || IndexFor::WiceBuilder builder = builder.new(objects, , self) block.call builder render partial: "index_for/wice_index_for", locals: { builder: builder, objects: builder.result, html_options: , block: block } end |