Class: Brut::FrontEnd::Component

Inherits:
Phlex::HTML
  • Object
show all
Includes:
Brut::Framework::Errors, Helpers, I18n::ForHTML
Defined in:
lib/brut/front_end/component.rb

Overview

A Component is the top level class for managing the rendering of content. It is a Phlex component with additional features. Components are the primary mechanism for managing view complexity and managing markup re-use in Brut.

To create a component, subclass this class (or, more likely, your app's AppComponent) and provide an initializer that accepts keyword arguments. The names of these arguments will be used to locate the values that Brut will pass in when creating your component object.

Consult Brut's documentation on keyword injection to know what values you may use and how values are located.

Becuase this is a Phlex component, you must implement view_template and make calls to Phlex's API to create the markup for your component.

Defined Under Namespace

Modules: Helpers

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#entity, #global_component, #inline_svg

Methods included from I18n::ForHTML

#html_escape, #t

Methods included from I18n::BaseMethods

#l, #t, #t_direct, #this_field_value

Methods included from Brut::Framework::Errors

#abstract_method!, #bug!

Class Method Details

.component_nameObject

The name of this component, used for debugging and other purposes. Do not override this.



126
127
128
# File 'lib/brut/front_end/component.rb', line 126

def self.component_name = self.name
# Convenience method to get the component name. This just calls the class
# method {.component_name}.

Instance Method Details

#around_templateObject

Override's Phlex' callback to add instrumentation to the view_template method.



141
142
143
144
145
146
# File 'lib/brut/front_end/component.rb', line 141

def around_template
  Brut.container.instrumentation.span(self.class.name + "#view_template") do |span|
    span.add_prefixed_attributes("brut", type: :component, class: self.class)
    super
  end
end

#component_nameObject

Convenience method to get the component name. This just calls the class method component_name.



129
# File 'lib/brut/front_end/component.rb', line 129

def component_name = self.class.component_name