From 6e5296a510b31b01804105f57d3998a9a96d655e Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 17 Apr 2017 10:11:51 -0400 Subject: [PATCH] FEATURE: upgrade sprockets to latest stable This unlocks Rails upgrades, so we can now upgrade to latest Rails --- Gemfile.lock | 4 ++-- lib/es6_module_transpiler/sprockets.rb | 3 ++- .../tilt/es6_module_transpiler_template.rb | 9 +++++++++ lib/source_url.rb | 9 +++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 64a64c3dc61..e7357029e28 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -358,10 +358,10 @@ GEM spork-rails (4.0.0) rails (>= 3.0.0, < 5) spork (>= 1.0rc0) - sprockets (3.6.3) + sprockets (3.7.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.1.1) + sprockets-rails (3.2.0) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) diff --git a/lib/es6_module_transpiler/sprockets.rb b/lib/es6_module_transpiler/sprockets.rb index 1a62c5cbfb0..9da657f03c2 100644 --- a/lib/es6_module_transpiler/sprockets.rb +++ b/lib/es6_module_transpiler/sprockets.rb @@ -1,3 +1,4 @@ require 'sprockets' -Sprockets.register_engine '.es6', Tilt::ES6ModuleTranspilerTemplate +Sprockets.register_mime_type 'application/ecmascript6', extensions: ['.es6', '.js.es6'], charset: :unicode +Sprockets.register_transformer 'application/ecmascript6', 'application/javascript', Tilt::ES6ModuleTranspilerTemplate diff --git a/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb b/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb index d18afbf3c92..f093a0a30e4 100644 --- a/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb +++ b/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb @@ -10,6 +10,15 @@ module Tilt @mutex = Mutex.new @ctx_init = Mutex.new + def self.call(input) + filename = input[:filename] + source = input[:data] + context = input[:environment].context_class.new(input) + + result = new(filename){source}.render(context) + context.metadata.merge(data: result) + end + def prepare # intentionally left empty # Tilt requires this method to be defined diff --git a/lib/source_url.rb b/lib/source_url.rb index c089d18eb62..41d4fe5decc 100644 --- a/lib/source_url.rb +++ b/lib/source_url.rb @@ -1,6 +1,15 @@ class SourceURL < Tilt::Template self.default_mime_type = 'application/javascript' + def self.call(input) + filename = input[:filename] + source = input[:data] + context = input[:environment].context_class.new(input) + + result = new(filename){source}.render(context) + context.metadata.merge(data: result) + end + def prepare end