Class: Sprockets::BumbleD::Transformer
- Inherits:
-
Object
- Object
- Sprockets::BumbleD::Transformer
- Defined in:
- lib/sprockets/bumble_d/transformer.rb
Defined Under Namespace
Classes: BabelBridge
Instance Attribute Summary collapse
-
#cache_key ⇒ Object
readonly
Returns the value of attribute cache_key.
Instance Method Summary collapse
- #babel ⇒ Object
-
#cache_key_from_input(input) ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/MethodLength.
-
#call(input) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
-
#initialize(options) ⇒ Transformer
constructor
rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(options) ⇒ Transformer
rubocop:disable Metrics/MethodLength
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sprockets/bumble_d/transformer.rb', line 21 def initialize() @options = .dup @root_dir = @options.delete(:root_dir) babel_config_version = @options.delete(:babel_config_version) unless @root_dir && File.directory?(@root_dir) = 'You must provide the `root_dir` directory from which ' \ 'node modules are to be resolved' raise RootDirectoryDoesNotExistError, end @resolution_complete = false @cache_key = [ self.class.name, VERSION, babel_config_version, @options ].freeze end |
Instance Attribute Details
#cache_key ⇒ Object (readonly)
Returns the value of attribute cache_key.
18 19 20 |
# File 'lib/sprockets/bumble_d/transformer.rb', line 18 def cache_key @cache_key end |
Instance Method Details
#babel ⇒ Object
78 79 80 |
# File 'lib/sprockets/bumble_d/transformer.rb', line 78 def babel @babel ||= BabelBridge.new(@root_dir) end |
#cache_key_from_input(input) ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/MethodLength
74 75 76 |
# File 'lib/sprockets/bumble_d/transformer.rb', line 74 def cache_key_from_input(input) @cache_key + [input[:filename]] + [input[:data]] end |
#call(input) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/sprockets/bumble_d/transformer.rb', line 44 def call(input) data = input[:data] result = input[:cache].fetch(cache_key_from_input(input)) do filename_relative = Sprockets::PathUtils.split_subpath( input[:load_path], input[:filename] ) = { moduleIds: true, sourceRoot: input[:load_path], filename: input[:filename], filenameRelative: filename_relative, ast: false }.merge() if [:moduleIds] && [:moduleRoot] [:moduleId] ||= File.join([:moduleRoot], input[:name]) elsif [:moduleIds] && input[:name] && !input[:name].empty? [:moduleId] ||= input[:name] end babel.transform(data, ) end { data: result['code'] } end |