Module: Mack::ViewHelpers::HtmlHelpers
- 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)) %>.
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>
10 11 12 13 14 15 16 17 18 |
# File 'lib/mack/view_helpers/html_helpers.rb', line 10 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
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mack/view_helpers/html_helpers.rb', line 41 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.
30 31 32 33 |
# File 'lib/mack/view_helpers/html_helpers.rb', line 30 def img(image_src, = {}) 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%" />
25 26 27 |
# File 'lib/mack/view_helpers/html_helpers.rb', line 25 def non_content_tag(tag, = {}) "<#{tag}#{()} />" end |
#rss_tag(url) ⇒ Object
Example:
<%= rss_tag(posts_index_url(:format => :xml)) %>
37 38 39 |
# File 'lib/mack/view_helpers/html_helpers.rb', line 37 def rss_tag(url) "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"#{url}\">" end |