Module: Asset::Helpers

Included in:
Filters
Defined in:
lib/assets/helpers.rb

Instance Method Summary collapse

Instance Method Details

#asset_url(path) ⇒ Object

Asset URL



5
6
7
# 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) ⇒ Object

Image tags



24
25
26
# File 'lib/assets/helpers.rb', line 24

def image_tag(path)
  %{<img src="#{image_url(path)}">}
end

#image_url(path) ⇒ Object

Image URL



29
30
31
32
33
34
35
# 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) ⇒ Object

Script tags



10
11
12
13
14
# 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) ⇒ Object

Style tags



17
18
19
20
21
# 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