Module: RKit::Grid::ActionViewExtension

Defined in:
lib/r_kit/grid/action_view_extension.rb

Instance Method Summary collapse

Instance Method Details

#col__tag(col_size, options = {}, &block) ⇒ Object



38
39
40
# File 'lib/r_kit/grid/action_view_extension.rb', line 38

def col__tag col_size, options = {}, &block
  col_tag options.merge(col_size: col_size), &block
end

#col_tag(options = {}, &block) ⇒ Object



30
31
32
33
34
35
# File 'lib/r_kit/grid/action_view_extension.rb', line 30

def col_tag options = {}, &block
  proc_options options[:instance], options
  html_options = html_options(options, {class: "col-#{ options[:col_size] }"})
  
  (options[:tag] || :div, html_options){ block.call(options[:instance]) }
end

#container__tag(col_size, collection, options = {}, &block) ⇒ Object



60
61
62
63
# File 'lib/r_kit/grid/action_view_extension.rb', line 60

def container__tag col_size, collection, options = {}, &block
  row_options = options.delete(:rows) || {}
  container_tag(options){ send("rows_#{ col_size}_tag", collection, row_options, &block) }
end

#container_tag(options = {}, &block) ⇒ Object



20
21
22
23
# File 'lib/r_kit/grid/action_view_extension.rb', line 20

def container_tag options = {}, &block
  html_options = html_options(options, {class: :container})
   options[:tag] || :div, html_options, &block
end

#html_options(options = {}, defaults = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/r_kit/grid/action_view_extension.rb', line 8

def html_options options = {}, defaults = {}
  id = options[:id]
  classes = "#{ defaults[:class] } #{ options[:class] }"
  classes += " off-#{ options[:offset] }" if options[:offset]
  
  {
    :id => id,
    :class => classes
  }
end

#proc_options(instance, options = {}) ⇒ Object



2
3
4
5
6
# File 'lib/r_kit/grid/action_view_extension.rb', line 2

def proc_options instance, options = {}
  (options[:proc_options] || []).each do |key, proc|
    options[key] = proc.call(instance)
  end
end

#row__tag(col_size, collection, options = {}, &block) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/r_kit/grid/action_view_extension.rb', line 42

def row__tag col_size, collection, options = {}, &block
  col_options = options[:cols] || {}
  
  cols_buffer = collection.inject ActiveSupport::SafeBuffer.new do |safe_buffer, instance|
    safe_buffer.safe_concat send("col_#{ col_size }_tag", col_options.merge(instance: instance), &block)
  end
  
  row_tag(options){ cols_buffer }
end

#row_tag(options = {}, &block) ⇒ Object



25
26
27
28
# File 'lib/r_kit/grid/action_view_extension.rb', line 25

def row_tag options = {}, &block
  html_options = html_options(options, {class: :row})
   options[:tag] || :div, html_options, &block
end

#rows__tag(col_size, collection, options = {}, &block) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/r_kit/grid/action_view_extension.rb', line 52

def rows__tag col_size, collection, options = {}, &block
  rows_buffer = collection
    .in_groups_of(12 / col_size, false)
    .inject ActiveSupport::SafeBuffer.new do |safe_buffer, collection|
      safe_buffer.safe_concat send("row_#{ col_size }_tag", collection, options, &block)
  end
end