Module: Radiant::Configuration

Includes:
Rails::Configuration
Defined in:
lib/radiant/initializer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#extension_dependenciesObject

Returns the value of attribute extension_dependencies.



15
16
17
# File 'lib/radiant/initializer.rb', line 15

def extension_dependencies
  @extension_dependencies
end

#extension_pathsObject

Returns the value of attribute extension_paths.



12
13
14
# File 'lib/radiant/initializer.rb', line 12

def extension_paths
  @extension_paths
end

#extensionsObject



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

def extensions
  @extensions ||= all_available_extensions
end

#view_pathsObject

Returns the value of attribute view_paths.



14
15
16
# File 'lib/radiant/initializer.rb', line 14

def view_paths
  @view_paths
end

Instance Method Details

#all_available_extensionsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/radiant/initializer.rb', line 44

def all_available_extensions
  # TODO: FIX
  return Rails.application.railties.engines.select { |e| e.is_a? Radiant::Extension }

  # load vendorized extensions by inspecting load path(s)
  all = extension_paths.map do |path|
    Dir["#{path}/*"].select {|f| File.directory?(f) }
  end
  # load any gem that follows extension rules
  gems.inject(all) do |available,gem|
    available << gem.specification.full_gem_path if gem.specification and
      gem.specification.full_gem_path[/radiant-.*-extension-[\d\.]+$/]
    available
  end
  # strip version info to glean proper extension names
  all.flatten.map {|f| File.basename(f).gsub(/^radiant-|-extension-[\d\.]+$/, '') }.sort.map {|e| e.to_sym }
end

#check_extension_dependenciesObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/radiant/initializer.rb', line 72

def check_extension_dependencies
  unloaded_extensions = []
  @extension_dependencies.each do |ext|
    extension = ext.camelcase + 'Extension'
    begin
      extension_class = extension.constantize
      unloaded_extensions << extension unless defined?(extension_class) && (extension_class.active?)
    rescue NameError
      unloaded_extensions << extension
    end
  end
  if unloaded_extensions.any?
    abort <<-end_error
Missing these required extensions:
#{unloaded_extensions}
end_error
  else
    return true
  end
end

#default_extension_pathsObject



24
25
26
27
28
29
30
31
# File 'lib/radiant/initializer.rb', line 24

def default_extension_paths
  env = ENV["RAILS_ENV"] || RAILS_ENV
  paths = [RAILS_ROOT + '/vendor/extensions', RADIANT_ROOT + '/vendor/extensions'].uniq
  # There's no other way it will work, config/environments/test.rb loads too late
  # TODO: Should figure out how to include this extension path only for the tests that need it
  paths.unshift(RADIANT_ROOT + "/test/fixtures/extensions") if env == "test"
  paths
end

#default_plugin_locatorsObject



33
34
35
36
37
38
# File 'lib/radiant/initializer.rb', line 33

def default_plugin_locators
  locators = []
  locators << Radiant::ExtensionLocator if defined? Gem
  locators << Radiant::GemLocator if defined? Gem
  locators << Rails::Plugin::FileSystemLocator
end

#extension(ext) ⇒ Object



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

def extension(ext)
  ::ActiveSupport::Deprecation.warn("Extension dependencies have been deprecated. Extensions may be packaged as gems and use the Gem spec to declare dependencies.", caller)
  @extension_dependencies << ext unless @extension_dependencies.include?(ext)
end

#gem(name, options = {}) ⇒ Object



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

def gem(name, options = {})
  super
  extensions << $1.intern if gems.last.name =~ /^radiant-(.*)-extension$/
end

#initializeObject



17
18
19
20
21
22
# File 'lib/radiant/initializer.rb', line 17

def initialize
  self.view_paths = []
  self.extension_paths = default_extension_paths
  self.extension_dependencies = []
  super
end