Class: UiBibz::Ui::Core::Component

Inherits:
Base
  • Object
show all
Defined in:
lib/ui_bibz/ui/core/component.rb

Overview

Creates a component of the given name using options created by the set of options.

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:

  • state - State of élement with symbol value: (:default, :primary, :info, :warning, :danger)

  • glyph - Add glyph with name or hash options

    • name - String

    • size - Integer

    • type - Symbol

Signatures

UiBibz::Ui::Core::Component.new(content, options = nil, html_options = nil)

UiBibz::Ui::Core::Component.new(options = nil, html_options = nil) do
  content
end

Examples

UiBibz::Ui::Core::Component.new(content, { type: :success, glyph: 'eye' },{ class: 'test' })
# or
UiBibz::Ui::Core::Component.new({glyph: { name: 'eye', size: 3}, { class: 'test' }) do
  content
end

Direct Known Subclasses

Alert, Bar, Breadcrumb, BreadcrumbLink, Button, ButtonGroup, ButtonLink, Col, Dropdown, DropdownHeader, DropdownLink, Glyph, Jumbotron, Label, List, ListGroup, Modal, ModalBody, ModalFooter, ModalHeader, Nav, NavLink, Navbar, NavbarText, Panel, ProgressBar, Row, Stars, Ux::Column, Ux::Grid, Ux::Table

Instance Attribute Summary (collapse)

Attributes inherited from Base

#output_buffer

Instance Method Summary (collapse)

Methods inherited from Base

#i18n_set?

Constructor Details

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

Use link_to system in rails

  • Content can be send by content variable or by block if a block is sent, variable 'content' does not exit.

  • Options of component is defined in hash options

  • Html options is defined in hash html_options



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ui_bibz/ui/core/component.rb', line 48

def initialize content = nil, options = nil, html_options = nil, &block
  if !block.nil?
    @html_options, @options = options, content
    context  = eval("self", block.binding)
    @content = context.capture(&block)
  else
    if content.kind_of?(Hash)
      @html_options, @options = options, content
    else
      @html_options, @options, @content = html_options, options, content
    end
  end
  @html_options = @html_options || {}
  @options      = @options || {}
end

Instance Attribute Details

- (Object) content

Returns the value of attribute content



41
42
43
# File 'lib/ui_bibz/ui/core/component.rb', line 41

def content
  @content
end

- (Object) html_options

Returns the value of attribute html_options



41
42
43
# File 'lib/ui_bibz/ui/core/component.rb', line 41

def html_options
  @html_options
end

- (Object) options

Returns the value of attribute options



41
42
43
# File 'lib/ui_bibz/ui/core/component.rb', line 41

def options
  @options
end

Instance Method Details

- (Object) add_classes(*classes)

Add classes in html_options



113
114
115
# File 'lib/ui_bibz/ui/core/component.rb', line 113

def add_classes *classes
  classes.compact.join(' ')
end

- (Object) badge_html

Render badge html tag



86
87
88
# File 'lib/ui_bibz/ui/core/component.rb', line 86

def badge_html
   :span, @options[:badge], class: 'badge'
end

- (Object) class_and_html_options(classes = nil)

Add classes in html_options



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/ui_bibz/ui/core/component.rb', line 98

def class_and_html_options classes = nil
  options_class = options[:class] if options.kind_of?(Hash)
  cls = [
    html_options[:class],
    status,
    state,
    options_class
  ]
  cls << classes unless classes.nil?
  cls = cls.flatten.compact
  html_options[:class] = cls.join(' ') unless cls.empty?
  html_options
end

- (Object) glyph

Render glyph html



80
81
82
83
# File 'lib/ui_bibz/ui/core/component.rb', line 80

def glyph
  glyph_info = options[:glyph] if options.kind_of?(Hash)
  Glyph.new(glyph_info).render unless glyph_info.nil?
end

- (Object) glyph_and_content_html

Render glyph and content html



70
71
72
# File 'lib/ui_bibz/ui/core/component.rb', line 70

def glyph_and_content_html
  [glyph_with_space, @content].compact.join.html_safe
end

- (Object) glyph_with_space

Render glyph with space html



75
76
77
# File 'lib/ui_bibz/ui/core/component.rb', line 75

def glyph_with_space
  "#{ glyph } " unless glyph.nil?
end

- (Object) render

Render html tag



65
66
67
# File 'lib/ui_bibz/ui/core/component.rb', line 65

def render
  glyph_and_content_html
end

- (Object) state

Set :default state symbol



91
92
93
94
95
# File 'lib/ui_bibz/ui/core/component.rb', line 91

def state
  sym = options.delete(:state) if options[:state]
  sym = sym || :default
  states[:sym]
end