Module: Lanes::Extensions

Defined in:
lib/lanes/extension.rb,
lib/lanes/extension/definition.rb

Defined Under Namespace

Classes: Base, Definition

Constant Summary collapse

ALL =
Array.new

Class Method Summary collapse

Class Method Details

.add(klass) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/lanes/extension.rb', line 25

def add(klass)
    @cached_instances = nil
    if Extensions.controlling_locked
        ALL.unshift(klass)
    else
        ALL << klass
    end
end

.allObject



34
35
36
# File 'lib/lanes/extension.rb', line 34

def all
    ALL
end

.client_bootstrap_data(view) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/lanes/extension.rb', line 86

def client_bootstrap_data(view)
    data = {
      csrf_token: Rack::Csrf.csrf_token(view.env),
      controlling_extension: controlling.identifier,
      root_view:  Lanes.config.root_view,
      assets_path_prefix: Lanes.config.assets_path_prefix,
      api_path: Lanes.config.mounted_at,
      environment: Lanes.config.environment,
      initial_workspace_screen_id: Lanes.config.initial_workspace_screen_id,
    }
    each do | ext |
        ext_data  = ext.client_bootstrap_data(view)
        data[ext.identifier] = ext_data unless ext_data.nil?
    end
    return data
end

.controllingObject



80
81
82
83
84
# File 'lib/lanes/extension.rb', line 80

def controlling
    last = ALL.last
    each{|ext| return ext if ext.is_a?(last) }
    Lanes.logger.error "Unable to find controlling extension. #{sorted} are loaded"
end

.eachObject



75
76
77
78
# File 'lib/lanes/extension.rb', line 75

def each
    @cached_instances ||= sorted.map{ |klass| klass.new }
    @cached_instances.each{ |ext| yield ext }
end

.each_asset(phase: :early, type: :js) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/lanes/extension.rb', line 38

def each_asset(phase: :early, type: :js)
    each do |ext|
        if phase == :all || ext.load_phase == phase
            asset = case type
                    when :js  then ext.javascript_include
                    when :css then ext.stylesheet_include
                    else nil
                    end
            yield asset unless asset.nil?
        end
    end
end

.load_controlling_configObject



103
104
105
106
107
108
# File 'lib/lanes/extension.rb', line 103

def load_controlling_config
    config_file = self.controlling.root_path.join('config','lanes.rb')
    if config_file.exist?
        require config_file
    end
end

.load_screensObject



10
11
12
13
14
15
16
17
# File 'lib/lanes/extension.rb', line 10

def load_screens
    each do | ext |
        screens_config = ext.root_path.join('config','screens.rb')
        if screens_config.exist?
            require screens_config
        end
    end
end

.lock_controlling!Object

lock the current controlling extension so that it can’t be changed by other extensions that are loaded later



21
22
23
# File 'lib/lanes/extension.rb', line 21

def lock_controlling!
    self.controlling_locked=true
end

.sortedObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/lanes/extension.rb', line 51

def sorted
    unmapped = all
    mapped   = []
    while unmapped.any?
        mapped_count = mapped.length
        unmapped.each do | ext |
            if !ext.before && !ext.after
                mapped.push(ext)
            end
            if ext.before && (position = mapped.find_index(ext.before))
                mapped.insert(position, ext)
            end
            if ext.after && (position = mapped.find_index(ext.after))
                mapped.insert(position+1, ext)
            end
        end
        if mapped_count == mapped.length # we failed to add any extensions
            Lanes.logger.info "Conflicting load directives.  Some extensions will not be available"
        end
        unmapped -= mapped
    end
    mapped
end