Class: SimpleModelView::ActionViewHelperBuilder

Inherits:
Object
  • Object
show all
Includes:
TemplateHelpers
Defined in:
lib/simple_model_view/action_view_helper_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TemplateHelpers

#blank_span, #block_concat, #merge_html_attrs

Constructor Details

#initialize(template) ⇒ ActionViewHelperBuilder

Returns a new instance of ActionViewHelperBuilder.



7
8
9
# File 'lib/simple_model_view/action_view_helper_builder.rb', line 7

def initialize(template)
  @template = template
end

Instance Attribute Details

#templateObject (readonly)

Returns the value of attribute template.



11
12
13
# File 'lib/simple_model_view/action_view_helper_builder.rb', line 11

def template
  @template
end

Instance Method Details

#collection_table(collection, *args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/simple_model_view/action_view_helper_builder.rb', line 23

def collection_table(collection, *args)
  builder = SimpleModelView::CollectionTableBuilder.new template, collection, *args

  template. :table, nil, SimpleModelView.collection_table_html do
    block_concat do
      template. :thead do
        template. :tr do
          columns_builder = builder.columns_builder
          yield columns_builder
        end
      end
    end
    block_concat do
      template. :tbody do
        collection.each do |el|
          block_concat do
            template. :tr do
              row_builder = builder.row_builder_for el
              yield row_builder
            end
          end
        end
      end
    end
  end
end

#resource_table(model, *args) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/simple_model_view/action_view_helper_builder.rb', line 13

def resource_table(model, *args)
  builder = SimpleModelView::ResourceTableBuilder.new template, model, *args

  template. :table, nil, SimpleModelView.collection_table_html do
    template. :tbody do
      yield builder
    end
  end
end