module Sinatra::AssetPack::Builder

Public Instance Methods

build!(&blk) click to toggle source
# File lib/sinatra/assetpack/builder.rb, line 4
def build!(&blk)
  build_packages!
  build_files!
end
build_files!(&blk) click to toggle source
# File lib/sinatra/assetpack/builder.rb, line 13
def build_files!(&blk)
  files.each { |path, local| build_file!(path, local, &blk) }
end
build_packages!(&blk) click to toggle source
# File lib/sinatra/assetpack/builder.rb, line 9
def build_packages!(&blk)
  packages.each { |_, pack| build_package!(pack, &blk) }
end

Private Instance Methods

build_file!(path, local, &blk) click to toggle source
# File lib/sinatra/assetpack/builder.rb, line 30
def build_file!(path, local, &blk)
  response = build_get(path)
  build_write(path, response, &blk)
  build_write(BusterHelpers.add_cache_buster(path, local), response, &blk)
end
build_get(path, &blk) click to toggle source
# File lib/sinatra/assetpack/builder.rb, line 19
def build_get(path, &blk)
  @session ||= Rack::Test::Session.new app
  @session.get(path)
end
build_package!(pack, &blk) click to toggle source
# File lib/sinatra/assetpack/builder.rb, line 24
def build_package!(pack, &blk)
  response = build_get(pack.path)
  build_write(pack.path, response, &blk)
  build_write(pack.production_path, response, &blk)
end
build_write(path, response) { |path| ... } click to toggle source
# File lib/sinatra/assetpack/builder.rb, line 36
def build_write(path, response, &blk)
  require 'fileutils'

  mtime = Time.parse(response.headers['Last-Modified']) if response.headers['Last-Modified']
  path = File.join(@output_path, path)

  yield path if block_given?

  FileUtils.mkdir_p(File.dirname(path))
  File.open(path, 'wb') { |f| f.write(response.body) }
  File.utime(mtime, mtime, path) if mtime
end