Module: Mack::ViewHelpers::HtmlHelpers
- Includes:
- Assets
- Defined in:
- lib/mack/view_helpers/html_helpers.rb
Instance Method Summary collapse
-
#content_tag(tag, options = {}, content = nil, &block) ⇒ Object
Builds an HTML tag.
- #google_analytics(id) ⇒ Object
-
#img(image_src, options = {}) ⇒ Object
Builds a HTML image tag.
-
#non_content_tag(tag, options = {}) ⇒ Object
Builds an HTML tag with no content.
-
#rss_tag(url) ⇒ Object
Example: <%= rss_tag(posts_index_url(:format => :xml)) %>.
Methods included from Assets
Instance Method Details
#content_tag(tag, options = {}, content = nil, &block) ⇒ Object
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>
11 12 13 14 15 16 17 18 19 |
# File 'lib/mack/view_helpers/html_helpers.rb', line 11 def content_tag(tag, = {}, content = nil, &block) if block_given? concat("<#{tag}#{()}>\n", block.binding) yield concat("\n</#{tag}>", block.binding) else "<#{tag}#{()}>#{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, = {}) 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}" non_content_tag(:img, {:src => image_src}.merge()) end |
#non_content_tag(tag, options = {}) ⇒ Object
Builds an HTML tag with no content.
Examples:
non_content_tag(:br) # => <br />
non_content_tag(:hr, :width => "100%") # => <hr width="100%" />
26 27 28 |
# File 'lib/mack/view_helpers/html_helpers.rb', line 26 def non_content_tag(tag, = {}) "<#{tag}#{()} />" 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 |