Class: Radiant::ExtensionLoader

Inherits:
Object
  • Object
show all
Includes:
Simpleton
Defined in:
lib/radiant/extension_loader.rb

Defined Under Namespace

Classes: DependenciesObserver

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Simpleton

included

Constructor Details

#initializeExtensionLoader

Returns a new instance of ExtensionLoader.



28
29
30
# File 'lib/radiant/extension_loader.rb', line 28

def initialize
  self.extensions = []
end

Instance Attribute Details

#extensionsObject

Returns the value of attribute extensions.



26
27
28
# File 'lib/radiant/extension_loader.rb', line 26

def extensions
  @extensions
end

#initializerObject

Returns the value of attribute initializer.



26
27
28
# File 'lib/radiant/extension_loader.rb', line 26

def initializer
  @initializer
end

Instance Method Details

#activate_extensionsObject Also known as: reactivate



92
93
94
95
96
97
98
99
100
101
# File 'lib/radiant/extension_loader.rb', line 92

def activate_extensions
  initializer.initialize_default_admin_tabs
  # Reset the view paths after
  initializer.initialize_framework_views
  # Reset the admin UI regions
  initializer.admin.load_default_regions
  extensions.each &:activate
  # Make sure we have our subclasses loaded!
  Page.load_subclasses
end

#add_controller_pathsObject



59
60
61
# File 'lib/radiant/extension_loader.rb', line 59

def add_controller_paths
  configuration.controller_paths.concat(controller_paths)
end

#add_extension_pathsObject



44
45
46
47
48
49
# File 'lib/radiant/extension_loader.rb', line 44

def add_extension_paths
  extension_load_paths.reverse_each do |path|
    configuration.load_paths.unshift path
    $LOAD_PATH.unshift path
  end
end

#add_plugin_pathsObject



51
52
53
# File 'lib/radiant/extension_loader.rb', line 51

def add_plugin_paths
  configuration.plugin_paths.concat plugin_paths
end

#configurationObject



32
33
34
# File 'lib/radiant/extension_loader.rb', line 32

def configuration
  initializer.configuration
end

#controller_pathsObject



55
56
57
# File 'lib/radiant/extension_loader.rb', line 55

def controller_paths
  extensions.map { |extension| "#{extension.root}/app/controllers" }.select { |d| File.directory?(d) }
end

#deactivate_extensionsObject



88
89
90
# File 'lib/radiant/extension_loader.rb', line 88

def deactivate_extensions
  extensions.each &:deactivate
end

#extension_load_pathsObject



36
37
38
# File 'lib/radiant/extension_loader.rb', line 36

def extension_load_paths
  load_extension_roots.map { |extension| load_paths_for(extension) }.flatten.select { |d| File.directory?(d) }
end

#load_extensionsObject

Load the extensions



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/radiant/extension_loader.rb', line 72

def load_extensions
  @observer ||= DependenciesObserver.new(configuration).observe(::ActiveSupport::Dependencies)
  self.extensions = load_extension_roots.map do |root|
    begin
      extension_file = "#{File.basename(root).sub(/^\d+_/,'')}_extension"
      extension = extension_file.camelize.constantize
      extension.unloadable
      extension.root = root
      extension
    rescue LoadError, NameError => e
      $stderr.puts "Could not load extension from file: #{extension_file}.\n#{e.inspect}"
      nil
    end
  end.compact
end

#metal_pathsObject



67
68
69
# File 'lib/radiant/extension_loader.rb', line 67

def metal_paths
  load_extension_roots.map { |extension| "#{extension}/app/metal" }.select { |d| File.directory?(d) }.reverse
end

#plugin_pathsObject



40
41
42
# File 'lib/radiant/extension_loader.rb', line 40

def plugin_paths
  load_extension_roots.map {|extension| "#{extension}/vendor/plugins" }.select {|d| File.directory?(d) }
end

#view_pathsObject



63
64
65
# File 'lib/radiant/extension_loader.rb', line 63

def view_paths
  extensions.map { |extension| "#{extension.root}/app/views" }.select { |d| File.directory?(d) }.reverse
end