Class: NfgUi::Bootstrap::Components::Base
- Inherits:
-
Object
- Object
- NfgUi::Bootstrap::Components::Base
- Includes:
- ActionView::Context, ActionView::Helpers::AssetTagHelper, ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper
- Defined in:
- lib/nfg_ui/bootstrap/components/base.rb
Overview
Base Component Defines conventional, shared behavior across Bootstrap components
Direct Known Subclasses
Alert, Badge, Breadcrumb, BreadcrumbItem, Button, ButtonGroup, ButtonToolbar, Card, CardBody, CardFooter, CardHeader, CardImage, CardImageOverlay, Carousel, CarouselCaption, CarouselControl, CarouselIndicators, CarouselItem, Collapse, Dropdown, DropdownDivider, DropdownHeader, DropdownItem, DropdownMenu, DropdownToggle, Embed, Form, InputGroup, Jumbotron, ListGroup, ListGroupItem, Media, MediaBody, MediaObject, Modal, ModalBody, ModalFooter, ModalHeader, Nav, NavItem, NavLink, Navbar, NavbarBrand, NavbarNav, NavbarText, NavbarToggler, PageItem, Pagination, Popover, Progress, TabContent, TabPane, Table, Components::Base
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#options ⇒ Object
Returns the value of attribute options.
-
#view_context ⇒ Object
Returns the value of attribute view_context.
Instance Method Summary collapse
-
#component_family ⇒ Object
This is used to help identify where to find partials for rendering components.
- #data ⇒ Object
-
#href ⇒ Object
Use view_context url_for method to ensure that when objects are passed into href, e.g.
- #html_options ⇒ Object
- #id ⇒ Object
-
#initialize(component_options, view_context) ⇒ Base
constructor
A new instance of Base.
-
#render ⇒ Object
This base render handles many of the components and can be changed to have a different base element by overriding the base_element.
- #style ⇒ Object
Constructor Details
#initialize(component_options, view_context) ⇒ Base
Returns a new instance of Base.
20 21 22 23 24 25 26 |
# File 'lib/nfg_ui/bootstrap/components/base.rb', line 20 def initialize(, view_context) self. = defaults.merge!() self.view_context = view_context @body = .fetch(:body, '') utility_initialize component_initialize end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
15 16 17 |
# File 'lib/nfg_ui/bootstrap/components/base.rb', line 15 def body @body end |
#options ⇒ Object
Returns the value of attribute options.
17 18 19 |
# File 'lib/nfg_ui/bootstrap/components/base.rb', line 17 def @options end |
#view_context ⇒ Object
Returns the value of attribute view_context.
17 18 19 |
# File 'lib/nfg_ui/bootstrap/components/base.rb', line 17 def view_context @view_context end |
Instance Method Details
#component_family ⇒ Object
This is used to help identify where to find partials for rendering components.
Set the component family, e.g.: :breadcrumb on any sibling components.
For example: BreadcrumbItem & Breadcrumb are members of the :breadcrumb component_family
48 49 50 |
# File 'lib/nfg_ui/bootstrap/components/base.rb', line 48 def component_family nil end |
#data ⇒ Object
52 53 54 |
# File 'lib/nfg_ui/bootstrap/components/base.rb', line 52 def data [:data] || {} end |
#href ⇒ Object
Use view_context url_for method to ensure that when objects are passed into href, e.g. ‘href: @admin` will convert it to the correct path
Likewise that hashes are also parsed correctly example: href: { controller: ‘admin’, action: ‘show’, id: 7 }
76 77 78 79 80 81 |
# File 'lib/nfg_ui/bootstrap/components/base.rb', line 76 def href = [:href] return if .blank? view_context.url_for() end |
#html_options ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/nfg_ui/bootstrap/components/base.rb', line 56 def .except(*.uniq) .merge!(id: id, class: css_classes, data: data, href: href, style: style, **assistive_html_attributes) .reject { |_k, v| v.blank? } # prevent empty attributes from showing up # Example: <div class>Text</div> end |
#id ⇒ Object
83 84 85 |
# File 'lib/nfg_ui/bootstrap/components/base.rb', line 83 def id [:id] end |
#render ⇒ Object
This base render handles many of the components and can be changed to have a different base element by overriding the base_element. in some cases, the child component can also call super with a block to have this render as the wrapping element.
35 36 37 38 39 |
# File 'lib/nfg_ui/bootstrap/components/base.rb', line 35 def render content_tag(base_element, ) do (block_given? ? yield : body) end end |
#style ⇒ Object
87 88 89 |
# File 'lib/nfg_ui/bootstrap/components/base.rb', line 87 def style [:style] end |