FIX: properly load desktop and mobile only plugin css assets.

5bd6b70d98
This commit is contained in:
Vinoth Kannan
2019-08-22 08:39:10 +05:30
parent 741d5bf541
commit 41f22946c3
4 changed files with 22 additions and 6 deletions

View File

@@ -12,6 +12,6 @@
<%= discourse_stylesheet_link_tag(mobile_view? ? :mobile_theme : :desktop_theme) %> <%= discourse_stylesheet_link_tag(mobile_view? ? :mobile_theme : :desktop_theme) %>
<%- end %> <%- end %>
<%- Discourse.find_plugin_css_assets(include_official: allow_plugins?, include_unofficial: allow_third_party_plugins?).each do |file| %> <%- Discourse.find_plugin_css_assets(include_official: allow_plugins?, include_unofficial: allow_third_party_plugins?, mobile_view: mobile_view?).each do |file| %>
<%= discourse_stylesheet_link_tag(file) %> <%= discourse_stylesheet_link_tag(file) %>
<%- end %> <%- end %>

View File

@@ -215,9 +215,18 @@ module Discourse
end end
def self.find_plugin_css_assets(args) def self.find_plugin_css_assets(args)
self.find_plugins(args).find_all do |plugin| plugins = self.find_plugins(args)
assets = plugins.find_all do |plugin|
plugin.css_asset_exists? plugin.css_asset_exists?
end.map { |plugin| plugin.directory_name } end.map { |plugin| plugin.directory_name }
target = args[:mobile_view] ? :mobile : :desktop
assets += plugins.find_all do |plugin|
plugin.css_asset_exists?(target)
end.map { |plugin| "#{plugin.directory_name}_#{target}" }
assets
end end
def self.find_plugin_js_assets(args) def self.find_plugin_js_assets(args)

View File

@@ -183,8 +183,15 @@ class DiscoursePluginRegistry
end end
end end
def self.stylesheets_exists?(plugin_directory_name) def self.stylesheets_exists?(plugin_directory_name, target = nil)
self.stylesheets[plugin_directory_name].present? || self.mobile_stylesheets[plugin_directory_name].present? || self.desktop_stylesheets[plugin_directory_name].present? case target
when :desktop
self.desktop_stylesheets[plugin_directory_name].present?
when :mobile
self.mobile_stylesheets[plugin_directory_name].present?
else
self.stylesheets[plugin_directory_name].present?
end
end end
def self.register_seed_data(key, value) def self.register_seed_data(key, value)

View File

@@ -658,8 +658,8 @@ class Plugin::Instance
@directory_name ||= File.dirname(path).split("/").last @directory_name ||= File.dirname(path).split("/").last
end end
def css_asset_exists? def css_asset_exists?(target = nil)
DiscoursePluginRegistry.stylesheets_exists?(directory_name) DiscoursePluginRegistry.stylesheets_exists?(directory_name, target)
end end
def js_asset_exists? def js_asset_exists?