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 |
# File 'lib/terser/compressor.rb', line 11 def initialize( = {}) [:comments] ||= :none @options = @cache_key = -"Terser:#{::Terser::VERSION}:#{VERSION}:#{::Sprockets::DigestUtils.digest()}" end |
Instance Attribute Details
#cache_key ⇒ Object (readonly)
Returns the value of attribute cache_key.
29 30 31 |
# File 'lib/terser/compressor.rb', line 29 def cache_key @cache_key end |
Class Method Details
.cache_key ⇒ Object
25 26 27 |
# File 'lib/terser/compressor.rb', line 25 def self.cache_key instance.cache_key end |
.call(input) ⇒ Object
21 22 23 |
# File 'lib/terser/compressor.rb', line 21 def self.call(input) instance.call(input) end |
.instance ⇒ Object
17 18 19 |
# File 'lib/terser/compressor.rb', line 17 def self.instance @instance ||= new end |
Instance Method Details
#call(input) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/terser/compressor.rb', line 32 def call(input) = { :source_map => { :filename => input[:filename] } } terser = ::Terser.new(@options.merge()) 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 |