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



44
45
46
# File 'lib/r_kit/grid/action_view_extension.rb', line 44

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

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



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

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



67
68
69
70
# File 'lib/r_kit/grid/action_view_extension.rb', line 67

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



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

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
18
19
20
21
22
23
# 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]
  classes = classes
    .compact
    .map(&:to_s)
    .map(&:dasherize)
    .join " "
  
  {
    :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



48
49
50
51
52
53
54
55
56
# File 'lib/r_kit/grid/action_view_extension.rb', line 48

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



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

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



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

def rows__tag col_size, collection, options = {}, &block
  rows_buffer = collection
    .to_a
    .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