module Sinatra::AssetHelpers::Helpers
Public Instance Methods
asset_url_for(filename)
click to toggle source
# File lib/sinatra/asset_helpers.rb, line 7 def asset_url_for(filename) return filename if filename =~ /^http|https|\// halt 500, "Invalid path (#{settings.manifest_path}) to manifest.json" unless File.exists? settings.manifest_path filepath = filename.split('/') filename = filepath.pop manifest = Oj.load(File.open(settings.manifest_path, 'r')) asset_url = [(settings.assets_host || ''), settings.assets_path, filepath, manifest[filename]].flatten.join('/') puts asset_url asset_url end
image_tag(filename, alt = '', title = '')
click to toggle source
# File lib/sinatra/asset_helpers.rb, line 27 def image_tag(filename, alt = '', title = '') %Q(<img src="#{asset_url_for(filename)}" alt="#{alt}" title="#{title}">) end
javascript_tag(filename)
click to toggle source
# File lib/sinatra/asset_helpers.rb, line 23 def javascript_tag(filename) %Q(<script src="#{asset_url_for(filename)}"></script>) end
stylesheet_tag(filename, media = 'screen')
click to toggle source
# File lib/sinatra/asset_helpers.rb, line 19 def stylesheet_tag(filename, media = 'screen') %Q(<link href="#{asset_url_for(filename)}" media="#{media}" rel="stylesheet">) end