Module: RackPipeline::Sinatra::Helpers
- Defined in:
- lib/rack-pipeline/sinatra.rb
Instance Method Summary collapse
- #cache_buster(file) ⇒ Object
- #pipe_tag(type, asset, bust_cache = nil) ⇒ Object
- #pipeline(pipes = [ :app ], types = [ :css, :js ], options = {}) ⇒ Object
Instance Method Details
#cache_buster(file) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# 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 = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rack-pipeline/sinatra.rb', line 9 def pipeline(pipes = [ :app ], types = [ :css, :js ], = {}) 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, ) assets.map do |asset| pipe_tag(type, asset + [:postfix].to_s, bust_cache) end.join("\n") end.join("\n") end |