mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 02:56:26 -05:00
Update sprockets. (#4167)
* Update sass-rails. * FIX: Tilt dependency has been removed from Ember::Handlebars::Template. * Update `DiscourseIIFE` to new Sprockets API. * `Rails.application.assets` returns `nil` in production. * Move sprockets-rails out of the assets group. * Pin ember-rails to 0.18.5 which works with Sprockets 3.x. * Update sprockets to 3.6.0. * Make `DiscourseSassCompiler` work with Sprockets 3. * Use `Sass::Rails::SassImporterGlobbing` instead of haxxing our own. * Moneky patch so that we don't add dependencies for our custom css. * FIX: Missing class. * Upgrade ember-handlebars-template. * FIX: require path needs to share the same root as the folder's path. * Bump discourse-qunit-rails. * Update ember-template-compiler.js to 1.12.2. * `prepend` is private in Ruby 2.0.0.
This commit is contained in:
parent
36e3f1f5e4
commit
256d7a00e9
17 changed files with 673 additions and 618 deletions
4
Gemfile
4
Gemfile
|
@ -47,7 +47,7 @@ gem 'onebox'
|
||||||
|
|
||||||
gem 'http_accept_language', '~>2.0.5', require: false
|
gem 'http_accept_language', '~>2.0.5', require: false
|
||||||
|
|
||||||
gem 'ember-rails'
|
gem 'ember-rails', '0.18.5'
|
||||||
gem 'ember-source', '1.12.2'
|
gem 'ember-source', '1.12.2'
|
||||||
gem 'barber'
|
gem 'barber'
|
||||||
gem 'babel-transpiler'
|
gem 'babel-transpiler'
|
||||||
|
@ -99,6 +99,7 @@ gem 'rest-client'
|
||||||
gem 'rinku'
|
gem 'rinku'
|
||||||
gem 'sanitize'
|
gem 'sanitize'
|
||||||
gem 'sass'
|
gem 'sass'
|
||||||
|
gem 'sass-rails'
|
||||||
gem 'sidekiq'
|
gem 'sidekiq'
|
||||||
gem 'sidekiq-statistic'
|
gem 'sidekiq-statistic'
|
||||||
|
|
||||||
|
@ -114,7 +115,6 @@ gem 'rack-protection' # security
|
||||||
# in production environments by default.
|
# in production environments by default.
|
||||||
# allow everywhere for now cause we are allowing asset debugging in prd
|
# allow everywhere for now cause we are allowing asset debugging in prd
|
||||||
group :assets do
|
group :assets do
|
||||||
gem 'sass-rails', '~> 4.0.5'
|
|
||||||
gem 'uglifier'
|
gem 'uglifier'
|
||||||
gem 'rtlit', require: false # for css rtling
|
gem 'rtlit', require: false # for css rtling
|
||||||
end
|
end
|
||||||
|
|
48
Gemfile.lock
48
Gemfile.lock
|
@ -52,8 +52,8 @@ GEM
|
||||||
babel-transpiler (0.7.0)
|
babel-transpiler (0.7.0)
|
||||||
babel-source (>= 4.0, < 6)
|
babel-source (>= 4.0, < 6)
|
||||||
execjs (~> 2.0)
|
execjs (~> 2.0)
|
||||||
barber (0.9.0)
|
barber (0.11.1)
|
||||||
ember-source (>= 1.0, < 2)
|
ember-source (>= 1.0, < 3)
|
||||||
execjs (>= 1.2, < 3)
|
execjs (>= 1.2, < 3)
|
||||||
better_errors (2.1.1)
|
better_errors (2.1.1)
|
||||||
coderay (>= 1.0.0)
|
coderay (>= 1.0.0)
|
||||||
|
@ -65,13 +65,13 @@ GEM
|
||||||
byebug (8.2.1)
|
byebug (8.2.1)
|
||||||
certified (1.0.0)
|
certified (1.0.0)
|
||||||
coderay (1.1.0)
|
coderay (1.1.0)
|
||||||
concurrent-ruby (1.0.0)
|
concurrent-ruby (1.0.1)
|
||||||
connection_pool (2.2.0)
|
connection_pool (2.2.0)
|
||||||
crass (1.0.2)
|
crass (1.0.2)
|
||||||
daemons (1.2.3)
|
daemons (1.2.3)
|
||||||
debug_inspector (0.0.2)
|
debug_inspector (0.0.2)
|
||||||
diff-lcs (1.2.5)
|
diff-lcs (1.2.5)
|
||||||
discourse-qunit-rails (0.0.8)
|
discourse-qunit-rails (0.0.9)
|
||||||
railties
|
railties
|
||||||
docile (1.1.5)
|
docile (1.1.5)
|
||||||
domain_name (0.5.25)
|
domain_name (0.5.25)
|
||||||
|
@ -79,10 +79,10 @@ GEM
|
||||||
email_reply_trimmer (0.1.3)
|
email_reply_trimmer (0.1.3)
|
||||||
ember-data-source (1.0.0.beta.16.1)
|
ember-data-source (1.0.0.beta.16.1)
|
||||||
ember-source (~> 1.8)
|
ember-source (~> 1.8)
|
||||||
ember-handlebars-template (0.1.5)
|
ember-handlebars-template (0.7.3)
|
||||||
barber (>= 0.9.0)
|
barber (>= 0.11.0)
|
||||||
sprockets (>= 2.1, < 3.1)
|
sprockets (>= 3.3, < 4)
|
||||||
ember-rails (0.18.2)
|
ember-rails (0.18.5)
|
||||||
active_model_serializers
|
active_model_serializers
|
||||||
ember-data-source (>= 1.0.0.beta.5)
|
ember-data-source (>= 1.0.0.beta.5)
|
||||||
ember-handlebars-template (>= 0.1.1, < 1.0)
|
ember-handlebars-template (>= 0.1.1, < 1.0)
|
||||||
|
@ -122,7 +122,6 @@ GEM
|
||||||
guess_html_encoding (0.0.11)
|
guess_html_encoding (0.0.11)
|
||||||
hashie (3.4.3)
|
hashie (3.4.3)
|
||||||
highline (1.7.8)
|
highline (1.7.8)
|
||||||
hike (1.2.3)
|
|
||||||
hiredis (0.6.1)
|
hiredis (0.6.1)
|
||||||
htmlentities (4.3.4)
|
htmlentities (4.3.4)
|
||||||
http-cookie (1.0.2)
|
http-cookie (1.0.2)
|
||||||
|
@ -330,11 +329,12 @@ GEM
|
||||||
nokogiri (>= 1.4.4)
|
nokogiri (>= 1.4.4)
|
||||||
nokogumbo (~> 1.4.1)
|
nokogumbo (~> 1.4.1)
|
||||||
sass (3.2.19)
|
sass (3.2.19)
|
||||||
sass-rails (4.0.5)
|
sass-rails (5.0.4)
|
||||||
railties (>= 4.0.0, < 5.0)
|
railties (>= 4.0.0, < 5.0)
|
||||||
sass (~> 3.2.0)
|
sass (~> 3.1)
|
||||||
sprockets (~> 2.8, <= 2.11.0)
|
sprockets (>= 2.8, < 4.0)
|
||||||
sprockets-rails (~> 2.0.0)
|
sprockets-rails (>= 2.0, < 4.0)
|
||||||
|
tilt (>= 1.1, < 3)
|
||||||
seed-fu (2.3.5)
|
seed-fu (2.3.5)
|
||||||
activerecord (>= 3.1, < 4.3)
|
activerecord (>= 3.1, < 4.3)
|
||||||
activesupport (>= 3.1, < 4.3)
|
activesupport (>= 3.1, < 4.3)
|
||||||
|
@ -366,15 +366,13 @@ GEM
|
||||||
spork-rails (4.0.0)
|
spork-rails (4.0.0)
|
||||||
rails (>= 3.0.0, < 5)
|
rails (>= 3.0.0, < 5)
|
||||||
spork (>= 1.0rc0)
|
spork (>= 1.0rc0)
|
||||||
sprockets (2.11.0)
|
sprockets (3.6.0)
|
||||||
hike (~> 1.2)
|
concurrent-ruby (~> 1.0)
|
||||||
multi_json (~> 1.0)
|
rack (> 1, < 3)
|
||||||
rack (~> 1.0)
|
sprockets-rails (3.0.4)
|
||||||
tilt (~> 1.1, != 1.3.0)
|
actionpack (>= 4.0)
|
||||||
sprockets-rails (2.0.1)
|
activesupport (>= 4.0)
|
||||||
actionpack (>= 3.0)
|
sprockets (>= 3.0.0)
|
||||||
activesupport (>= 3.0)
|
|
||||||
sprockets (~> 2.8)
|
|
||||||
stackprof (0.2.7)
|
stackprof (0.2.7)
|
||||||
therubyracer (0.12.2)
|
therubyracer (0.12.2)
|
||||||
libv8 (~> 3.16.14.0)
|
libv8 (~> 3.16.14.0)
|
||||||
|
@ -385,7 +383,7 @@ GEM
|
||||||
rack (~> 1.0)
|
rack (~> 1.0)
|
||||||
thor (0.19.1)
|
thor (0.19.1)
|
||||||
thread_safe (0.3.5)
|
thread_safe (0.3.5)
|
||||||
tilt (1.4.1)
|
tilt (2.0.2)
|
||||||
timecop (0.8.0)
|
timecop (0.8.0)
|
||||||
trollop (2.1.2)
|
trollop (2.1.2)
|
||||||
tzinfo (1.2.2)
|
tzinfo (1.2.2)
|
||||||
|
@ -416,7 +414,7 @@ DEPENDENCIES
|
||||||
certified
|
certified
|
||||||
discourse-qunit-rails
|
discourse-qunit-rails
|
||||||
email_reply_trimmer (= 0.1.3)
|
email_reply_trimmer (= 0.1.3)
|
||||||
ember-rails
|
ember-rails (= 0.18.5)
|
||||||
ember-source (= 1.12.2)
|
ember-source (= 1.12.2)
|
||||||
excon
|
excon
|
||||||
fabrication (= 2.9.8)
|
fabrication (= 2.9.8)
|
||||||
|
@ -485,7 +483,7 @@ DEPENDENCIES
|
||||||
ruby-readability
|
ruby-readability
|
||||||
sanitize
|
sanitize
|
||||||
sass
|
sass
|
||||||
sass-rails (~> 4.0.5)
|
sass-rails
|
||||||
seed-fu (~> 2.3.5)
|
seed-fu (~> 2.3.5)
|
||||||
shoulda
|
shoulda
|
||||||
sidekiq
|
sidekiq
|
||||||
|
|
|
@ -44,7 +44,7 @@ PLUGIN_API_JS
|
||||||
name = node["name"] || node["data-template-name"] || "broken"
|
name = node["name"] || node["data-template-name"] || "broken"
|
||||||
precompiled =
|
precompiled =
|
||||||
if name =~ /\.raw$/
|
if name =~ /\.raw$/
|
||||||
"Discourse.EmberCompatHandlebars.template(#{Barber::EmberCompatPrecompiler.compile(node.inner_html)})"
|
"Discourse.EmberCompatHandlebars.template(#{Barber::Precompiler.compile(node.inner_html)})"
|
||||||
else
|
else
|
||||||
"Ember.HTMLBars.template(#{Barber::Ember::Precompiler.compile(node.inner_html)})"
|
"Ember.HTMLBars.template(#{Barber::Ember::Precompiler.compile(node.inner_html)})"
|
||||||
end
|
end
|
||||||
|
|
|
@ -144,6 +144,7 @@ module Discourse
|
||||||
|
|
||||||
# Our templates shouldn't start with 'discourse/templates'
|
# Our templates shouldn't start with 'discourse/templates'
|
||||||
config.handlebars.templates_root = 'discourse/templates'
|
config.handlebars.templates_root = 'discourse/templates'
|
||||||
|
config.handlebars.raw_template_namespace = "Ember.TEMPLATES"
|
||||||
|
|
||||||
require 'discourse_redis'
|
require 'discourse_redis'
|
||||||
require 'logster/redis_store'
|
require 'logster/redis_store'
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
require 'discourse_iife'
|
require 'discourse_iife'
|
||||||
|
|
||||||
Rails.application.assets.register_preprocessor('application/javascript', DiscourseIIFE)
|
Rails.application.config.assets.configure do |env|
|
||||||
unless Rails.env.production? || ENV["DISABLE_EVAL"]
|
env.register_preprocessor('application/javascript', DiscourseIIFE)
|
||||||
require 'source_url'
|
|
||||||
Rails.application.assets.register_postprocessor('application/javascript', SourceURL)
|
unless Rails.env.production? || ENV["DISABLE_EVAL"]
|
||||||
|
require 'source_url'
|
||||||
|
env.register_postprocessor('application/javascript', SourceURL)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
Rails.application.assets.logger = Logger.new('/dev/null')
|
Rails.application.config.assets.configure do |env|
|
||||||
|
env.logger = Logger.new('/dev/null')
|
||||||
|
end
|
||||||
|
|
||||||
Rails::Rack::Logger.class_eval do
|
Rails::Rack::Logger.class_eval do
|
||||||
def call_with_quiet_assets(env)
|
def call_with_quiet_assets(env)
|
||||||
previous_level = Rails.logger.level
|
previous_level = Rails.logger.level
|
||||||
|
|
|
@ -2,20 +2,18 @@ require_dependency 'sass/discourse_stylesheets'
|
||||||
require_dependency 'sass/discourse_sass_importer'
|
require_dependency 'sass/discourse_sass_importer'
|
||||||
require_dependency 'sass/discourse_safe_sass_importer'
|
require_dependency 'sass/discourse_safe_sass_importer'
|
||||||
|
|
||||||
if defined?(Sass::Rails::SassTemplate)
|
DiscourseSassTemplate = Class.new(Sass::Rails::SassTemplate) do
|
||||||
DiscourseSassTemplate = Class.new(Sass::Rails::SassTemplate) do
|
def importer_class
|
||||||
def importer_class
|
DiscourseSassImporter
|
||||||
DiscourseSassImporter
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
DiscourseScssTemplate = Class.new(DiscourseSassTemplate) do
|
end
|
||||||
def syntax
|
DiscourseScssTemplate = Class.new(DiscourseSassTemplate) do
|
||||||
:scss
|
def syntax
|
||||||
end
|
:scss
|
||||||
end
|
end
|
||||||
Rails.application.assets.register_engine '.sass', DiscourseSassTemplate
|
end
|
||||||
Rails.application.assets.register_engine '.scss', DiscourseScssTemplate
|
|
||||||
else
|
Rails.application.config.assets.configure do |env|
|
||||||
Sprockets.send(:remove_const, :SassImporter)
|
env.register_engine '.sass', DiscourseSassTemplate
|
||||||
Sprockets::SassImporter = DiscourseSassImporter
|
env.register_engine '.scss', DiscourseScssTemplate
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,19 @@
|
||||||
class DiscourseIIFE < Sprockets::Processor
|
class DiscourseIIFE
|
||||||
|
def initialize(options = {}, &block)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.instance
|
||||||
|
@instance ||= new
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.call(input)
|
||||||
|
instance.call(input)
|
||||||
|
end
|
||||||
|
|
||||||
# Add a IIFE around our javascript
|
# Add a IIFE around our javascript
|
||||||
def evaluate(context, locals)
|
def call(input)
|
||||||
|
path = input[:environment].context_class.new(input).pathname.to_s
|
||||||
path = context.pathname.to_s
|
data = input[:data]
|
||||||
|
|
||||||
# Only discourse or admin paths
|
# Only discourse or admin paths
|
||||||
return data unless (path =~ /\/javascripts\/discourse/ || path =~ /\/javascripts\/admin/ || path =~ /\/test\/javascripts/)
|
return data unless (path =~ /\/javascripts\/discourse/ || path =~ /\/javascripts\/admin/ || path =~ /\/test\/javascripts/)
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
module Ember
|
module Ember
|
||||||
module Handlebars
|
module Handlebars
|
||||||
class Template < Tilt::Template
|
class Template
|
||||||
|
|
||||||
# Wrap in an IIFE in development mode to get the correct filename
|
# Wrap in an IIFE in development mode to get the correct filename
|
||||||
def compile_ember_handlebars(string, ember_template = 'Handlebars')
|
def compile_ember_handlebars(string, ember_template = 'Handlebars', options = nil)
|
||||||
if ::Rails.env.development?
|
if ::Rails.env.development?
|
||||||
"(function() { try { return Ember.#{ember_template}.compile(#{indent(string).inspect}); } catch(err) { throw err; } })()"
|
"(function() { try { return Ember.#{ember_template}.compile(#{indent(string).inspect}); } catch(err) { throw err; } })()"
|
||||||
else
|
else
|
||||||
"Ember.#{ember_template}.compile(#{indent(string).inspect});"
|
"Ember.#{ember_template}.compile(#{indent(string).inspect}, #{options.to_json});"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,32 +1,47 @@
|
||||||
# barber patches to re-route raw compilation via ember compat handlebars
|
# barber patches to re-route raw compilation via ember compat handlebars
|
||||||
#
|
|
||||||
|
|
||||||
module Barber
|
class Barber::Precompiler
|
||||||
class EmberCompatPrecompiler < Barber::Precompiler
|
def sources
|
||||||
|
[File.open("#{Rails.root}/vendor/assets/javascripts/handlebars.js"), precompiler]
|
||||||
|
end
|
||||||
|
|
||||||
def sources
|
def precompiler
|
||||||
[File.open("#{Rails.root}/vendor/assets/javascripts/handlebars.js"), precompiler]
|
@precompiler ||= StringIO.new <<END
|
||||||
end
|
var Discourse = {};
|
||||||
|
#{File.read(Rails.root + "app/assets/javascripts/discourse/lib/ember_compat_handlebars.js")}
|
||||||
def precompiler
|
var Barber = {
|
||||||
@precompiler ||= StringIO.new <<END
|
precompile: function(string) {
|
||||||
var Discourse = {};
|
return Discourse.EmberCompatHandlebars.precompile(string,false).toString();
|
||||||
#{File.read(Rails.root + "app/assets/javascripts/discourse/lib/ember_compat_handlebars.js")}
|
}
|
||||||
var Barber = {
|
};
|
||||||
precompile: function(string) {
|
|
||||||
return Discourse.EmberCompatHandlebars.precompile(string,false).toString();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
END
|
END
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Discourse
|
||||||
|
module Ember
|
||||||
|
module Handlebars
|
||||||
|
module Helper
|
||||||
|
def precompile_handlebars(string)
|
||||||
|
"Discourse.EmberCompatHandlebars.template(#{Barber::Precompiler.compile(string)});"
|
||||||
|
end
|
||||||
|
|
||||||
|
def compile_handlebars(string)
|
||||||
|
"Discourse.EmberCompatHandlebars.compile(#{indent(string).inspect});"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Ember::Handlebars::Template
|
class Ember::Handlebars::Template
|
||||||
def precompile_handlebars(string)
|
include Discourse::Ember::Handlebars::Helper
|
||||||
"Discourse.EmberCompatHandlebars.template(#{Barber::EmberCompatPrecompiler.compile(string)});"
|
|
||||||
end
|
# FIXME: Previously, ember-handlebars-templates uses the logical path which incorrectly
|
||||||
def compile_handlebars(string)
|
# returned paths with the `.raw` extension and our code is depending on the `.raw`
|
||||||
"Discourse.EmberCompatHandlebars.compile(#{indent(string).inspect});"
|
# to find the right template to use.
|
||||||
|
def actual_name(input)
|
||||||
|
actual_name = input[:name]
|
||||||
|
input[:filename].include?('.raw') ? "#{actual_name}.raw" : actual_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
19
lib/freedom_patches/resolve.rb
Normal file
19
lib/freedom_patches/resolve.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# sass-rails expects an actual file to exists when calling `@import`. However,
|
||||||
|
# we don't actually create the files for our special imports but rather inject
|
||||||
|
# them dynamically.
|
||||||
|
module Discourse
|
||||||
|
module Sprockets
|
||||||
|
module Resolve
|
||||||
|
def resolve(path, options = {})
|
||||||
|
return [path, []] if DiscourseSassImporter.special_imports.has_key?(File.basename(path, '.scss'))
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Sprockets
|
||||||
|
class Base
|
||||||
|
prepend Discourse::Sprockets::Resolve
|
||||||
|
end
|
||||||
|
end
|
16
lib/freedom_patches/sass_rails_template.rb
Normal file
16
lib/freedom_patches/sass_rails_template.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# sass-rails expects an actual file to exists when calling `@import`. However,
|
||||||
|
# we don't actually create the files for our special imports but rather inject
|
||||||
|
# them dynamically.
|
||||||
|
module Discourse
|
||||||
|
module Sprockets
|
||||||
|
module Resolve
|
||||||
|
def resolve(path, options = {})
|
||||||
|
return [path, []] if DiscourseSassImporter.special_imports.has_key?(File.basename(path, '.scss'))
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Call `prepend` directly once we drop support for Ruby 2.0.0.
|
||||||
|
Sprockets::Base.send(:prepend, Discourse::Sprockets::Resolve)
|
|
@ -20,7 +20,7 @@ class DiscourseSafeSassImporter < DiscourseSassImporter
|
||||||
special_imports[name].each do |css_file|
|
special_imports[name].each do |css_file|
|
||||||
contents << File.read(css_file)
|
contents << File.read(css_file)
|
||||||
end
|
end
|
||||||
Sass::Engine.new(contents, options.merge(
|
::Sass::Engine.new(contents, options.merge(
|
||||||
filename: "#{name}.scss",
|
filename: "#{name}.scss",
|
||||||
importer: self,
|
importer: self,
|
||||||
syntax: :scss
|
syntax: :scss
|
||||||
|
|
|
@ -39,17 +39,17 @@ class DiscourseSassCompiler
|
||||||
# Options:
|
# Options:
|
||||||
# safe: (boolean) if true, theme and plugin stylesheets will not be included. Default is false.
|
# safe: (boolean) if true, theme and plugin stylesheets will not be included. Default is false.
|
||||||
def compile(opts={})
|
def compile(opts={})
|
||||||
env = Rails.application.assets
|
app = Rails.application
|
||||||
|
env = app.assets || Sprockets::Railtie.build_environment(app)
|
||||||
# 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.
|
|
||||||
if env.is_a?(Sprockets::Index)
|
|
||||||
env = env.instance_variable_get('@environment')
|
|
||||||
end
|
|
||||||
|
|
||||||
pathname = Pathname.new("app/assets/stylesheets/#{@target}.scss")
|
pathname = Pathname.new("app/assets/stylesheets/#{@target}.scss")
|
||||||
context = env.context_class.new(env, "#{@target}.scss", pathname)
|
|
||||||
|
context = env.context_class.new(
|
||||||
|
environment: env,
|
||||||
|
filename: "#{@target}.scss",
|
||||||
|
pathname: pathname,
|
||||||
|
metadata: {}
|
||||||
|
)
|
||||||
|
|
||||||
debug_opts = Rails.env.production? ? {} : {
|
debug_opts = Rails.env.production? ? {} : {
|
||||||
line_numbers: true,
|
line_numbers: true,
|
||||||
|
@ -57,12 +57,15 @@ class DiscourseSassCompiler
|
||||||
style: :expanded
|
style: :expanded
|
||||||
}
|
}
|
||||||
|
|
||||||
|
importer_class = opts[:safe] ? DiscourseSafeSassImporter : DiscourseSassImporter
|
||||||
|
|
||||||
css = ::Sass::Engine.new(@scss, {
|
css = ::Sass::Engine.new(@scss, {
|
||||||
syntax: :scss,
|
syntax: :scss,
|
||||||
cache: false,
|
cache: false,
|
||||||
read_cache: false,
|
read_cache: false,
|
||||||
style: :compressed,
|
style: :compressed,
|
||||||
filesystem_importer: opts[:safe] ? DiscourseSafeSassImporter : DiscourseSassImporter,
|
filesystem_importer: importer_class,
|
||||||
|
load_paths: context.environment.paths.map { |path| importer_class.new(path.to_s) },
|
||||||
sprockets: {
|
sprockets: {
|
||||||
context: context,
|
context: context,
|
||||||
environment: context.environment
|
environment: context.environment
|
||||||
|
|
|
@ -2,156 +2,118 @@
|
||||||
# Sprockets::SassImporter implementation provided in sass-rails since that is used
|
# Sprockets::SassImporter implementation provided in sass-rails since that is used
|
||||||
# during asset precompilation.
|
# during asset precompilation.
|
||||||
class DiscourseSassImporter < Sass::Importers::Filesystem
|
class DiscourseSassImporter < Sass::Importers::Filesystem
|
||||||
GLOB = /\*|\[.+\]/ unless defined? GLOB
|
module Sass
|
||||||
|
def extensions
|
||||||
|
{
|
||||||
|
'css' => :scss,
|
||||||
|
'css.scss' => :scss,
|
||||||
|
'css.sass' => :sass,
|
||||||
|
'css.erb' => :scss,
|
||||||
|
'scss.erb' => :scss,
|
||||||
|
'sass.erb' => :sass,
|
||||||
|
'css.scss.erb' => :scss,
|
||||||
|
'css.sass.erb' => :sass
|
||||||
|
}.merge!(super)
|
||||||
|
end
|
||||||
|
|
||||||
# Depending upon where this is passed we might either be passed a string as the
|
def special_imports
|
||||||
# first argument or a sprockets context. If the first argument is a sprockets
|
{
|
||||||
# context we store it and use it to mark dependencies.
|
"plugins" => DiscoursePluginRegistry.stylesheets,
|
||||||
def initialize(*args)
|
"plugins_mobile" => DiscoursePluginRegistry.mobile_stylesheets,
|
||||||
@context = args.first unless args.first.is_a? String
|
"plugins_desktop" => DiscoursePluginRegistry.desktop_stylesheets,
|
||||||
@root = Rails.root.join('app', 'assets', 'stylesheets').to_s
|
"plugins_variables" => DiscoursePluginRegistry.sass_variables,
|
||||||
@same_name_warnings = Set.new
|
"theme_variables" => [ColorScheme::BASE_COLORS_FILE],
|
||||||
end
|
"category_backgrounds" => Proc.new { |c| "body.category-#{c.full_slug} { background-image: url(#{apply_cdn(c.background_url)}) }\n" }
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def extensions
|
def find_relative(name, base, options)
|
||||||
{
|
|
||||||
'css' => :scss,
|
|
||||||
'css.scss' => :scss,
|
|
||||||
'css.sass' => :sass,
|
|
||||||
'css.erb' => :scss,
|
|
||||||
'scss.erb' => :scss,
|
|
||||||
'sass.erb' => :sass,
|
|
||||||
'css.scss.erb' => :scss,
|
|
||||||
'css.sass.erb' => :sass
|
|
||||||
}.merge!(super)
|
|
||||||
end
|
|
||||||
|
|
||||||
def special_imports
|
|
||||||
{
|
|
||||||
"plugins" => DiscoursePluginRegistry.stylesheets,
|
|
||||||
"plugins_mobile" => DiscoursePluginRegistry.mobile_stylesheets,
|
|
||||||
"plugins_desktop" => DiscoursePluginRegistry.desktop_stylesheets,
|
|
||||||
"plugins_variables" => DiscoursePluginRegistry.sass_variables,
|
|
||||||
"theme_variables" => [ColorScheme::BASE_COLORS_FILE]
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
def find_relative(name, base, options)
|
|
||||||
if name =~ GLOB
|
|
||||||
glob_imports(name, Pathname.new(base), options)
|
|
||||||
else
|
|
||||||
engine_from_path(name, File.dirname(base), options)
|
engine_from_path(name, File.dirname(base), options)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def apply_cdn(url)
|
def apply_cdn(url)
|
||||||
"#{GlobalSetting.cdn_url}#{url}"
|
"#{GlobalSetting.cdn_url}#{url}"
|
||||||
end
|
|
||||||
|
|
||||||
def find(name, options)
|
|
||||||
|
|
||||||
if name == "category_backgrounds"
|
|
||||||
contents = ""
|
|
||||||
Category.where('background_url IS NOT NULL').each do |c|
|
|
||||||
if c.background_url.present?
|
|
||||||
contents << "body.category-#{c.full_slug} { background-image: url(#{apply_cdn(c.background_url)}) }\n"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return Sass::Engine.new(contents, options.merge(
|
|
||||||
filename: "#{name}.scss",
|
|
||||||
importer: self,
|
|
||||||
syntax: :scss
|
|
||||||
))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if special_imports.has_key? name
|
def find(name, options)
|
||||||
if name == "theme_variables"
|
|
||||||
|
if name == "category_backgrounds"
|
||||||
contents = ""
|
contents = ""
|
||||||
if color_scheme = ColorScheme.enabled
|
Category.where('background_url IS NOT NULL').each do |c|
|
||||||
ColorScheme.base_colors.each do |n, base_hex|
|
contents << special_imports[name].call(c) if c.background_url.present?
|
||||||
override = color_scheme.colors_by_name[n]
|
|
||||||
contents << "$#{n}: ##{override ? override.hex : base_hex} !default;\n"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
special_imports[name].each do |css_file|
|
|
||||||
contents << File.read(css_file)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Sass::Engine.new(contents, options.merge(
|
return ::Sass::Engine.new(contents, options.merge(
|
||||||
filename: "#{name}.scss",
|
filename: "#{name}.scss",
|
||||||
importer: self,
|
importer: self,
|
||||||
syntax: :scss
|
syntax: :scss
|
||||||
))
|
))
|
||||||
else
|
end
|
||||||
stylesheets = special_imports[name]
|
|
||||||
contents = ""
|
if special_imports.has_key? name
|
||||||
stylesheets.each do |css_file|
|
if name == "theme_variables"
|
||||||
if css_file =~ /\.scss$/
|
contents = ""
|
||||||
contents << "@import '#{css_file}';"
|
if color_scheme = ColorScheme.enabled
|
||||||
|
ColorScheme.base_colors.each do |n, base_hex|
|
||||||
|
override = color_scheme.colors_by_name[n]
|
||||||
|
contents << "$#{n}: ##{override ? override.hex : base_hex} !default;\n"
|
||||||
|
end
|
||||||
else
|
else
|
||||||
contents << File.read(css_file)
|
special_imports[name].each do |css_file|
|
||||||
|
contents << File.read(css_file)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
depend_on(css_file)
|
|
||||||
|
::Sass::Engine.new(contents, options.merge(
|
||||||
|
filename: "#{name}.scss",
|
||||||
|
importer: self,
|
||||||
|
syntax: :scss
|
||||||
|
))
|
||||||
|
else
|
||||||
|
stylesheets = special_imports[name]
|
||||||
|
contents = ""
|
||||||
|
stylesheets.each do |css_file|
|
||||||
|
if css_file =~ /\.scss$/
|
||||||
|
contents << "@import '#{css_file}';"
|
||||||
|
else
|
||||||
|
contents << File.read(css_file)
|
||||||
|
end
|
||||||
|
depend_on(css_file)
|
||||||
|
end
|
||||||
|
|
||||||
|
::Sass::Engine.new(contents, options.merge(
|
||||||
|
filename: "#{name}.scss",
|
||||||
|
importer: self,
|
||||||
|
syntax: :scss
|
||||||
|
))
|
||||||
end
|
end
|
||||||
Sass::Engine.new(contents, options.merge(
|
|
||||||
filename: "#{name}.scss",
|
|
||||||
importer: self,
|
|
||||||
syntax: :scss
|
|
||||||
))
|
|
||||||
end
|
|
||||||
elsif name =~ GLOB
|
|
||||||
nil # globs must be relative
|
|
||||||
else
|
|
||||||
engine_from_path(name, root, options)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def each_globbed_file(glob, base_pathname, options)
|
|
||||||
Dir["#{base_pathname}/#{glob}"].sort.each do |filename|
|
|
||||||
next if filename == options[:filename]
|
|
||||||
yield filename # assume all matching files are requirable
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
|
||||||
end
|
|
||||||
return nil if contents.empty?
|
|
||||||
Sass::Engine.new(contents, options.merge(
|
|
||||||
filename: base_pathname.to_s,
|
|
||||||
importer: self,
|
|
||||||
syntax: :scss
|
|
||||||
))
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
else
|
||||||
File.dirname(filename)
|
engine_from_path(name, root, options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def engine_from_path(name, dir, options)
|
private
|
||||||
full_filename, _ = Sass::Util.destructure(find_real_file(dir, name, options))
|
|
||||||
return unless full_filename && File.readable?(full_filename)
|
|
||||||
|
|
||||||
depend_on(full_filename)
|
def depend_on(filename)
|
||||||
Sass::Engine.for_file(full_filename, options)
|
if @context
|
||||||
end
|
@context.depend_on(filename)
|
||||||
|
@context.depend_on(globbed_file_parent(filename))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def engine_from_path(name, dir, options)
|
||||||
|
full_filename, _ = ::Sass::Util.destructure(find_real_file(dir, name, options))
|
||||||
|
return unless full_filename && File.readable?(full_filename)
|
||||||
|
|
||||||
|
depend_on(full_filename)
|
||||||
|
::Sass::Engine.for_file(full_filename, options)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
include Sass
|
||||||
|
include ::Sass::Rails::SassImporter::Globbing
|
||||||
|
|
||||||
|
def self.special_imports
|
||||||
|
self.new('').special_imports
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*global document, sinon, QUnit, Logster */
|
/*global document, sinon, QUnit, Logster */
|
||||||
|
|
||||||
//= require env
|
//= require env
|
||||||
//= require ../../app/assets/javascripts/preload_store
|
//= require preload_store
|
||||||
//= require probes
|
//= require probes
|
||||||
//= require jquery.debug
|
//= require jquery.debug
|
||||||
//= require jquery.ui.widget
|
//= require jquery.ui.widget
|
||||||
|
@ -14,8 +14,8 @@
|
||||||
//= require route-recognizer
|
//= require route-recognizer
|
||||||
//= require pretender
|
//= require pretender
|
||||||
|
|
||||||
//= require ../../app/assets/javascripts/locales/i18n
|
//= require locales/i18n
|
||||||
//= require ../../app/assets/javascripts/locales/en
|
//= require locales/en
|
||||||
|
|
||||||
//= require vendor
|
//= require vendor
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
//= require plugin_tests
|
//= require plugin_tests
|
||||||
//= require_self
|
//= require_self
|
||||||
//
|
//
|
||||||
//= require ../../public/javascripts/jquery.magnific-popup-min.js
|
//= require jquery.magnific-popup-min.js
|
||||||
|
|
||||||
window.inTestEnv = true;
|
window.inTestEnv = true;
|
||||||
|
|
||||||
|
|
821
vendor/assets/javascripts/ember-template-compiler.js
vendored
821
vendor/assets/javascripts/ember-template-compiler.js
vendored
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue