Class: Sprockets::ES6
- Inherits:
-
Object
- Object
- Sprockets::ES6
- Defined in:
- lib/sprockets/es6.rb,
lib/sprockets/es6/version.rb
Constant Summary collapse
- VERSION =
'0.9.2'
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Instance Attribute Summary collapse
-
#cache_key ⇒ Object
readonly
Returns the value of attribute cache_key.
Class Method Summary collapse
- .cache_key ⇒ Object
- .call(input) ⇒ Object
- .configuration_hash ⇒ Object
- .configure {|configuration| ... } ⇒ Object
- .instance ⇒ Object
- .reset_configuration ⇒ Object
Instance Method Summary collapse
- #call(input) ⇒ Object
- #configuration_hash ⇒ Object
-
#initialize(options = {}) ⇒ ES6
constructor
A new instance of ES6.
- #transform(data, opts) ⇒ Object
- #transformation_options(input) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ ES6
Returns a new instance of ES6.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sprockets/es6.rb', line 49 def initialize( = {}) @options = configuration_hash.merge().freeze @cache_key = [ self.class.name, Babel::Transpiler.version, Babel::Transpiler.source_version, VERSION, @options ].freeze end |
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
11 12 13 |
# File 'lib/sprockets/es6.rb', line 11 def configuration @configuration end |
Instance Attribute Details
#cache_key ⇒ Object (readonly)
Returns the value of attribute cache_key.
43 44 45 |
# File 'lib/sprockets/es6.rb', line 43 def cache_key @cache_key end |
Class Method Details
.cache_key ⇒ Object
37 38 39 |
# File 'lib/sprockets/es6.rb', line 37 def cache_key instance.cache_key end |
.call(input) ⇒ Object
33 34 35 |
# File 'lib/sprockets/es6.rb', line 33 def call(input) instance.call(input) end |
.configuration_hash ⇒ Object
13 14 15 16 17 18 |
# 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| ... } ⇒ Object
24 25 26 27 |
# File 'lib/sprockets/es6.rb', line 24 def configure self.configuration ||= OpenStruct.new yield configuration end |
.instance ⇒ Object
20 21 22 |
# File 'lib/sprockets/es6.rb', line 20 def instance @instance ||= new end |
.reset_configuration ⇒ Object
29 30 31 |
# File 'lib/sprockets/es6.rb', line 29 def reset_configuration self.configuration = OpenStruct.new end |
Instance Method Details
#call(input) ⇒ Object
61 62 63 64 65 66 67 |
# 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, (input)) end result['code'] end |
#configuration_hash ⇒ Object
45 46 47 |
# File 'lib/sprockets/es6.rb', line 45 def configuration_hash self.class.configuration_hash end |
#transform(data, opts) ⇒ Object
69 70 71 |
# File 'lib/sprockets/es6.rb', line 69 def transform(data, opts) Babel::Transpiler.transform(data, opts) end |
#transformation_options(input) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/sprockets/es6.rb', line 73 def (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 |