Class: Terser::Compressor
- Inherits:
-
Object
- Object
- Terser::Compressor
- Defined in:
- lib/terser/compressor.rb
Overview
A wrapper for Sprockets
Constant Summary collapse
- VERSION =
'1'
Instance Attribute Summary collapse
-
#cache_key ⇒ Object
readonly
Returns the value of attribute cache_key.
Class Method Summary collapse
Instance Method Summary collapse
- #call(input) ⇒ Object
-
#initialize(options = {}) ⇒ Compressor
constructor
A new instance of Compressor.
Constructor Details
#initialize(options = {}) ⇒ Compressor
Returns a new instance of Compressor.
11 12 13 14 15 16 |
# File 'lib/terser/compressor.rb', line 11 def initialize( = {}) [:comments] ||= :none @options = @cache_key = -"Terser:#{::Terser::VERSION}:#{VERSION}:#{::Sprockets::DigestUtils.digest()}" @terser = ::Terser.new(@options) end |
Instance Attribute Details
#cache_key ⇒ Object (readonly)
Returns the value of attribute cache_key.
30 31 32 |
# File 'lib/terser/compressor.rb', line 30 def cache_key @cache_key end |
Class Method Details
.cache_key ⇒ Object
26 27 28 |
# File 'lib/terser/compressor.rb', line 26 def self.cache_key instance.cache_key end |
.call(input) ⇒ Object
22 23 24 |
# File 'lib/terser/compressor.rb', line 22 def self.call(input) instance.call(input) end |
.instance ⇒ Object
18 19 20 |
# File 'lib/terser/compressor.rb', line 18 def self.instance @instance ||= new end |
Instance Method Details
#call(input) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/terser/compressor.rb', line 33 def call(input) = { :source_map => { :filename => input[:filename] } } js, map = @terser.compile_with_map(input[:data], ) map = ::Sprockets::SourceMapUtils.format_source_map(JSON.parse(map), input) map = ::Sprockets::SourceMapUtils.combine_source_maps(input[:metadata][:map], map) { :data => js, :map => map } end |