FEATURE: adds support for loading existing core asset in pretty text
This commit is contained in:
parent
867f327055
commit
45f657336e
|
@ -82,6 +82,9 @@ class DiscoursePluginRegistry
|
||||||
@vendored_pretty_text ||= Set.new
|
@vendored_pretty_text ||= Set.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def vendored_core_pretty_text
|
||||||
|
@vendored_core_pretty_text ||= Set.new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def register_js(filename, options = {})
|
def register_js(filename, options = {})
|
||||||
|
@ -136,6 +139,8 @@ class DiscoursePluginRegistry
|
||||||
self.admin_javascripts << asset
|
self.admin_javascripts << asset
|
||||||
elsif opts == :vendored_pretty_text
|
elsif opts == :vendored_pretty_text
|
||||||
self.vendored_pretty_text << asset
|
self.vendored_pretty_text << asset
|
||||||
|
elsif opts == :vendored_core_pretty_text
|
||||||
|
self.vendored_core_pretty_text << asset
|
||||||
else
|
else
|
||||||
self.javascripts << asset
|
self.javascripts << asset
|
||||||
end
|
end
|
||||||
|
@ -180,6 +185,15 @@ class DiscoursePluginRegistry
|
||||||
result.uniq
|
result.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
|
VENDORED_CORE_PRETTY_TEXT_MAP = {
|
||||||
|
"moment.js" => "lib/javascripts/moment.js"
|
||||||
|
}
|
||||||
|
def self.core_asset_for_name(name)
|
||||||
|
asset = VENDORED_CORE_PRETTY_TEXT_MAP[name]
|
||||||
|
raise KeyError, "Asset #{name} not found in #{VENDORED_CORE_PRETTY_TEXT_MAP}" unless asset
|
||||||
|
asset
|
||||||
|
end
|
||||||
|
|
||||||
def locales
|
def locales
|
||||||
self.class.locales
|
self.class.locales
|
||||||
end
|
end
|
||||||
|
@ -235,6 +249,7 @@ class DiscoursePluginRegistry
|
||||||
asset_globs.clear
|
asset_globs.clear
|
||||||
html_builders.clear
|
html_builders.clear
|
||||||
vendored_pretty_text.clear
|
vendored_pretty_text.clear
|
||||||
|
vendored_core_pretty_text.clear
|
||||||
seed_path_builders.clear
|
seed_path_builders.clear
|
||||||
locales.clear
|
locales.clear
|
||||||
end
|
end
|
||||||
|
|
|
@ -338,7 +338,12 @@ class Plugin::Instance
|
||||||
end
|
end
|
||||||
|
|
||||||
def register_asset(file, opts = nil)
|
def register_asset(file, opts = nil)
|
||||||
|
if opts && opts == :vendored_core_pretty_text
|
||||||
|
full_path = DiscoursePluginRegistry.core_asset_for_name(file)
|
||||||
|
else
|
||||||
full_path = File.dirname(path) << "/assets/" << file
|
full_path = File.dirname(path) << "/assets/" << file
|
||||||
|
end
|
||||||
|
|
||||||
assets << [full_path, opts]
|
assets << [full_path, opts]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -506,6 +511,7 @@ JS
|
||||||
|
|
||||||
def javascript_includes
|
def javascript_includes
|
||||||
assets.map do |asset, opts|
|
assets.map do |asset, opts|
|
||||||
|
next if opts == :vendored_core_pretty_text
|
||||||
next if opts == :admin
|
next if opts == :admin
|
||||||
next unless asset =~ DiscoursePluginRegistry::JS_REGEX
|
next unless asset =~ DiscoursePluginRegistry::JS_REGEX
|
||||||
asset
|
asset
|
||||||
|
|
|
@ -101,6 +101,10 @@ module PrettyText
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
DiscoursePluginRegistry.vendored_core_pretty_text.each do |vpt|
|
||||||
|
ctx.eval(File.read(vpt))
|
||||||
|
end
|
||||||
|
|
||||||
DiscoursePluginRegistry.vendored_pretty_text.each do |vpt|
|
DiscoursePluginRegistry.vendored_pretty_text.each do |vpt|
|
||||||
ctx.eval(File.read(vpt))
|
ctx.eval(File.read(vpt))
|
||||||
end
|
end
|
||||||
|
|
|
@ -168,6 +168,13 @@ describe DiscoursePluginRegistry do
|
||||||
expect(registry.admin_javascripts.count).to eq(1)
|
expect(registry.admin_javascripts.count).to eq(1)
|
||||||
expect(registry.javascripts.count).to eq(0)
|
expect(registry.javascripts.count).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "registers vendored_core_pretty_text properly" do
|
||||||
|
registry.register_asset("my_lib.js", :vendored_core_pretty_text)
|
||||||
|
|
||||||
|
expect(registry.vendored_core_pretty_text.count).to eq(1)
|
||||||
|
expect(registry.javascripts.count).to eq(0)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context '#register_seed_data' do
|
context '#register_seed_data' do
|
||||||
|
|
|
@ -93,6 +93,15 @@ describe Plugin::Instance do
|
||||||
expect(DiscoursePluginRegistry.mobile_stylesheets.count).to eq(0)
|
expect(DiscoursePluginRegistry.mobile_stylesheets.count).to eq(0)
|
||||||
expect(DiscoursePluginRegistry.stylesheets.count).to eq(2)
|
expect(DiscoursePluginRegistry.stylesheets.count).to eq(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "remaps vendored_core_pretty_text asset" do
|
||||||
|
plugin = Plugin::Instance.new nil, "/tmp/test.rb"
|
||||||
|
plugin.register_asset("moment.js", :vendored_core_pretty_text)
|
||||||
|
|
||||||
|
plugin.send :register_assets!
|
||||||
|
|
||||||
|
expect(DiscoursePluginRegistry.vendored_core_pretty_text.first).to eq("lib/javascripts/moment.js")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "register service worker" do
|
context "register service worker" do
|
||||||
|
|
Loading…
Reference in New Issue