Module: Lanes::Components

Defined in:
lib/lanes/components.rb

Constant Summary collapse

@@enabled =
[]

Class Method Summary collapse

Class Method Details

.component_configuration(component, env) ⇒ Object

or an empty hash if no configuration is present

Parameters:

  • component (String, Symbol)

    component name to lookup

Returns:

  • Hash configuration for component, read from a config.json file in the components directory,



33
34
35
36
37
38
39
40
41
# File 'lib/lanes/components.rb', line 33

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

.enable(*names) ⇒ Object

Parameters:

  • names (Symbol)

    list of components to include in applications



9
10
11
12
# File 'lib/lanes/components.rb', line 9

def enable(*names)
    @@enabled += names.map(&:to_s)
    @@enabled.uniq!
end

.enabled(&block) ⇒ Object



14
15
16
# File 'lib/lanes/components.rb', line 14

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

.enabled_with_dependencies(env, &block) ⇒ Object

Called by sprockets during processing from the client/components/enabled.js.erb Requires the enabled components and all of their dependencies



20
21
22
23
24
25
26
27
28
# File 'lib/lanes/components.rb', line 20

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