Class: Grid

Inherits:
RKit::Grid::Base show all
Defined in:
lib/r_kit/grid/base/grid.rb

Instance Attribute Summary collapse

Attributes inherited from RKit::Grid::Base

#_binding

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RKit::Grid::Base

#_h, #to_s

Constructor Details

#initialize(collection, &block) ⇒ Grid

Returns a new instance of Grid.



18
19
20
21
22
23
24
25
# File 'lib/r_kit/grid/base/grid.rb', line 18

def initialize collection, &block
  @collection = collection

  @_binding = RKit::Grid::Binding.new
  @_binding.block = block

  super @_binding
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



16
17
18
# File 'lib/r_kit/grid/base/grid.rb', line 16

def collection
  @collection
end

Class Method Details

.binding_accessor(name) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/r_kit/grid/base/grid.rb', line 40

def binding_accessor name
  define_method name do |value, &block|
    _binding.block = block if block
    _binding.send "#{ name }=", value

    self
  end
end

.try_convert(object, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/r_kit/grid/base/grid.rb', line 3

def self.try_convert object, &block
  if object.kind_of? RKit::Grid::Base
    object

  elsif object.respond_to? :to_grid
    object.to_grid &block

  else
    RKit::Grid::Base::Grid.new Array.wrap(object), &block
  end
end

Instance Method Details

#_attributesObject



70
71
72
# File 'lib/r_kit/grid/base/grid.rb', line 70

def _attributes
  _binding.attributes
end

#_tagObject



66
67
68
# File 'lib/r_kit/grid/base/grid.rb', line 66

def _tag
  :div
end

#captureObject



74
75
76
77
78
79
# File 'lib/r_kit/grid/base/grid.rb', line 74

def capture
  collection.map do |object|
    GridCol.new(object, binding: _binding).to_s
  end
  .reduce(:safe_concat)
end

#flex(&block) ⇒ Object



56
57
58
# File 'lib/r_kit/grid/base/grid.rb', line 56

def flex &block
  attributes class: 'grid-flex', &block
end

#items(value, &block) ⇒ Object



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

def items value, &block
  attributes class: "grid-items-#{ value }", &block
end

#required_bindingsObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/r_kit/grid/base/grid.rb', line 27

def required_bindings
  # TODO: change config to min-col-size
  # TODO: col size adapts to collection size, but not below min-col-size
  {
    col_size: RKit::Grid.config.col_size,
    attributes: {
      class: :grid
    }
  }
end