Module: Mack::ViewHelpers::HtmlHelpers

Includes:
Assets
Defined in:
lib/mack/view_helpers/html_helpers.rb

Instance Method Summary collapse

Methods included from Assets

#get_resource_root

Instance Method Details

#content_tag(tag, options = {}, content = nil, &block) ⇒ Object

Builds an HTML tag.

Examples:

(:b) {"hello"} # => <b>hello</b>
("div", :class => :foo) {"hello world!"} # => <div class="foo">hello world!</div>


11
12
13
14
15
16
17
18
19
# File 'lib/mack/view_helpers/html_helpers.rb', line 11

def (tag, options = {}, content = nil, &block)
  if block_given?
    concat("<#{tag}#{build_options(options)}>\n", block.binding)
    yield
    concat("\n</#{tag}>", block.binding)
  else
     "<#{tag}#{build_options(options)}>#{content}</#{tag}>"
  end
end

#google_analytics(id) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mack/view_helpers/html_helpers.rb', line 52

def google_analytics(id)
  %{
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("#{id}");
pageTracker._trackPageview();
</script>}.strip
end

#img(image_src, options = {}) ⇒ Object

Builds a HTML image tag.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/mack/view_helpers/html_helpers.rb', line 31

def img(image_src, options = {})
  image_src = case image_src.to_s
  when /^\/images/
    image_src
  when /^images/
    '/' + image_src
  when /^\//
    image_src
  else
    '/images/' + image_src
  end
  image_src = "#{get_resource_root(image_src)}#{image_src}?#{configatron.mack.assets.stamp}"
  (:img, {:src => image_src}.merge(options))
end

#non_content_tag(tag, options = {}) ⇒ Object

Builds an HTML tag with no content.

Examples:

(:br) # => <br />
(:hr, :width => "100%") # => <hr width="100%" />


26
27
28
# File 'lib/mack/view_helpers/html_helpers.rb', line 26

def (tag, options = {})
  "<#{tag}#{build_options(options)} />"
end

#rss_tag(url) ⇒ Object

Example:

<%= rss_tag(posts_index_url(:format => :xml)) %>


48
49
50
# File 'lib/mack/view_helpers/html_helpers.rb', line 48

def rss_tag(url)
  "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"#{url}\">"
end