class Sprockets::Babel::Template
Public Class Methods
engine_initialized?()
click to toggle source
# File lib/sprockets/babel.rb, line 14 def self.engine_initialized? true end
Public Instance Methods
evaluate(scope, locals, &block)
click to toggle source
# File lib/sprockets/babel.rb, line 24 def evaluate(scope, locals, &block) source_root = get_source_root(scope) babel_options = { modules: 'inline', moduleIds: true, moduleId: get_module_name(source_root), filename: file, filenameRelative: get_filename_relative(source_root) }.merge(options.merge(::Babel.options)) Babel.transform(data, babel_options)['code'] end
initialize_engine()
click to toggle source
# File lib/sprockets/babel.rb, line 18 def initialize_engine end
prepare()
click to toggle source
# File lib/sprockets/babel.rb, line 21 def prepare end
Private Instance Methods
basename(file)
click to toggle source
# File lib/sprockets/babel.rb, line 58 def basename(file) file.gsub(/\.[^\/]+$/, '').gsub(/^\//, '') end
get_filename_relative(source_root)
click to toggle source
# File lib/sprockets/babel.rb, line 48 def get_filename_relative(source_root) return '' unless source_root Pathname.new(file).relative_path_from(Pathname.new(source_root)) end
get_module_name(source_root)
click to toggle source
# File lib/sprockets/babel.rb, line 53 def get_module_name(source_root) return basename(file) unless source_root basename(file.gsub(source_root, '')) end
get_source_root(scope)
click to toggle source
# File lib/sprockets/babel.rb, line 38 def get_source_root(scope) asset_paths = scope.environment.paths asset_paths.each do |path| if file.start_with?(path) return path end end '' end