| Module | Mack::ViewHelpers::HtmlHelpers |
| In: |
lib/mack/view_helpers/html_helpers.rb
|
Builds an HTML tag.
Examples:
content_tag(:b) {"hello"} # => <b>hello</b>
content_tag("div", :class => :foo) {"hello world!"} # => <div class="foo">hello world!</div>
# File lib/mack/view_helpers/html_helpers.rb, line 11
11: def content_tag(tag, options = {}, content = nil, &block)
12: if block_given?
13: concat("<#{tag}#{build_options(options)}>\n", block.binding)
14: yield
15: concat("\n</#{tag}>", block.binding)
16: else
17: "<#{tag}#{build_options(options)}>#{content}</#{tag}>"
18: end
19: end
# File lib/mack/view_helpers/html_helpers.rb, line 52
52: def google_analytics(id)
53: %{
54: <script type="text/javascript">
55: var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
56: document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
57: </script>
58: <script type="text/javascript">
59: var pageTracker = _gat._getTracker("#{id}");
60: pageTracker._trackPageview();
61: </script>}.strip
62: end
Builds a HTML image tag.
# File lib/mack/view_helpers/html_helpers.rb, line 31
31: def img(image_src, options = {})
32: image_src = case image_src.to_s
33: when /^\/images/
34: image_src
35: when /^images/
36: '/' + image_src
37: when /^\//
38: image_src
39: else
40: '/images/' + image_src
41: end
42: image_src = "#{get_resource_root(image_src)}#{image_src}?#{configatron.mack.assets.stamp}"
43: non_content_tag(:img, {:src => image_src}.merge(options))
44: end
Builds an HTML tag with no content.
Examples:
non_content_tag(:br) # => <br /> non_content_tag(:hr, :width => "100%") # => <hr width="100%" />
# File lib/mack/view_helpers/html_helpers.rb, line 26
26: def non_content_tag(tag, options = {})
27: "<#{tag}#{build_options(options)} />"
28: end