Logo: Relish

  1. Sign in

Project: Pannier v0.2.0

Asset modification

In order that my assets are optimised for production
As a developer
I want to modify the content and filenames of my assets

Scenarios
Assets modified by modify block
Given
the file "input/qux.js" contains
/* comment */
And
the file ".assets.rb" contains
input  'input'
output 'output'

package :foo do
  assets '*.js'
  modify do |content, basename|
    [content.reverse, basename]
  end
end
When
the app is loaded
And
the app has been processed
Then
the file "output/qux.js" should contain
/* tnemmoc */
Assets modified by modifier
Given
the file "input/qux.js" contains
/* comment */
And
a loaded ruby file contains
class Exclaimifier
  def call(content, basename)
    [content.gsub(/(\w+)/, '\1!'), basename]
  end
end
And
a loaded ruby file contains
class Suffixer
  def initialize(suffix)
    @suffix = suffix
  end

  def call(content, basename)
    ext = File.extname(basename)
    base = File.basename(basename, ext)
    [content, "#{base}-#{@suffix}#{ext}"]
  end
end
And
the file ".assets.rb" contains
input  'input'
output 'output'

package :foo do
  assets '*.js'
  modify Exclaimifier.new, Suffixer.new('abcde')
end
When
the app is loaded
And
the app has been processed
Then
the file "output/qux-abcde.js" should contain
/* comment! */

Last published almost 4 years ago by joecorcoran.