class Sprockets::ES6
Constants
- VERSION
Attributes
configuration[RW]
cache_key[R]
Public Class Methods
cache_key()
click to toggle source
# File lib/sprockets/es6.rb, line 37 def cache_key instance.cache_key end
call(input)
click to toggle source
# File lib/sprockets/es6.rb, line 33 def call(input) instance.call(input) end
configuration_hash()
click to toggle source
# File lib/sprockets/es6.rb, line 13 def configuration_hash configuration.to_h.reduce({}) do |hash, (key, val)| hash[key.to_s] = val hash end end
configure() { |configuration| ... }
click to toggle source
# File lib/sprockets/es6.rb, line 24 def configure self.configuration ||= OpenStruct.new yield configuration end
instance()
click to toggle source
# File lib/sprockets/es6.rb, line 20 def instance @instance ||= new end
new(options = {})
click to toggle source
# File lib/sprockets/es6.rb, line 49 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
reset_configuration()
click to toggle source
# File lib/sprockets/es6.rb, line 29 def reset_configuration self.configuration = OpenStruct.new end
Public Instance Methods
call(input)
click to toggle source
# File lib/sprockets/es6.rb, line 61 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
configuration_hash()
click to toggle source
# File lib/sprockets/es6.rb, line 45 def configuration_hash self.class.configuration_hash end
transform(data, opts)
click to toggle source
# File lib/sprockets/es6.rb, line 69 def transform(data, opts) Babel::Transpiler.transform(data, opts) end
transformation_options(input)
click to toggle source
# File lib/sprockets/es6.rb, line 73 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