mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 11:48:26 -06:00
Always use DiscourseSassImporter, add optional sprockets deps tracking.
This commit is contained in:
parent
ce4f87e461
commit
8c129e480a
@ -32,7 +32,7 @@ class SiteCustomization < ActiveRecord::Base
|
|||||||
filesystem_importer: DiscourseSassImporter,
|
filesystem_importer: DiscourseSassImporter,
|
||||||
sprockets: {
|
sprockets: {
|
||||||
context: context,
|
context: context,
|
||||||
environment: env
|
environment: context.environment
|
||||||
}
|
}
|
||||||
}).render
|
}).render
|
||||||
|
|
||||||
|
4
config/initializers/sprockets.rb
Normal file
4
config/initializers/sprockets.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
require_dependency 'discourse_sass_importer'
|
||||||
|
|
||||||
|
Sprockets.send(:remove_const, :SassImporter)
|
||||||
|
Sprockets::SassImporter = DiscourseSassImporter
|
@ -4,7 +4,11 @@
|
|||||||
class DiscourseSassImporter < Sass::Importers::Filesystem
|
class DiscourseSassImporter < Sass::Importers::Filesystem
|
||||||
GLOB = /\*|\[.+\]/
|
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)
|
def initialize(*args)
|
||||||
|
@context = args.first unless args.first.is_a? String
|
||||||
@root = Rails.root.join('app', 'assets', 'stylesheets').to_s
|
@root = Rails.root.join('app', 'assets', 'stylesheets').to_s
|
||||||
@same_name_warnings = Set.new
|
@same_name_warnings = Set.new
|
||||||
end
|
end
|
||||||
@ -48,6 +52,7 @@ class DiscourseSassImporter < Sass::Importers::Filesystem
|
|||||||
def glob_imports(glob, base_pathname, options)
|
def glob_imports(glob, base_pathname, options)
|
||||||
contents = ""
|
contents = ""
|
||||||
each_globbed_file(glob, base_pathname.dirname, options) do |filename|
|
each_globbed_file(glob, base_pathname.dirname, options) do |filename|
|
||||||
|
depend_on(filename)
|
||||||
unless File.directory?(filename)
|
unless File.directory?(filename)
|
||||||
contents << "@import #{Pathname.new(filename).relative_path_from(base_pathname.dirname).to_s.inspect};\n"
|
contents << "@import #{Pathname.new(filename).relative_path_from(base_pathname.dirname).to_s.inspect};\n"
|
||||||
end
|
end
|
||||||
@ -62,6 +67,21 @@ class DiscourseSassImporter < Sass::Importers::Filesystem
|
|||||||
|
|
||||||
private
|
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)
|
def engine_from_path(name, dir, options)
|
||||||
full_filename, syntax = Sass::Util.destructure(find_real_file(dir, name, options))
|
full_filename, syntax = Sass::Util.destructure(find_real_file(dir, name, options))
|
||||||
return unless full_filename && File.readable?(full_filename)
|
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
|
# let's make precompile faster using redis magic
|
||||||
require 'sprockets'
|
require 'sprockets'
|
||||||
require 'digest/sha1'
|
require 'digest/sha1'
|
||||||
require_dependency 'discourse_sass_importer'
|
|
||||||
|
|
||||||
Sprockets::SassImporter = DiscourseSassImporter
|
|
||||||
|
|
||||||
module ::Sprockets
|
module ::Sprockets
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user