Module: Sinatra::StaticAssets

Defined in:
lib/sinatra/static_assets.rb

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.



15
16
17
18
19
# File 'lib/sinatra/static_assets.rb', line 15

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

#javascript_script_tag(*sources) ⇒ Object



27
28
29
30
# File 'lib/sinatra/static_assets.rb', line 27

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


32
33
34
# File 'lib/sinatra/static_assets.rb', line 32

def link_to(desc, url)
  "<a href='#{url_for url}'>#{desc}</a>"
end


21
22
23
24
25
# File 'lib/sinatra/static_assets.rb', line 21

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