Module: Brut::FrontEnd::Component::Helpers
- Included in:
- Brut::FrontEnd::Component
- Defined in:
- lib/brut/front_end/component.rb
Overview
Module for the various "free methods" available to all components. Generally, we don't want to build up mega-classes with lots of modules, but this provides a nice, singular namespace to document the helpers as apart from the various methods of the component.
Instance Method Summary collapse
-
#global_component(component_klass) ⇒ Object
Render (in Phlex parlance) a component that you would like Brut to instantiate.
-
#inline_svg(svg) ⇒ Object
Render an inline an SVG that is part of your app.
Instance Method Details
#global_component(component_klass) ⇒ Object
Render (in Phlex parlance) a component that you would like Brut to instantiate. This is useful when you want to use a component that only requires values from the RequestContext. By using this method, this component does not have to receive data from the RequestContext that only serves to pass to the component you use here.
For example, you may have a component that renders the flash message. To avoid requiring this component/page to be passed the flash, a global component can be injected with it from Brut.
This component will be rendered into the Phlex context. Do not call
render
on the result, nor rely on the return value.
107 108 109 |
# File 'lib/brut/front_end/component.rb', line 107 def global_component(component_klass) render Brut::FrontEnd::RequestContext.inject(component_klass) end |
#inline_svg(svg) ⇒ Object
Render an inline an SVG that is part of your app. Note this does not return the SVG's contents, but it renders it into the current Phlex context.
83 84 85 86 87 88 89 |
# File 'lib/brut/front_end/component.rb', line 83 def inline_svg(svg) Brut.container.svg_locator.locate(svg).then { |svg_file| File.read(svg_file) }.then { |svg_content| raw(safe(svg_content)) } end |