Class: Spritely::Sprockets::Preprocessor

Inherits:
Sprockets::DirectiveProcessor
  • Object
show all
Defined in:
lib/spritely/sprockets/preprocessor.rb

Overview

Converts Sprockets directives from this:

//= directory foo/bar
//= repeat arrow true
//= spacing-below arrow 10
//= position another-image right
//= spacing-above 5
//= spacing-below 5

To this:

{
  directory: 'foo/bar',
  global: { spacing_above: '5', spacing_below: '5' },
  images: {
    'arrow' => { repeat: 'true', spacing_above: '10', spacing_below: '5' },
    'another-image' => { position: 'right', spacing_above: '5', spacing_below: '5' }
  }
}

Constant Summary collapse

GLOBAL_DIRECTIVES =
%w(position spacing spacing-above spacing-below).freeze
IMAGE_DIRECTIVES =
%w(repeat position spacing spacing-above spacing-below).freeze

Instance Method Summary collapse

Instance Method Details

#_call(input) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/spritely/sprockets/preprocessor.rb', line 28

def _call(input)
  @sprite_directives = { directory: nil, global: {}, images: {} }

  super.tap do
    merge_global_options!

    input[:metadata][:sprite_directives] = @sprite_directives
  end
end

#process_directory_directive(value) ⇒ Object



38
39
40
# File 'lib/spritely/sprockets/preprocessor.rb', line 38

def process_directory_directive(value)
  @sprite_directives[:directory] = value
end