Sha256: b986c0981d934ca044664f266a3ac6ac1316bfe78f009b79df63e7a872608d1f

Contents?: true

Size: 1.58 KB

Versions: 1

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_sym)
                @@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

1 entries across 1 versions & 1 rubygems

Version Path
lanes-0.1.2 lib/lanes/components.rb