class Spritely::Sprockets::Preprocessor
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' } } }
Constants
- GLOBAL_DIRECTIVES
- IMAGE_DIRECTIVES
Public Instance Methods
_call(input)
click to toggle source
Calls superclass method
# 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)
click to toggle source
# File lib/spritely/sprockets/preprocessor.rb, line 38 def process_directory_directive(value) @sprite_directives[:directory] = value end
Private Instance Methods
check_if_deprecated_directive(directive)
click to toggle source
# File lib/spritely/sprockets/preprocessor.rb, line 75 def check_if_deprecated_directive(directive) if directive == 'spacing' Spritely.logger.warn "The `spacing` directive is deprecated and has been replaced by `spacing-below`. It will be removed in Spritely 3.0. (called from #{@filename})" end end
merge_global_options!()
click to toggle source
# File lib/spritely/sprockets/preprocessor.rb, line 69 def merge_global_options! @sprite_directives[:images].each do |image, options| options.merge!(@sprite_directives[:global]) { |key, left, right| left } end end
process_global_option(directive, value)
click to toggle source
# File lib/spritely/sprockets/preprocessor.rb, line 61 def process_global_option(directive, value) raise ArgumentError, "'#{directive}' is not a valid global option" unless GLOBAL_DIRECTIVES.include?(directive) check_if_deprecated_directive(directive) @sprite_directives[:global][directive.tr('-', '_').to_sym] = value end
process_image_option(directive, image, value)
click to toggle source
# File lib/spritely/sprockets/preprocessor.rb, line 54 def process_image_option(directive, image, value) check_if_deprecated_directive(directive) @sprite_directives[:images][image] ||= {} @sprite_directives[:images][image][directive.tr('-', '_').to_sym] = value end