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 arrow 10
//= position another-image right
//= spacing 5

To this:

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

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#_call(input) ⇒ Object



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

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



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

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