sprockets-es6-0.9.2/0000755000004100000410000000000012774760534014301 5ustar www-datawww-datasprockets-es6-0.9.2/lib/0000755000004100000410000000000012774760534015047 5ustar www-datawww-datasprockets-es6-0.9.2/lib/sprockets/0000755000004100000410000000000012774760534017064 5ustar www-datawww-datasprockets-es6-0.9.2/lib/sprockets/es6/0000755000004100000410000000000012774760534017561 5ustar www-datawww-datasprockets-es6-0.9.2/lib/sprockets/es6/version.rb0000644000004100000410000000007512774760534021575 0ustar www-datawww-datamodule Sprockets class ES6 VERSION = '0.9.2' end end sprockets-es6-0.9.2/lib/sprockets/es6.rb0000644000004100000410000000462312774760534020113 0ustar www-datawww-datarequire 'babel/transpiler' require 'sprockets' require 'sprockets/es6/version' require 'ostruct' module Sprockets class ES6 class << self attr_accessor :configuration def configuration_hash configuration.to_h.reduce({}) do |hash, (key, val)| hash[key.to_s] = val hash end end def instance @instance ||= new end def configure self.configuration ||= OpenStruct.new yield configuration end def reset_configuration self.configuration = OpenStruct.new end def call(input) instance.call(input) end def cache_key instance.cache_key end end attr_reader :cache_key def configuration_hash self.class.configuration_hash end def initialize(options = {}) @options = configuration_hash.merge(options).freeze @cache_key = [ self.class.name, Babel::Transpiler.version, Babel::Transpiler.source_version, VERSION, @options ].freeze end def call(input) data = input[:data] result = input[:cache].fetch(@cache_key + [input[:filename]] + [data]) do transform(data, transformation_options(input)) end result['code'] end def transform(data, opts) Babel::Transpiler.transform(data, opts) end def transformation_options(input) opts = { 'sourceRoot' => input[:load_path], 'moduleRoot' => nil, 'filename' => input[:filename], 'filenameRelative' => input[:environment].split_subpath(input[:load_path], input[:filename]) }.merge(@options) if opts['moduleIds'] && opts['moduleRoot'] opts['moduleId'] ||= File.join(opts['moduleRoot'], input[:name]) elsif opts['moduleIds'] opts['moduleId'] ||= input[:name] end opts end end append_path Babel::Transpiler.source_path if respond_to?(:register_transformer) register_mime_type 'text/ecmascript-6', extensions: ['.es6'], charset: :unicode register_transformer 'text/ecmascript-6', 'application/javascript', ES6 register_preprocessor 'text/ecmascript-6', DirectiveProcessor end if respond_to?(:register_engine) args = ['.es6', ES6] args << { mime_type: 'text/ecmascript-6', silence_deprecation: true } if Sprockets::VERSION.start_with?("3") register_engine(*args) end end sprockets-es6-0.9.2/sprockets-es6.gemspec0000644000004100000410000000346512774760534020366 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = "sprockets-es6" s.version = "0.9.2" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Joshua Peek"] s.date = "2016-09-23" s.description = " A Sprockets transformer that converts ES6 code into vanilla ES5 with Babel JS.\n" s.email = "josh@joshpeek.com" s.files = ["LICENSE", "README.md", "lib/sprockets/es6.rb", "lib/sprockets/es6/version.rb"] s.homepage = "https://github.com/TannerRogalsky/sprockets-es6" s.licenses = ["MIT"] s.require_paths = ["lib"] s.rubygems_version = "1.8.23" s.summary = "Sprockets ES6 transformer" if s.respond_to? :specification_version then s.specification_version = 4 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_runtime_dependency(%q, [">= 5.8.11"]) s.add_runtime_dependency(%q, [">= 0"]) s.add_development_dependency(%q, [">= 0"]) s.add_development_dependency(%q, [">= 0"]) s.add_runtime_dependency(%q, [">= 3.0.0"]) else s.add_dependency(%q, [">= 5.8.11"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 3.0.0"]) end else s.add_dependency(%q, [">= 5.8.11"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 3.0.0"]) end end sprockets-es6-0.9.2/LICENSE0000644000004100000410000000203712774760534015310 0ustar www-datawww-dataCopyright (c) 2014 Joshua Peek Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. sprockets-es6-0.9.2/README.md0000644000004100000410000000212512774760534015560 0ustar www-datawww-data# Sprockets ES6 **Experimental** A Sprockets transformer that converts ES6 code into vanilla ES5 with [Babel JS](https://babeljs.io). ## Usage ``` ruby # Gemfile gem 'sprockets', '>= 3.0.0' gem 'sprockets-es6' ``` ``` ruby # application.rb # [...] require "action_view/railtie" require "sprockets/railtie" # require "rails/test_unit/railtie" require 'sprockets/es6' # [...] ``` ``` js // app.es6 let square = (x) => x * x class Animal { constructor(name) { this.name = name } } ``` ## Releases This plugin is primarily experimental and will never reach a stable 1.0. The purpose is to test out BabelJS features on Sprockets 3.x and include it by default in Sprockets 4.x. ## Asset manifests required for precompiling `.es6` won't work directly with `config.assets.precompile = %w( foo.es6 )` for annoying compatibility reasons with Sprockets 2.x. Besides, you should look into moving away from `config.assets.precompile` and using manifests instead. See [Sprockets 3.x UPGRADING guide](https://github.com/rails/sprockets/blob/master/UPGRADING.md#preference-for-asset-manifest-and-links).