From 33307a50b3315efb2c771a8290db36411aba3f2d Mon Sep 17 00:00:00 2001 From: Vikhyat Korrapati Date: Wed, 9 Apr 2014 19:36:42 +0530 Subject: [PATCH] Get rid of plugins.css, inject it using DiscourseSassImporter. --- app/assets/stylesheets/common.scss | 3 +++ app/assets/stylesheets/mobile.scss | 3 +++ app/assets/stylesheets/plugins.css.erb | 7 ------- app/assets/stylesheets/plugins_mobile.css.erb | 7 ------- app/views/common/_discourse_stylesheet.html.erb | 2 -- config/application.rb | 2 +- lib/discourse_sass_importer.rb | 15 ++++++++++++++- 7 files changed, 21 insertions(+), 18 deletions(-) delete mode 100644 app/assets/stylesheets/plugins.css.erb delete mode 100644 app/assets/stylesheets/plugins_mobile.css.erb diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index 521f0aa0a..69064e175 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -8,3 +8,6 @@ @import "common/components/*"; @import "common/admin/*"; @import "common/input_tip"; + +/* This file doesn't actually exist, it is injected by DiscourseSassImporter. */ +@import "plugins"; diff --git a/app/assets/stylesheets/mobile.scss b/app/assets/stylesheets/mobile.scss index df2a08dc5..1c9951094 100644 --- a/app/assets/stylesheets/mobile.scss +++ b/app/assets/stylesheets/mobile.scss @@ -1,2 +1,5 @@ @import "common"; @import "mobile/*"; + +/* This file doesn't actually exist, it is injected by DiscourseSassImporter. */ +@import "plugins_mobile"; diff --git a/app/assets/stylesheets/plugins.css.erb b/app/assets/stylesheets/plugins.css.erb deleted file mode 100644 index 4068ef5a0..000000000 --- a/app/assets/stylesheets/plugins.css.erb +++ /dev/null @@ -1,7 +0,0 @@ -<% - # TODO this is very tricky, we want to add a dependency here on files that may not yet exist - # otherwise in dev we are often stuck nuking the tmp/cache directory - DiscoursePluginRegistry.stylesheets.each do |css| - require_asset(css) - end -%> diff --git a/app/assets/stylesheets/plugins_mobile.css.erb b/app/assets/stylesheets/plugins_mobile.css.erb deleted file mode 100644 index 3798373d0..000000000 --- a/app/assets/stylesheets/plugins_mobile.css.erb +++ /dev/null @@ -1,7 +0,0 @@ -<% - # TODO this is very tricky, we want to add a dependency here on files that may not yet exist - # otherwise in dev we are often stuck nuking the tmp/cache directory - DiscoursePluginRegistry.mobile_stylesheets.each do |css| - require_asset(css) - end -%> diff --git a/app/views/common/_discourse_stylesheet.html.erb b/app/views/common/_discourse_stylesheet.html.erb index 957cc1541..b7cc1d523 100644 --- a/app/views/common/_discourse_stylesheet.html.erb +++ b/app/views/common/_discourse_stylesheet.html.erb @@ -1,10 +1,8 @@ <%- unless SiteCustomization.override_default_style(session[:preview_style]) %> <% if mobile_view? %> <%= stylesheet_link_tag "mobile" %> - <%= stylesheet_link_tag "plugins_mobile" %> <% else %> <%= stylesheet_link_tag "desktop" %> - <%= stylesheet_link_tag "plugins" %> <% end %> <%- end %> diff --git a/config/application.rb b/config/application.rb index 80f779972..ab2f4252a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -68,7 +68,7 @@ module Discourse path =~ /assets\/images/ && !%w(.js .css).include?(File.extname(filename)) end] - config.assets.precompile += ['vendor.js', 'common.css', 'desktop.css', 'mobile.css', 'admin.js', 'admin.css', 'shiny/shiny.css', 'preload_store.js', 'browser-update.js', 'embed.css', 'break_string.js', 'plugins.css', 'plugins_mobile.css'] + config.assets.precompile += ['vendor.js', 'common.css', 'desktop.css', 'mobile.css', 'admin.js', 'admin.css', 'shiny/shiny.css', 'preload_store.js', 'browser-update.js', 'embed.css', 'break_string.js'] # Precompile all defer Dir.glob("#{config.root}/app/assets/javascripts/defer/*.js").each do |file| diff --git a/lib/discourse_sass_importer.rb b/lib/discourse_sass_importer.rb index 857d204ac..5c4bca4b3 100644 --- a/lib/discourse_sass_importer.rb +++ b/lib/discourse_sass_importer.rb @@ -35,7 +35,20 @@ class DiscourseSassImporter < Sass::Importers::Filesystem end def find(name, options) - if name =~ GLOB + if name == "plugins" || name == "plugins_mobile" + if name == "plugins" + stylesheets = DiscoursePluginRegistry.stylesheets + elsif name == "plugins_mobile" + stylesheets = DiscoursePluginRegistry.mobile_stylesheets + end + contents = "" + stylesheets.each {|css| contents << File.read(css) } + Sass::Engine.new(contents, options.merge( + filename: "#{name}.scss", + importer: self, + syntax: :scss + )) + elsif name =~ GLOB nil # globs must be relative else engine_from_path(name, root, options)