module Asset::Helpers
Public Instance Methods
asset_url(path)
click to toggle source
Asset
URL
# File lib/assets/helpers.rb, line 5 def asset_url(path) ::Asset.manifest.find{|i| i.path == path}.src rescue path end
image_tag(path)
click to toggle source
Image tags
# File lib/assets/helpers.rb, line 24 def image_tag(path) %{<img src="#{image_url(path)}">} end
image_url(path)
click to toggle source
Image URL
# File lib/assets/helpers.rb, line 29 def image_url(path) # Just slip through if the path starts with http(s) or // src = path =~ /^(http[s]?)?:?\/\// ? path : %{/images/#{path}} # Return the path with timestamp if possible %{#{src}#{(b = (::Asset.images[path] rescue nil)) ? "?#{b}" : ''}} end
script_tag(*paths)
click to toggle source
Script tags
# File lib/assets/helpers.rb, line 10 def script_tag(*paths) tag('js', *paths) do |src| %{<script src="#{src}"></script>} end end
style_tag(*paths)
click to toggle source
Style tags
# File lib/assets/helpers.rb, line 17 def style_tag(*paths) tag('css', *paths) do |src| %{<link href="#{src}" media="all" rel="stylesheet" type="text/css">} end end
Private Instance Methods
tag(type, *paths) { |asset_url(f)| ... }
click to toggle source
Build the tags
# File lib/assets/helpers.rb, line 40 def tag(type, *paths, &block) paths.map do |path| # Yield the source back to the tag builder item = ::Asset.manifest.find{|i| i.path == path} # Src is same as path if item not found item ? item.sources.map{|f| yield(asset_url(f))} : yield(path) end.flatten.join("\n") end