mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06: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:
@@ -1,13 +1,13 @@
|
||||
module Ember
|
||||
module Handlebars
|
||||
class Template < Tilt::Template
|
||||
class Template
|
||||
|
||||
# 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?
|
||||
"(function() { try { return Ember.#{ember_template}.compile(#{indent(string).inspect}); } catch(err) { throw err; } })()"
|
||||
else
|
||||
"Ember.#{ember_template}.compile(#{indent(string).inspect});"
|
||||
"Ember.#{ember_template}.compile(#{indent(string).inspect}, #{options.to_json});"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -1,32 +1,47 @@
|
||||
# barber patches to re-route raw compilation via ember compat handlebars
|
||||
#
|
||||
|
||||
module Barber
|
||||
class EmberCompatPrecompiler < Barber::Precompiler
|
||||
class Barber::Precompiler
|
||||
def sources
|
||||
[File.open("#{Rails.root}/vendor/assets/javascripts/handlebars.js"), precompiler]
|
||||
end
|
||||
|
||||
def sources
|
||||
[File.open("#{Rails.root}/vendor/assets/javascripts/handlebars.js"), precompiler]
|
||||
end
|
||||
|
||||
def precompiler
|
||||
@precompiler ||= StringIO.new <<END
|
||||
var Discourse = {};
|
||||
#{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();
|
||||
}
|
||||
};
|
||||
def precompiler
|
||||
@precompiler ||= StringIO.new <<END
|
||||
var Discourse = {};
|
||||
#{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
|
||||
|
||||
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
|
||||
|
||||
class Ember::Handlebars::Template
|
||||
def precompile_handlebars(string)
|
||||
"Discourse.EmberCompatHandlebars.template(#{Barber::EmberCompatPrecompiler.compile(string)});"
|
||||
end
|
||||
def compile_handlebars(string)
|
||||
"Discourse.EmberCompatHandlebars.compile(#{indent(string).inspect});"
|
||||
include Discourse::Ember::Handlebars::Helper
|
||||
|
||||
# FIXME: Previously, ember-handlebars-templates uses the logical path which incorrectly
|
||||
# returned paths with the `.raw` extension and our code is depending on the `.raw`
|
||||
# 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
|
||||
|
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)
|
Reference in New Issue
Block a user