mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Plugins can register providers for global settings
This commit is contained in:
parent
185dcb2ca1
commit
b60bc47a4c
@ -145,14 +145,14 @@ class GlobalSetting
|
|||||||
attr_accessor :provider
|
attr_accessor :provider
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.configure!
|
||||||
if Rails.env == "test"
|
if Rails.env == "test"
|
||||||
@provider = BlankProvider.new
|
@provider = BlankProvider.new
|
||||||
else
|
else
|
||||||
@provider =
|
@provider =
|
||||||
FileProvider.from(File.expand_path('../../../config/discourse.conf', __FILE__)) ||
|
FileProvider.from(File.expand_path('../../../config/discourse.conf', __FILE__)) ||
|
||||||
EnvProvider.new
|
EnvProvider.new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
load_defaults
|
|
||||||
end
|
end
|
||||||
|
@ -6,8 +6,15 @@ require_relative '../lib/discourse_event'
|
|||||||
require_relative '../lib/discourse_plugin'
|
require_relative '../lib/discourse_plugin'
|
||||||
require_relative '../lib/discourse_plugin_registry'
|
require_relative '../lib/discourse_plugin_registry'
|
||||||
|
|
||||||
|
require_relative '../lib/plugin_gem'
|
||||||
|
|
||||||
# Global config
|
# Global config
|
||||||
require_relative '../app/models/global_setting'
|
require_relative '../app/models/global_setting'
|
||||||
|
GlobalSetting.configure!
|
||||||
|
unless Rails.env.test? && ENV['LOAD_PLUGINS'] != "1"
|
||||||
|
require_relative '../lib/custom_setting_providers'
|
||||||
|
end
|
||||||
|
GlobalSetting.load_defaults
|
||||||
|
|
||||||
require 'pry-rails' if Rails.env.development?
|
require 'pry-rails' if Rails.env.development?
|
||||||
|
|
||||||
@ -15,8 +22,10 @@ if defined?(Bundler)
|
|||||||
Bundler.require(*Rails.groups(assets: %w(development test profile)))
|
Bundler.require(*Rails.groups(assets: %w(development test profile)))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
module Discourse
|
module Discourse
|
||||||
class Application < Rails::Application
|
class Application < Rails::Application
|
||||||
|
|
||||||
def config.database_configuration
|
def config.database_configuration
|
||||||
if Rails.env.production?
|
if Rails.env.production?
|
||||||
GlobalSetting.database_config
|
GlobalSetting.database_config
|
||||||
|
7
lib/custom_setting_providers.rb
Normal file
7
lib/custom_setting_providers.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# Support for plugins to register custom setting providers. They can do this
|
||||||
|
# by having a file, `register_provider.rb` in their root that will be run
|
||||||
|
# at this point.
|
||||||
|
|
||||||
|
Dir.glob(File.join(File.dirname(__FILE__), '../plugins', '*', "register_provider.rb")) do |p|
|
||||||
|
require p
|
||||||
|
end
|
@ -363,27 +363,7 @@ JS
|
|||||||
#
|
#
|
||||||
# This is a very rough initial implementation
|
# This is a very rough initial implementation
|
||||||
def gem(name, version, opts = {})
|
def gem(name, version, opts = {})
|
||||||
gems_path = File.dirname(path) + "/gems/#{RUBY_VERSION}"
|
PluginGem.load(path, name, version, opts)
|
||||||
spec_path = gems_path + "/specifications"
|
|
||||||
spec_file = spec_path + "/#{name}-#{version}.gemspec"
|
|
||||||
unless File.exists? spec_file
|
|
||||||
command = "gem install #{name} -v #{version} -i #{gems_path} --no-document --ignore-dependencies"
|
|
||||||
if opts[:source]
|
|
||||||
command << " --source #{opts[:source]}"
|
|
||||||
end
|
|
||||||
puts command
|
|
||||||
puts `#{command}`
|
|
||||||
end
|
|
||||||
if File.exists? spec_file
|
|
||||||
spec = Gem::Specification.load spec_file
|
|
||||||
spec.activate
|
|
||||||
unless opts[:require] == false
|
|
||||||
require opts[:require_name] ? opts[:require_name] : name
|
|
||||||
end
|
|
||||||
else
|
|
||||||
puts "You are specifying the gem #{name} in #{path}, however it does not exist!"
|
|
||||||
exit(-1)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def enabled_site_setting(setting=nil)
|
def enabled_site_setting(setting=nil)
|
||||||
|
27
lib/plugin_gem.rb
Normal file
27
lib/plugin_gem.rb
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
module PluginGem
|
||||||
|
def self.load(path, name, version, opts=nil)
|
||||||
|
opts ||= {}
|
||||||
|
|
||||||
|
gems_path = File.dirname(path) + "/gems/#{RUBY_VERSION}"
|
||||||
|
spec_path = gems_path + "/specifications"
|
||||||
|
spec_file = spec_path + "/#{name}-#{version}.gemspec"
|
||||||
|
unless File.exists? spec_file
|
||||||
|
command = "gem install #{name} -v #{version} -i #{gems_path} --no-document --ignore-dependencies"
|
||||||
|
if opts[:source]
|
||||||
|
command << " --source #{opts[:source]}"
|
||||||
|
end
|
||||||
|
puts command
|
||||||
|
puts `#{command}`
|
||||||
|
end
|
||||||
|
if File.exists? spec_file
|
||||||
|
spec = Gem::Specification.load spec_file
|
||||||
|
spec.activate
|
||||||
|
unless opts[:require] == false
|
||||||
|
require opts[:require_name] ? opts[:require_name] : name
|
||||||
|
end
|
||||||
|
else
|
||||||
|
puts "You are specifying the gem #{name} in #{path}, however it does not exist!"
|
||||||
|
exit(-1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user