Module: Sinatra::StaticAssets::Helpers
- Defined in:
- lib/sinatra/static_assets.rb
Constant Summary collapse
- @@asset_timestamps_cache =
{}
Instance Method Summary collapse
-
#image_tag(source, options = {}) ⇒ Object
In HTML <link> and <img> tags have no end tag.
- #javascript_script_tag(*sources) ⇒ Object (also: #javascript_include_tag)
- #link_favicon_tag(source = nil, options = {}) ⇒ Object
- #link_to(desc, url, options = {}) ⇒ Object
- #stylesheet_link_tag(*sources) ⇒ Object
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, = {}) [:src] = url_for(source) tag("img", ) 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, = (sources) list.collect { |source| javascript_tag(source, ) }.join("\n") end |
#link_favicon_tag(source = nil, options = {}) ⇒ Object
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, = {}) source = "favicon.ico" if source.nil? or source.empty? unless settings.xhtml # html5 style like <link rel="icon" href="http://example.com/myicon.ico" /> [:rel] = [:rel] || "icon" else # xhtml style like <link rel="shortcut icon" href="http://example.com/myicon.ico" /> [:rel] = "shortcut icon" end [:href] = url_for(source) tag("link", ) end |
#link_to(desc, url, options = {}) ⇒ Object
36 37 38 39 40 |
# File 'lib/sinatra/static_assets.rb', line 36 def link_to(desc, url, = {}) tag("a", .merge(:href => url_for(url))) do desc end end |
#stylesheet_link_tag(*sources) ⇒ Object
24 25 26 27 |
# File 'lib/sinatra/static_assets.rb', line 24 def stylesheet_link_tag(*sources) list, = (sources) list.collect { |source| stylesheet_tag(source, ) }.join("\n") end |