Class: Hanami::Assets::Compressors::Javascript Private

Inherits:
Abstract
  • Object
show all
Defined in:
lib/hanami/assets/compressors/javascript.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Base class for JavaScript compressors

Since:

  • 0.1.0

Class Method Summary collapse

Methods inherited from Abstract

#compress

Class Method Details

.for(engine_name) ⇒ Hanami::Assets::Compressors::Abstract

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Factory for Javascript compressors.

It loads a compressor for the given name.

Examples:

Basic Usage

require 'hanami/assets'
require 'hanami/assets/compressors/javascript'

Hanami::Assets::Compressors::Javascript.for(:closure)
  # => #<Hanami::Assets::Compressors::ClosureJavascript:0x007fa32a32e108 ...>

Null Compressor

require 'hanami/assets'
require 'hanami/assets/compressors/javascript'

Hanami::Assets::Compressors::Javascript.for(nil)
  # => #<Hanami::Assets::Compressors::NullCompressor:0x007fa32a314258>

Custom Compressor

require 'hanami/assets'
require 'hanami/assets/compressors/javascript'

class CustomJavascriptCompressor
  def compress(filename)
    # ...
  end
end

Hanami::Assets::Compressors::Javascript.for(CustomJavascriptCompressor.new)
  # => #<CustomJavascriptCompressor:0x007fa32a2cdf10>

Third Party Compressor

require 'hanami/assets'
require 'hanami/assets/compressors/javascript'
require 'hanami/foo/compressor' # third party gem

Hanami::Assets::Compressors::Javascript.for(:foo)
  # => #<Hanami::Assets::Compressors::FooJavascript:0x007fa3dd9ed968>

Unknown Engine

require 'hanami/assets'
require 'hanami/assets/compressors/javascript'

Hanami::Assets::Compressors::Javascript.for(:wat)
  # => Hanami::Assets::Compressors::UnknownCompressorError: Unknown Javascript compressor: :wat

Parameters:

  • engine_name (Symbol, String, NilClass, #compress)

    the name of the engine to load or an instance of an engine

Returns:

Raises:

See Also:

Since:

  • 0.1.0



71
72
73
# File 'lib/hanami/assets/compressors/javascript.rb', line 71

def self.for(engine_name)
  super
end