FEATURE: plugins can register a custom admin quick start topic that will be seeded into new sites
This commit is contained in:
parent
803083fc2e
commit
f1637fc11e
|
@ -54,6 +54,15 @@ if seed_welcome_topics
|
|||
post.topic.update_pinned(true)
|
||||
end
|
||||
|
||||
welcome = File.read(Rails.root + 'docs/ADMIN-QUICK-START-GUIDE.md')
|
||||
PostCreator.create(Discourse.system_user, raw: welcome, title: "READ ME FIRST: Admin Quick Start Guide", skip_validations: true, category: staff ? staff.name : nil)
|
||||
filename = DiscoursePluginRegistry.seed_data["admin_quick_start_filename"]
|
||||
if filename.nil? || !File.exists?(filename)
|
||||
filename = Rails.root + 'docs/ADMIN-QUICK-START-GUIDE.md'
|
||||
end
|
||||
|
||||
welcome = File.read(filename)
|
||||
PostCreator.create( Discourse.system_user,
|
||||
raw: welcome,
|
||||
title: DiscoursePluginRegistry.seed_data["admin_quick_start_title"] || "READ ME FIRST: Admin Quick Start Guide",
|
||||
skip_validations: true,
|
||||
category: staff ? staff.name : nil)
|
||||
end
|
||||
|
|
|
@ -13,6 +13,7 @@ class DiscoursePluginRegistry
|
|||
attr_writer :sass_variables
|
||||
attr_writer :handlebars
|
||||
attr_writer :serialized_current_user_fields
|
||||
attr_writer :seed_data
|
||||
|
||||
attr_accessor :custom_html
|
||||
|
||||
|
@ -56,6 +57,10 @@ class DiscoursePluginRegistry
|
|||
def serialized_current_user_fields
|
||||
@serialized_current_user_fields ||= Set.new
|
||||
end
|
||||
|
||||
def seed_data
|
||||
@seed_data ||= HashWithIndifferentAccess.new({})
|
||||
end
|
||||
end
|
||||
|
||||
def register_js(filename, options={})
|
||||
|
@ -104,6 +109,10 @@ class DiscoursePluginRegistry
|
|||
end
|
||||
end
|
||||
|
||||
def self.register_seed_data(key, value)
|
||||
self.seed_data[key] = value
|
||||
end
|
||||
|
||||
def javascripts
|
||||
self.class.javascripts
|
||||
end
|
||||
|
|
|
@ -17,6 +17,10 @@ class Plugin::Instance
|
|||
}
|
||||
end
|
||||
|
||||
def seed_data
|
||||
@seed_data ||= {}
|
||||
end
|
||||
|
||||
def self.find_all(parent_path)
|
||||
[].tap { |plugins|
|
||||
# also follows symlinks - http://stackoverflow.com/q/357754
|
||||
|
@ -168,6 +172,10 @@ class Plugin::Instance
|
|||
color_schemes << {name: name, colors: colors}
|
||||
end
|
||||
|
||||
def register_seed_data(key, value)
|
||||
seed_data[key] = value
|
||||
end
|
||||
|
||||
def automatic_assets
|
||||
css = styles.join("\n")
|
||||
js = javascripts.join("\n")
|
||||
|
@ -224,6 +232,10 @@ class Plugin::Instance
|
|||
|
||||
register_assets! unless assets.blank?
|
||||
|
||||
seed_data.each do |key, value|
|
||||
DiscoursePluginRegistry.register_seed_data(key, value)
|
||||
end
|
||||
|
||||
# TODO: possibly amend this to a rails engine
|
||||
|
||||
# Automatically include assets
|
||||
|
|
|
@ -43,6 +43,14 @@ describe DiscoursePluginRegistry do
|
|||
end
|
||||
end
|
||||
|
||||
context '#seed_data' do
|
||||
it 'defaults to an empty Set' do
|
||||
registry.seed_data = nil
|
||||
expect(registry.seed_data).to be_a(Hash)
|
||||
expect(registry.seed_data.size).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context '.register_css' do
|
||||
before do
|
||||
registry_instance.register_css('hello.css')
|
||||
|
@ -143,4 +151,20 @@ describe DiscoursePluginRegistry do
|
|||
end
|
||||
end
|
||||
|
||||
context '#register_seed_data' do
|
||||
let(:registry) { DiscoursePluginRegistry }
|
||||
|
||||
after do
|
||||
registry.reset!
|
||||
end
|
||||
|
||||
it "registers seed data properly" do
|
||||
registry.register_seed_data("admin_quick_start_title", "Banana Hosting: Quick Start Guide")
|
||||
registry.register_seed_data("admin_quick_start_filename", File.expand_path("../docs/BANANA-QUICK-START.md", __FILE__))
|
||||
|
||||
expect(registry.seed_data["admin_quick_start_title"]).to eq("Banana Hosting: Quick Start Guide")
|
||||
expect(registry.seed_data["admin_quick_start_filename"]).to eq(File.expand_path("../docs/BANANA-QUICK-START.md", __FILE__))
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue