Merge pull request #2244 from vikhyat/css-import
Site Customization @import fixes
This commit is contained in:
@@ -4,7 +4,11 @@
|
||||
class DiscourseSassImporter < Sass::Importers::Filesystem
|
||||
GLOB = /\*|\[.+\]/
|
||||
|
||||
# Depending upon where this is passed we might either be passed a string as the
|
||||
# first argument or a sprockets context. If the first argument is a sprockets
|
||||
# context we store it and use it to mark dependencies.
|
||||
def initialize(*args)
|
||||
@context = args.first unless args.first.is_a? String
|
||||
@root = Rails.root.join('app', 'assets', 'stylesheets').to_s
|
||||
@same_name_warnings = Set.new
|
||||
end
|
||||
@@ -31,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)
|
||||
@@ -48,6 +65,7 @@ class DiscourseSassImporter < Sass::Importers::Filesystem
|
||||
def glob_imports(glob, base_pathname, options)
|
||||
contents = ""
|
||||
each_globbed_file(glob, base_pathname.dirname, options) do |filename|
|
||||
depend_on(filename)
|
||||
unless File.directory?(filename)
|
||||
contents << "@import #{Pathname.new(filename).relative_path_from(base_pathname.dirname).to_s.inspect};\n"
|
||||
end
|
||||
@@ -62,6 +80,21 @@ class DiscourseSassImporter < Sass::Importers::Filesystem
|
||||
|
||||
private
|
||||
|
||||
def depend_on(filename)
|
||||
if @context
|
||||
@context.depend_on(filename)
|
||||
@context.depend_on(globbed_file_parent(filename))
|
||||
end
|
||||
end
|
||||
|
||||
def globbed_file_parent(filename)
|
||||
if File.directory?(filename)
|
||||
File.expand_path('..', filename)
|
||||
else
|
||||
File.dirname(filename)
|
||||
end
|
||||
end
|
||||
|
||||
def engine_from_path(name, dir, options)
|
||||
full_filename, syntax = Sass::Util.destructure(find_real_file(dir, name, options))
|
||||
return unless full_filename && File.readable?(full_filename)
|
||||
|
||||
@@ -16,9 +16,6 @@ task 'assets:precompile:before' do
|
||||
# let's make precompile faster using redis magic
|
||||
require 'sprockets'
|
||||
require 'digest/sha1'
|
||||
require_dependency 'discourse_sass_importer'
|
||||
|
||||
Sprockets::SassImporter = DiscourseSassImporter
|
||||
|
||||
module ::Sprockets
|
||||
|
||||
|
||||
Reference in New Issue
Block a user