Merge pull request #2244 from vikhyat/css-import

Site Customization @import fixes
This commit is contained in:
Sam
2014-04-10 07:01:34 +10:00
11 changed files with 61 additions and 41 deletions

View File

@@ -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";

View File

@@ -1,2 +1,5 @@
@import "common";
@import "mobile/*";
/* This file doesn't actually exist, it is injected by DiscourseSassImporter. */
@import "plugins_mobile";

View File

@@ -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
%>

View File

@@ -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
%>

View File

@@ -14,12 +14,26 @@ class SiteCustomization < ActiveRecord::Base
end
def compile_stylesheet(scss)
# Get the sprockets environment. In production Rails.application.assets is a
# Sprockets::Index instead of Sprockets::Environment, there is no cleaner way
# to get the environment from the index.
env = Rails.application.assets
if env.is_a?(Sprockets::Index)
env = env.instance_variable_get('@environment')
end
context = env.context_class.new(env, "custom.scss", "app/assets/stylesheets/custom.scss")
::Sass::Engine.new(scss, {
syntax: :scss,
cache: false,
read_cache: false,
style: :compressed,
filesystem_importer: DiscourseSassImporter
filesystem_importer: DiscourseSassImporter,
sprockets: {
context: context,
environment: context.environment
}
}).render
rescue => e

View File

@@ -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 %>