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, DropdownList, Glyph, Jumbotron, Label, List, ListGroup, Nav, NavLink, Navbar, NavbarForm, NavbarText, Panel, ProgressBar, Row, Ux::Column, Ux::Grid, Ux::Table, Ux::TableAction

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)

Returns a new instance of Component



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ui_bibz/ui/core/component.rb', line 43

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)



132
133
134
# File 'lib/ui_bibz/ui/core/component.rb', line 132

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

- (Object) badge_html



94
95
96
# File 'lib/ui_bibz/ui/core/component.rb', line 94

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

- (Object) class_and_html_options(classes = nil)



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



67
68
69
70
# File 'lib/ui_bibz/ui/core/component.rb', line 67

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



63
64
65
# File 'lib/ui_bibz/ui/core/component.rb', line 63

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

- (Object) glyph_with_space



72
73
74
# File 'lib/ui_bibz/ui/core/component.rb', line 72

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

- (Object) options_in_html_options(opts)



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

def options_in_html_options opts
  html_options.merge!(opts) unless opts.nil?
  html_options
end

- (Object) render



59
60
61
# File 'lib/ui_bibz/ui/core/component.rb', line 59

def render
  glyph_and_content_html
end

- (Object) state



88
89
90
91
92
# File 'lib/ui_bibz/ui/core/component.rb', line 88

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

- (Object) states



121
122
123
124
125
126
127
128
129
130
# File 'lib/ui_bibz/ui/core/component.rb', line 121

def states
  if @states.nil?
    states = {}
    %w(default success primary info warning danger).each do |s|
      states = states.merge(Hash[s.to_sym, s])
    end
    @states = states
  end
  @states
end

- (Object) status



117
118
119
# File 'lib/ui_bibz/ui/core/component.rb', line 117

def status
  options[:status]
end