Class: UiBibz::Ui::Core::Component
- Inherits:
-
Base
- Object
- Base
- UiBibz::Ui::Core::Component
- 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, = nil, = nil)
UiBibz::Ui::Core::Component.new( = nil, = 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)
-
- (Object) content
Returns the value of attribute content.
-
- (Object) html_options
Returns the value of attribute html_options.
-
- (Object) options
Returns the value of attribute options.
Attributes inherited from Base
Instance Method Summary (collapse)
- - (Object) add_classes(*classes)
- - (Object) badge_html
- - (Object) class_and_html_options(classes = nil)
- - (Object) glyph
- - (Object) glyph_and_content_html
- - (Object) glyph_with_space
-
- (Component) initialize(content = nil, options = nil, html_options = nil, &block)
constructor
A new instance of Component.
- - (Object) options_in_html_options(opts)
- - (Object) render
- - (Object) state
- - (Object) states
- - (Object) status
Methods inherited from Base
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, = nil, = nil, &block if !block.nil? @html_options, @options = , content context = eval("self", block.binding) @content = context.capture(&block) else if content.kind_of?(Hash) @html_options, @options = , content else @html_options, @options, @content = , , 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 end |
- (Object) options
Returns the value of attribute options
41 42 43 |
# File 'lib/ui_bibz/ui/core/component.rb', line 41 def @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 content_tag :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 classes = nil = [:class] if .kind_of?(Hash) cls = [ [:class], status, state, ] cls << classes unless classes.nil? cls = cls.flatten.compact [:class] = cls.join(' ') unless cls.empty? end |
- (Object) glyph
67 68 69 70 |
# File 'lib/ui_bibz/ui/core/component.rb', line 67 def glyph glyph_info = [:glyph] if .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 opts .merge!(opts) unless opts.nil? 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 = .delete(:state) if [: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 [:status] end |