Class: UiBibz::Ui::Ux::Grid

Inherits:
Core::Component show all
Defined in:
lib/ui_bibz/ui/ux/grid.rb

Overview

Create a Grid

This element is an extend of UiBibz::Ui::Ux::Component.

Attributes

  • content - Content of element

  • options - Options of element

  • html_options - Html Options of element

Options

You can add HTML attributes using the html_options. You can pass arguments in options attribute:

Signatures

UiBibz::Ui::Ux::Grid.new().tap do |g|
  ...
  g.view content = nil, options = nil, html_options = nil, &block
  ...
end

Exemples

UiBibz::Ui::Ux::Grid.new().tap do |g|
  g.view num: 5, position: :left do
    'left'
  end
  g.view position: :right do
    'right'
  end
  g.view({ position: :top}, { class: 'success'}) do
    'top'
  end
  g.view position: :center do
    'center'
  end
  g.view position: :bottom do
    'bottom'
  end
end.render

Helper

grid(options = { tap: true }, html_options = {}) do |g|
  g.view(content, options = {}, html_options = {})
  g.view(options = {}, html_options = {}) do
    content
  end
end

Constant Summary

COL_NUM =
12

Instance Attribute Summary

Attributes inherited from Core::Component

#content, #html_options, #options

Attributes inherited from Base

#output_buffer

Instance Method Summary (collapse)

Methods inherited from Core::Component

#add_classes, #badge_html, #class_and_html_options, #glyph, #glyph_and_content_html, #glyph_with_space, #state

Methods inherited from Base

#i18n_set?

Constructor Details

- (Grid) initialize(content = nil, options = nil, html_options = nil, &block)

Returns a new instance of Grid



59
60
61
62
# File 'lib/ui_bibz/ui/ux/grid.rb', line 59

def initialize content = nil, options = nil, html_options = nil, &block
  super
  @views = {}
end

Instance Method Details

- (Object) render

Render html tag



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ui_bibz/ui/ux/grid.rb', line 73

def render
  define_col_nums
  UiBibz::Ui::Core::Row.new(class: 'grid') do
    # top
    concat top_view    unless @views[:top].nil?
    # left
    concat left_view   unless @views[:left].nil?
    # center
    concat center_view unless @views[:center].nil?
    # right
    concat right_view  unless @views[:right].nil?
    # bottom
    concat bottom_view unless @views[:bottom].nil?
  end.render
end

- (Object) view(content = nil, options = nil, html_options = nil, &block)

Add grid view items



65
66
67
68
69
70
# File 'lib/ui_bibz/ui/ux/grid.rb', line 65

def view content = nil, options = nil, html_options = nil, &block
  o      = content.kind_of?(Hash) ? content : options
  c      = UiBibz::Ui::Core::Component.new content, options, html_options, &block
  h      = Hash[o[:position], { component: c, num: o[:num]}]
  @views = @views.merge(h)
end