Module: Locomotive::Liquid::Filters::Html

Defined in:
lib/locomotive/liquid/filters/html.rb

Instance Method Summary collapse

Instance Method Details

Return a link tag that browsers and news readers can use to auto-detect an RSS or ATOM feed. input: url of the feed example:

{{ '/foo/bar' | auto_discovery_link_tag: 'rel:alternate', 'type:application/atom+xml', 'title:A title' }}


10
11
12
13
14
15
16
17
18
# File 'lib/locomotive/liquid/filters/html.rb', line 10

def auto_discovery_link_tag(input, *args)
  options = args_to_options(args)

  rel   = options[:rel] || 'alternate'
  type  = options[:type] || Mime::Type.lookup_by_extension('rss').to_s
  title = options[:title] || 'RSS'

  %{<link rel="#{rel}" type="#{type}" title="#{title}" href="#{input}">}
end

#flash_tag(input, *args) ⇒ Object

Embed a flash movie into a page input: url of the flash movie OR asset drop width: width (in pixel or in %) of the embedded movie height: height (in pixel or in %) of the embedded movie



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/locomotive/liquid/filters/html.rb', line 99

def flash_tag(input, *args)
  path = get_url_from_asset(input)
  embed_options = inline_options(args_to_options(args))
  %{
    <object #{embed_options}>
      <param name="movie" value="#{path}">
      <embed src="#{path}" #{embed_options}>
      </embed>
    </object>
  }.gsub(/ >/, '>').strip
end

#image_tag(input, *args) ⇒ Object

Write an image tag input: url of the image OR asset drop



89
90
91
92
93
# File 'lib/locomotive/liquid/filters/html.rb', line 89

def image_tag(input, *args)
  image_options = inline_options(args_to_options(args))

  "<img src=\"#{get_url_from_asset(input)}\" #{image_options}>"
end

#javascript_tag(input, *args) ⇒ Object

Write the link to javascript resource input: url of the javascript file



62
63
64
65
66
67
68
# File 'lib/locomotive/liquid/filters/html.rb', line 62

def javascript_tag(input, *args)
  return '' if input.nil?
  javascript_options = inline_options(args_to_options(args))
  input = javascript_url(input)

  "<script src=\"#{input}\" type=\"text/javascript\" #{javascript_options}></script>"
end

#javascript_url(input) ⇒ Object

Write the url to javascript resource input: name of the javascript file



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/locomotive/liquid/filters/html.rb', line 47

def javascript_url(input)
  return '' if input.nil?

  if input =~ /^(\/|https?:)/
    uri = URI(input)
  else
    uri = URI(asset_url("javascripts/#{input}"))
  end

  uri.path = "#{uri.path}.js" unless uri.path.ends_with?('.js')
  uri.to_s
end

#stylesheet_tag(input, media = 'screen') ⇒ Object

Write the link tag of a theme stylesheet input: url of the css file



37
38
39
40
41
42
43
# File 'lib/locomotive/liquid/filters/html.rb', line 37

def stylesheet_tag(input, media = 'screen')
  return '' if input.nil?

  input = stylesheet_url(input)

  %{<link href="#{input}" media="#{media}" rel="stylesheet" type="text/css">}
end

#stylesheet_url(input) ⇒ Object

Write the url of a theme stylesheet input: name of the css file



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/locomotive/liquid/filters/html.rb', line 22

def stylesheet_url(input)
  return '' if input.nil?

  if input =~ /^(\/|https?:)/
    uri = URI(input)
  else
    uri = URI(asset_url("stylesheets/#{input}"))
  end

  uri.path = "#{uri.path}.css" unless uri.path.ends_with?('.css')
  uri.to_s
end

#theme_image_tag(input, *args) ⇒ Object

Write a theme image tag input: name of file including folder example: ‘about/myphoto.jpg’ | theme_image # <img src=“images/about/myphoto.jpg”>



81
82
83
84
85
# File 'lib/locomotive/liquid/filters/html.rb', line 81

def theme_image_tag(input, *args)
  image_options = inline_options(args_to_options(args))

  "<img src=\"#{theme_image_url(input)}\" #{image_options}>"
end

#theme_image_url(input) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/locomotive/liquid/filters/html.rb', line 70

def theme_image_url(input)
  return '' if input.nil?

  input = "images/#{input}" unless input.starts_with?('/')

  asset_url(input)
end