mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 18:22:40 +08:00
BUGFIX: default should register CSS for both mobile and desktop
If you want desktop only use :desktop option
This commit is contained in:
@ -5,8 +5,7 @@ require_dependency 'plugin/auth_provider'
|
||||
|
||||
class Plugin::Instance
|
||||
|
||||
attr_reader :auth_providers, :assets, :admin_javascripts,
|
||||
:server_side_javascripts, :styles, :mobile_styles
|
||||
attr_reader :auth_providers, :assets, :styles
|
||||
attr_accessor :path, :metadata
|
||||
|
||||
def self.find_all(parent_path)
|
||||
@ -96,19 +95,7 @@ class Plugin::Instance
|
||||
|
||||
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
|
||||
if opts == :server_side
|
||||
@server_side_javascripts ||= []
|
||||
@server_side_javascripts << full_path
|
||||
end
|
||||
assets << [full_path, opts]
|
||||
end
|
||||
|
||||
def automatic_assets
|
||||
@ -152,47 +139,22 @@ class Plugin::Instance
|
||||
|
||||
end
|
||||
|
||||
|
||||
# note, we need to be able to parse seperately to activation.
|
||||
# this allows us to present information about a plugin in the UI
|
||||
# prior to activations
|
||||
def activate!
|
||||
self.instance_eval File.read(path), path
|
||||
if auto_assets = generate_automatic_assets!
|
||||
assets.concat auto_assets
|
||||
assets.concat auto_assets.map{|a| [a]}
|
||||
end
|
||||
unless assets.blank?
|
||||
assets.each do |asset|
|
||||
if asset =~ /\.js$|\.js\.erb$/
|
||||
DiscoursePluginRegistry.javascripts << asset
|
||||
elsif asset =~ /\.css$|\.scss$/
|
||||
DiscoursePluginRegistry.stylesheets << asset
|
||||
elsif asset =~ /\.js\.handlebars$/
|
||||
DiscoursePluginRegistry.handlebars << asset
|
||||
end
|
||||
end
|
||||
|
||||
register_assets!
|
||||
# TODO possibly amend this to a rails engine
|
||||
Rails.configuration.assets.paths << auto_generated_path
|
||||
Rails.configuration.assets.paths << File.dirname(path) + "/assets"
|
||||
end
|
||||
|
||||
if @admin_javascripts
|
||||
@admin_javascripts.each do |js|
|
||||
DiscoursePluginRegistry.admin_javascripts << js
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
public_data = File.dirname(path) + "/public"
|
||||
if Dir.exists?(public_data)
|
||||
@ -205,6 +167,7 @@ class Plugin::Instance
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def auth_provider(opts)
|
||||
@auth_providers ||= []
|
||||
provider = Plugin::AuthProvider.new
|
||||
@ -245,4 +208,32 @@ class Plugin::Instance
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def register_assets!
|
||||
assets.each do |asset, opts|
|
||||
if asset =~ /\.js$|\.js\.erb$/
|
||||
if opts == :admin
|
||||
DiscoursePluginRegistry.admin_javascripts << asset
|
||||
else
|
||||
if opts == :server_side
|
||||
DiscoursePluginRegistry.server_side_javascripts << asset
|
||||
end
|
||||
DiscoursePluginRegistry.javascripts << asset
|
||||
end
|
||||
elsif asset =~ /\.css$|\.scss$/
|
||||
|
||||
unless opts == :mobile
|
||||
DiscoursePluginRegistry.stylesheets << asset
|
||||
end
|
||||
unless opts == :desktop
|
||||
DiscoursePluginRegistry.mobile_stylesheets << asset
|
||||
end
|
||||
|
||||
elsif asset =~ /\.js\.handlebars$/
|
||||
DiscoursePluginRegistry.handlebars << asset
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user