class Grid

Attributes

collection[RW]

Public Class Methods

binding_accessor(name) click to toggle source
# 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
new(collection, &block) click to toggle source
Calls superclass method RKit::Grid::Base::new
# 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
try_convert(object, &block) click to toggle source
# 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

Public Instance Methods

_attributes() click to toggle source
# File lib/r_kit/grid/base/grid.rb, line 70
def _attributes
  _binding.attributes
end
_tag() click to toggle source
# File lib/r_kit/grid/base/grid.rb, line 66
def _tag
  :div
end
capture() click to toggle source
# 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) click to toggle source
# File lib/r_kit/grid/base/grid.rb, line 56
def flex &block
  attributes class: 'grid-flex', &block
end
items(value, &block) click to toggle source
# File lib/r_kit/grid/base/grid.rb, line 60
def items value, &block
  attributes class: "grid-items-#{ value }", &block
end
required_bindings() click to toggle source
# 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