Module: Card::Bootstrap::ComponentLoader
- Included in:
- Card::Bootstrap, Card::Bootstrapper
- Defined in:
- lib/card/bootstrap/component_loader.rb
Overview
support class for loading bootstrap components
Instance Method Summary collapse
- #components ⇒ Object
- #include_component(component) ⇒ Object
- #load_components ⇒ Object
- #to_const(name) ⇒ Object
Instance Method Details
#components ⇒ Object
19 20 21 22 23 24 |
# File 'lib/card/bootstrap/component_loader.rb', line 19 def components path = File. "component/*.rb", __dir__ Dir.glob(path).map do |file| File.basename file, ".rb" end end |
#include_component(component) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/card/bootstrap/component_loader.rb', line 12 def include_component component component_class = to_const component.camelcase define_method component do |*args, &block| component_class.render self, *args, &block end end |
#load_components ⇒ Object
5 6 7 8 9 10 |
# File 'lib/card/bootstrap/component_loader.rb', line 5 def load_components components.each do |component| require_relative "component/#{component}" include_component component end end |
#to_const(name) ⇒ Object
26 27 28 |
# File 'lib/card/bootstrap/component_loader.rb', line 26 def to_const name self.class.const_get "::Card::Bootstrap::Component::#{name.camelcase}" end |