mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 19:33:44 +08:00
FEATURE: Allow plugins to dynamically add seed fixture paths
This is useful if your plugin wants different seed data for different locales for example.
This commit is contained in:
parent
3d145a588f
commit
966c7e7f07
|
@ -64,6 +64,10 @@ class DiscoursePluginRegistry
|
|||
@html_builders ||= {}
|
||||
end
|
||||
|
||||
def seed_path_builders
|
||||
@seed_path_builders ||= Set.new
|
||||
end
|
||||
|
||||
def vendored_pretty_text
|
||||
@vendored_pretty_text ||= Set.new
|
||||
end
|
||||
|
@ -136,6 +140,10 @@ class DiscoursePluginRegistry
|
|||
self.seed_data[key] = value
|
||||
end
|
||||
|
||||
def self.register_seed_path_builder(&block)
|
||||
seed_path_builders << block
|
||||
end
|
||||
|
||||
def self.register_html_builder(name, &block)
|
||||
html_builders[name] ||= []
|
||||
html_builders[name] << block
|
||||
|
@ -146,6 +154,14 @@ class DiscoursePluginRegistry
|
|||
builders.map { |b| b.call(ctx) }.join("\n").html_safe
|
||||
end
|
||||
|
||||
def self.seed_paths
|
||||
result = SeedFu.fixture_paths.dup
|
||||
unless Rails.env.test? && ENV['LOAD_PLUGINS'] != "1"
|
||||
seed_path_builders.each { |b| result += b.call }
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def javascripts
|
||||
self.class.javascripts
|
||||
end
|
||||
|
@ -190,6 +206,7 @@ class DiscoursePluginRegistry
|
|||
asset_globs.clear
|
||||
html_builders.clear
|
||||
vendored_pretty_text.clear
|
||||
seed_path_builders.clear
|
||||
end
|
||||
|
||||
def self.setup(plugin_class)
|
||||
|
|
|
@ -340,6 +340,10 @@ class Plugin::Instance
|
|||
seed_data[key] = value
|
||||
end
|
||||
|
||||
def register_seed_path_builder(&block)
|
||||
DiscoursePluginRegistry.register_seed_path_builder(&block)
|
||||
end
|
||||
|
||||
def register_emoji(name, url)
|
||||
Plugin::CustomEmoji.register(name, url)
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ end
|
|||
|
||||
# we need to run seed_fu every time we run rails db:migrate
|
||||
task 'db:migrate', [:multisite] => ['environment', 'set_locale'] do |_, args|
|
||||
SeedFu.seed
|
||||
SeedFu.seed(DiscoursePluginRegistry.seed_paths)
|
||||
Jobs::Onceoff.enqueue_all
|
||||
|
||||
if Rails.env.test? && !args[:multisite]
|
||||
|
@ -39,7 +39,7 @@ end
|
|||
|
||||
task 'test:prepare' => 'environment' do
|
||||
I18n.locale = SiteSetting.default_locale rescue :en
|
||||
SeedFu.seed
|
||||
SeedFu.seed(DiscoursePluginRegistry.seed_paths)
|
||||
end
|
||||
|
||||
task 'db:api_test_seed' => 'environment' do
|
||||
|
|
Loading…
Reference in New Issue
Block a user