mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Always use DiscourseSassImporter, add optional sprockets deps tracking.
This commit is contained in:
parent
ce4f87e461
commit
8c129e480a
4 changed files with 25 additions and 4 deletions
|
@ -32,7 +32,7 @@ class SiteCustomization < ActiveRecord::Base
|
|||
filesystem_importer: DiscourseSassImporter,
|
||||
sprockets: {
|
||||
context: context,
|
||||
environment: env
|
||||
environment: context.environment
|
||||
}
|
||||
}).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
|
||||
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
|
||||
|
@ -48,6 +52,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 +67,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
|
||||
|
||||
|
|
Loading…
Reference in a new issue