Module: Sinatra::StaticAssets::Helpers

Defined in:
lib/sinatra/static_assets.rb

Constant Summary collapse

@@asset_timestamps_cache =
{}

Instance Method Summary collapse

Instance Method Details

#image_tag(source, options = {}) ⇒ Object

In HTML <link> and <img> tags have no end tag. In XHTML, on the contrary, these tags must be properly closed.

We can choose the appropriate behaviour with closed option:

image_tag "/images/foo.png", :alt => "Foo itself", :closed => true

The default value of closed option is false.



19
20
21
22
# File 'lib/sinatra/static_assets.rb', line 19

def image_tag(source, options = {})
  options[:src] = url_for(source)
  tag("img", options)
end

#javascript_script_tag(*sources) ⇒ Object Also known as: javascript_include_tag



29
30
31
32
# File 'lib/sinatra/static_assets.rb', line 29

def javascript_script_tag(*sources)
  list, options = extract_options(sources)
  list.collect { |source| javascript_tag(source, options) }.join("\n")
end


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sinatra/static_assets.rb', line 42

def link_favicon_tag(source = nil, options = {})
  source = "favicon.ico" if source.nil? or source.empty?
  unless settings.xhtml
    # html5 style like <link rel="icon" href="http://example.com/myicon.ico" />
    options[:rel] = options[:rel] || "icon"
  else
    # xhtml style like <link rel="shortcut icon" href="http://example.com/myicon.ico" />
    options[:rel] = "shortcut icon"
  end
  options[:href] = url_for(source)
  tag("link", options)
end


36
37
38
39
40
# File 'lib/sinatra/static_assets.rb', line 36

def link_to(desc, url, options = {})
  tag("a", options.merge(:href => url_for(url))) do
    desc
  end
end


24
25
26
27
# File 'lib/sinatra/static_assets.rb', line 24

def stylesheet_link_tag(*sources)
  list, options = extract_options(sources)
  list.collect { |source| stylesheet_tag(source, options) }.join("\n")
end