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

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.

Parameters:

  • component_klass (Class)

    the component class to use in the view. This class's initializer must only require information available from the RequestContext.



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.

Parameters:

  • svg (String)

    path to the SVG file, relative to where SVGs are stored, which is app/src/front_end/svgs or where Brut.container.svg_locator is looking

See Also:



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