Sha256: a879b5c4c33b2951b356678c74d93619090e9cc092158bf63a67768d362dfea5

Contents?: true

Size: 1.58 KB

Versions: 18

Compression:

Stored size: 1.58 KB

Contents

module Lanes

    module Components
        @@enabled = []

        class << self

            # @param names [Symbol] list of components to include in applications
            def enable(*names)
                @@enabled += names.map(&:to_s)
                @@enabled.uniq!
            end

            def enabled(&block)
                @@enabled.each{ |component| yield component }
            end

            # Called by sprockets during processing from the client/components/enabled.js.erb
            # Requires the enabled components and all of their dependencies
            def enabled_with_dependencies(env, &block)
                enabled do | component |
                    config = component_configuration(component, env.environment)
                    if config['depends']
                        config['depends'].each{ |d| yield d }
                    end
                    yield component
                end
            end

            # @param component [String,Symbol] component name to lookup
            # @return Hash configuration for component, read from a config.json file in the components directory,
            # or an empty hash if no configuration is present
            def component_configuration(component, env)
                if asset = env.find_asset("lanes/components/#{component}")
                    config_file = asset.pathname.dirname.join("config.json")
                    if config_file.exist?
                        return Oj.load(config_file.read)
                    end
                end
                return {}
            end

        end
    end

end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
lanes-0.8.3 lib/lanes/components.rb
lanes-0.8.2 lib/lanes/components.rb
lanes-0.8.1 lib/lanes/components.rb
lanes-0.8.0 lib/lanes/components.rb
lanes-0.7.0 lib/lanes/components.rb
lanes-0.6.1 lib/lanes/components.rb
lanes-0.6.0 lib/lanes/components.rb
lanes-0.5.6 lib/lanes/components.rb
lanes-0.5.5 lib/lanes/components.rb
lanes-0.5.0 lib/lanes/components.rb
lanes-0.4.0 lib/lanes/components.rb
lanes-0.3.0 lib/lanes/components.rb
lanes-0.1.9.5 lib/lanes/components.rb
lanes-0.1.9 lib/lanes/components.rb
lanes-0.1.8 lib/lanes/components.rb
lanes-0.1.7 lib/lanes/components.rb
lanes-0.1.6 lib/lanes/components.rb
lanes-0.1.5 lib/lanes/components.rb