Module: RackPipeline::Sinatra::Helpers
- Defined in:
- lib/rack-pipeline/sinatra.rb
Instance Method Summary collapse
- #cache_buster(file) ⇒ Object
- #pipe_tag(type, asset) ⇒ Object
- #pipeline(pipes = [ :app ], types = [ :css, :js ], opts = {}) ⇒ Object
Instance Method Details
#cache_buster(file) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rack-pipeline/sinatra.rb', line 28 def cache_buster(file) if File.file?(file) "?#{File.mtime(file).to_i}" else temp = if respond_to?(:settings) && settings.respond_to?(:pipeline) && settings.pipeline[:temp] settings.pipeline[:temp] else require 'tmpdir' File.join(Dir.tmpdir, 'RackPipeline') end mtimes = [] Dir.glob(File.join(temp,file+'.*')).each do |cached_file| mtimes << File.mtime(cached_file).to_i end "?#{mtimes.max || Time.now.to_i}" end end |
#pipe_tag(type, asset) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/rack-pipeline/sinatra.rb', line 18 def pipe_tag(type, asset) asset += cache_buster(asset) 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 ], opts = {}) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/rack-pipeline/sinatra.rb', line 9 def pipeline(pipes = [ :app ], types = [ :css, :js ], opts = {}) Array(types).map do |type| assets = env['rack-pipeline'].assets_for(pipes, type, opts) assets.map do |asset| pipe_tag(type, asset) end.join("\n") end.join("\n") end |