mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
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
4 changed files with 57 additions and 3 deletions
|
@ -54,6 +54,15 @@ if seed_welcome_topics
|
||||||
post.topic.update_pinned(true)
|
post.topic.update_pinned(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
welcome = File.read(Rails.root + 'docs/ADMIN-QUICK-START-GUIDE.md')
|
filename = DiscoursePluginRegistry.seed_data["admin_quick_start_filename"]
|
||||||
PostCreator.create(Discourse.system_user, raw: welcome, title: "READ ME FIRST: Admin Quick Start Guide", skip_validations: true, category: staff ? staff.name : nil)
|
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
|
end
|
||||||
|
|
|
@ -13,6 +13,7 @@ class DiscoursePluginRegistry
|
||||||
attr_writer :sass_variables
|
attr_writer :sass_variables
|
||||||
attr_writer :handlebars
|
attr_writer :handlebars
|
||||||
attr_writer :serialized_current_user_fields
|
attr_writer :serialized_current_user_fields
|
||||||
|
attr_writer :seed_data
|
||||||
|
|
||||||
attr_accessor :custom_html
|
attr_accessor :custom_html
|
||||||
|
|
||||||
|
@ -56,6 +57,10 @@ class DiscoursePluginRegistry
|
||||||
def serialized_current_user_fields
|
def serialized_current_user_fields
|
||||||
@serialized_current_user_fields ||= Set.new
|
@serialized_current_user_fields ||= Set.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def seed_data
|
||||||
|
@seed_data ||= HashWithIndifferentAccess.new({})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def register_js(filename, options={})
|
def register_js(filename, options={})
|
||||||
|
@ -104,6 +109,10 @@ class DiscoursePluginRegistry
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.register_seed_data(key, value)
|
||||||
|
self.seed_data[key] = value
|
||||||
|
end
|
||||||
|
|
||||||
def javascripts
|
def javascripts
|
||||||
self.class.javascripts
|
self.class.javascripts
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,6 +17,10 @@ class Plugin::Instance
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def seed_data
|
||||||
|
@seed_data ||= {}
|
||||||
|
end
|
||||||
|
|
||||||
def self.find_all(parent_path)
|
def self.find_all(parent_path)
|
||||||
[].tap { |plugins|
|
[].tap { |plugins|
|
||||||
# also follows symlinks - http://stackoverflow.com/q/357754
|
# also follows symlinks - http://stackoverflow.com/q/357754
|
||||||
|
@ -168,6 +172,10 @@ class Plugin::Instance
|
||||||
color_schemes << {name: name, colors: colors}
|
color_schemes << {name: name, colors: colors}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def register_seed_data(key, value)
|
||||||
|
seed_data[key] = value
|
||||||
|
end
|
||||||
|
|
||||||
def automatic_assets
|
def automatic_assets
|
||||||
css = styles.join("\n")
|
css = styles.join("\n")
|
||||||
js = javascripts.join("\n")
|
js = javascripts.join("\n")
|
||||||
|
@ -224,6 +232,10 @@ class Plugin::Instance
|
||||||
|
|
||||||
register_assets! unless assets.blank?
|
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
|
# TODO: possibly amend this to a rails engine
|
||||||
|
|
||||||
# Automatically include assets
|
# Automatically include assets
|
||||||
|
|
|
@ -43,6 +43,14 @@ describe DiscoursePluginRegistry do
|
||||||
end
|
end
|
||||||
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
|
context '.register_css' do
|
||||||
before do
|
before do
|
||||||
registry_instance.register_css('hello.css')
|
registry_instance.register_css('hello.css')
|
||||||
|
@ -143,4 +151,20 @@ describe DiscoursePluginRegistry do
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue