Sha256: 15a3556620130770cfd7668566ac7b71c44b65c828a6dcc8da15dec5cc128280

Contents?: true

Size: 760 Bytes

Versions: 22

Compression:

Stored size: 760 Bytes

Contents

class Card
  class Bootstrap
    module ComponentLoader
      def load_components
        components.each do |component|
          require_relative "component/#{component}"
          include_component component
        end
      end

      def include_component component
        component_class = to_const component.camelcase
        define_method component do |*args, &block|
          component_class.render self, *args, &block
        end
      end

      def components
        path = File.expand_path "component/*.rb", __dir__
        Dir.glob(path).map do |file|
          File.basename file, ".rb"
        end
      end

      def to_const name
        self.class.const_get "::Card::Bootstrap::Component::#{name.camelcase}"
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
card-mod-bootstrap-0.18.1 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.18.0 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.17.0 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.16.0 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.15.6 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.15.5 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.15.4 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.15.3 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.15.1.2 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.15.2.pre1 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.15.1.1 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.15.1 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.15.0 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.14.2 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.14.1 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.14.0 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.13.4 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.13.3 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.13.2 lib/card/bootstrap/component_loader.rb
card-mod-bootstrap-0.13.1 lib/card/bootstrap/component_loader.rb