module Bootstrap4RailsComponents::UI::Utilities::Initializer
Centralizes initialization for the UI
namespaces
Attributes
class_name[RW]
component[RW]
component_name[RW]
options[RW]
traits[RW]
Public Instance Methods
render_component()
click to toggle source
# File lib/bootstrap4_rails_components/ui/utilities/initializer.rb, line 21 def render_component component.render rescue NotImplementedError view_context.render partial: partial_path, locals: { component_name => component } end
Private Instance Methods
ancestry_string()
click to toggle source
# File lib/bootstrap4_rails_components/ui/utilities/initializer.rb, line 55 def ancestry_string '' end
component_family()
click to toggle source
def component_name_folder
@component_name_folder ||= ''
end
# File lib/bootstrap4_rails_components/ui/utilities/initializer.rb, line 63 def component_family component.component_family.presence end
components_within_group(*)
click to toggle source
# File lib/bootstrap4_rails_components/ui/utilities/initializer.rb, line 67 def components_within_group(*) [] end
group()
click to toggle source
# File lib/bootstrap4_rails_components/ui/utilities/initializer.rb, line 75 def group; end
grouping_folder()
click to toggle source
# File lib/bootstrap4_rails_components/ui/utilities/initializer.rb, line 71 def grouping_folder '' end
initializer(component_name = nil, *traits, **options, &block)
click to toggle source
Provides a central initialization method for Bootstrap4RailsComponents::UI::Base
child classes
# File lib/bootstrap4_rails_components/ui/utilities/initializer.rb, line 38 def initializer(component_name = nil, *traits, **options, &block) # #init_haml_helpers is required when utilizing #capture with HAML # (when outside of Rails) # https://www.rubydoc.info/github/haml/haml/Haml%2FHelpers:init_haml_helpers init_haml_helpers @component_name = component_name @class_name = component_name.to_s.camelize @traits = traits @options = options options[:body] = capture(&block) if block_given? options[:traits] = traits.present? ? traits : [] # self.view_context = view_context self.component = ancestry_string.constantize.new(options, view_context) end
partial_path()
click to toggle source
# File lib/bootstrap4_rails_components/ui/utilities/initializer.rb, line 77 def partial_path [ 'bootstrap4_rails_components', grouping_folder, (component_name_folder if component_name_folder.present?), component_name ].reject(&:nil?).join('/').chomp end
render_if()
click to toggle source
# File lib/bootstrap4_rails_components/ui/utilities/initializer.rb, line 29 def render_if options.fetch(:render_if, true) end
render_unless()
click to toggle source
# File lib/bootstrap4_rails_components/ui/utilities/initializer.rb, line 33 def render_unless options.fetch(:render_unless, true) end