module RackPipeline::Sinatra::Helpers

Public Instance Methods

cache_buster(file) click to toggle source
# File lib/rack-pipeline/sinatra.rb, line 30
def cache_buster(file)
  compress = respond_to?(:settings) && settings.respond_to?(:pipeline) && settings.pipeline[:compress]
  if !compress && File.file?(file)
    "?#{File.mtime(file).to_i}"
  else
    temp = @pipeline_object.ensure_temp_directory
    max_mtime = 0
    Dir.glob(File.join(temp, File.basename(file,'.*') << '.*' << File.extname(file))).each do |cached_file|
      mtime = File.mtime(cached_file).to_i
      max_mtime = mtime if mtime > max_mtime
    end
    max_mtime = Time.now.to_i if max_mtime == 0
    "?#{max_mtime}"
  end
end
pipe_tag(type, asset, bust_cache=nil) click to toggle source
# File lib/rack-pipeline/sinatra.rb, line 20
def pipe_tag(type, asset, bust_cache=nil)
  asset += cache_buster(asset) if bust_cache
  case type.to_sym
  when :css
    %(<link href="#{request.script_name}/#{asset}" rel="stylesheet">)
  when :js
    %(<script src="#{request.script_name}/#{asset}"></script>)
  end
end
pipeline(pipes = [ :app ], types = [ :css, :js ], options = {}) click to toggle source
# File lib/rack-pipeline/sinatra.rb, line 9
def pipeline(pipes = [ :app ], types = [ :css, :js ], options = {})
  bust_cache = respond_to?(:settings) && settings.respond_to?(:pipeline) && settings.pipeline[:bust_cache]
  @pipeline_object = env['rack-pipeline']
  Array(types).map do |type|
    assets = @pipeline_object.assets_for(pipes, type, options)
    assets.map do |asset|
      pipe_tag(type, asset + options[:postfix].to_s, bust_cache)
    end.join("\n")
  end.join("\n")
end