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

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

Instance Method Summary collapse

Instance Method Details

Returns 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



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

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



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

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) ⇒ Object

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



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

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

  input = javascript_url(input)

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

#javascript_url(input) ⇒ Object

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



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

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

  unless input =~ /^(\/|https?:)/
    input = asset_url("javascripts/#{input}")
  end

  input = "#{input}.js" unless input.ends_with?('.js')

  input
end

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

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



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

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
# File 'lib/locomotive/liquid/filters/html.rb', line 22

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

  unless input =~ /^(\/|https?:)/
    input = asset_url("stylesheets/#{input}")
  end

  input = "#{input}.css" unless input.ends_with?('.css')

  input
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”>



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

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



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

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

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

  asset_url(input)
end