Module: Sinatra::Sprockets::Helpers
- Defined in:
- lib/sinatra/sprockets/helpers.rb,
lib/sinatra/sprockets/asset_paths.rb
Defined Under Namespace
Classes: AssetPaths
Instance Method Summary collapse
- #asset_path(source, options = {}) ⇒ Object
- #image_path(source, options = {}) ⇒ Object
- #javascript_include_tag(*sources) ⇒ Object
- #javascript_path(source, options = {}) ⇒ Object
- #stylesheet_link_tag(*sources) ⇒ Object
- #stylesheet_path(source, options = {}) ⇒ Object
Instance Method Details
#asset_path(source, options = {}) ⇒ Object
3 4 5 6 7 |
# File 'lib/sinatra/sprockets/helpers.rb', line 3 def asset_path source, = {} source = source.logical_path if source.respond_to?(:logical_path) path = asset_paths.compute_public_path(source, config.prefix, .merge(:body => true)) [:body] ? "#{path}?body=1" : path end |
#image_path(source, options = {}) ⇒ Object
9 10 11 |
# File 'lib/sinatra/sprockets/helpers.rb', line 9 def image_path source, = {} asset_path source, { dir: 'images' }.merge() end |
#javascript_include_tag(*sources) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sinatra/sprockets/helpers.rb', line 21 def javascript_include_tag(*sources) debug = config.debug body = false digest = config.digest sources.collect do |source| if debug && asset = asset_paths.asset_for(source, 'js') asset.to_a.map do |dep| src = asset_path(dep, :ext => 'js', :body => true, :digest => digest) "<script src='#{src}' type='text/javascript'></script>" end else src = asset_path(source, :ext => 'js', :body => body, :digest => digest) "<script src='#{src}' type='text/javascript'></script>" end end.join("\n") end |
#javascript_path(source, options = {}) ⇒ Object
13 14 15 |
# File 'lib/sinatra/sprockets/helpers.rb', line 13 def javascript_path source, = {} asset_path source, { dir: 'javascripts', ext: 'js' }.merge() end |
#stylesheet_link_tag(*sources) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/sinatra/sprockets/helpers.rb', line 39 def stylesheet_link_tag(*sources) debug = config.debug body = false digest = config.digest sources.collect do |source| if debug && asset = asset_paths.asset_for(source, 'css') asset.to_a.map do |dep| href = asset_path(dep, :ext => 'css', :body => true, :protocol => :request, :digest => digest) "<link href='#{href}' media='screen' rel='stylesheet' type='text/css' />" end else href = asset_path(source, :ext => 'css', :body => body, :protocol => :request, :digest => digest) "<link href='#{href}' media='screen' rel='stylesheet' type='text/css' />" end end.join("\n") end |
#stylesheet_path(source, options = {}) ⇒ Object
17 18 19 |
# File 'lib/sinatra/sprockets/helpers.rb', line 17 def stylesheet_path source, = {} asset_path source, { dir: 'stylesheets', ext: 'css' }.merge() end |