Allow plugins to ship custom styles only for mobile

- adds another :mobile-flag to register_assets
- adds test for plugin registering of assets
- load plugins when on desktop and plugins_mobile when on mobile
This commit is contained in:
Benjamin Kampmann
2014-04-07 16:33:35 +02:00
parent 4a2438edc3
commit d22df7731d
7 changed files with 97 additions and 5 deletions

View File

@ -5,7 +5,8 @@ require_dependency 'plugin/auth_provider'
class Plugin::Instance
attr_reader :auth_providers, :assets
attr_reader :auth_providers, :assets, :admin_javascripts,
:server_side_javascripts, :styles, :mobile_styles
attr_accessor :path, :metadata
def self.find_all(parent_path)
@ -93,11 +94,14 @@ class Plugin::Instance
@javascripts << js
end
def register_asset(file,opts=nil)
def register_asset(file, opts=nil)
full_path = File.dirname(path) << "/assets/" << file
if opts == :admin
@admin_javascripts ||= []
@admin_javascripts << full_path
elsif opts == :mobile
@mobile_styles ||= []
@mobile_styles << full_path
else
assets << full_path
end
@ -178,6 +182,12 @@ class Plugin::Instance
end
end
if @mobile_styles
@mobile_styles.each do |style|
DiscoursePluginRegistry.mobile_stylesheets << style
end
end
if @server_side_javascripts
@server_side_javascripts.each do |js|
DiscoursePluginRegistry.server_side_javascripts << js