Module: ViewFu::TagHelper
- Defined in:
- lib/view_fu/tag_helper.rb
Instance Method Summary collapse
-
#add_class(css_class, options = {}) ⇒ Object
provides a slick way to add classes inside haml attribute collections.
- #add_class_if(css_class, condition) ⇒ Object
- #add_class_unless(css_class, condition) ⇒ Object
-
#anchor(anchor_name, options = {}) ⇒ Object
Writes an anchor tag.
-
#auto_discovery_link_tag(type = :rss, url = nil, tag_options = {}) ⇒ Object
ported from rails.
-
#br ⇒ Object
Writes a br tag.
-
#clear(direction = nil) ⇒ Object
Writes a clear div tag.
-
#clear_tag(tag, direction = nil) ⇒ Object
Writes a clear tag.
-
#clearbit_icon(icon, color, options = {}) ⇒ Object
clearbit icons.
- #current_year ⇒ Object
-
#delete_link(*args) ⇒ Object
Wrap a delete link.
-
#hide(options = {}) ⇒ Object
(also: #hidden)
Return a hidden attribute hash (useful in Haml tags - %div#hidden).
-
#hide_if(condition) ⇒ Object
(also: #hidden_if, #show_unless)
Return a hidden attribute hash if a condition evaluates to true.
-
#hide_unless(condition) ⇒ Object
(also: #hidden_unless, #show_if)
Return a hidden attribute hash if a condition evaluates to false.
-
#hr ⇒ Object
Writes an hr tag.
-
#is_first(i) ⇒ Object
check to see if an index is the first item in a collection.
-
#link_to_block(*args, &block) ⇒ Object
Wrap a block with a link.
-
#lorem ⇒ Object
Return some lorem text.
-
#nbsp ⇒ Object
Writes a nonbreaking space.
-
#paging(page_data, style = :sabros) ⇒ Object
Display will_paginate paging links.
-
#parent_layout(layout, &block) ⇒ Object
Allows Easy Nested Layouts in Merb.
-
#partial_block(template, options = {}, &block) ⇒ Object
Calls a Merb Partial with a block, which you can catch content from.
-
#pixel(options = {}) ⇒ Object
pixel spacing helper.
-
#production? ⇒ Boolean
Check if we’re on production environment.
-
#space ⇒ Object
Writes an hr space tag.
Instance Method Details
#add_class(css_class, options = {}) ⇒ Object
provides a slick way to add classes inside haml attribute collections
examples:
%div{add_class("current")}
#=> adds the "current" class to the div
%div{add_class("current", :if => current?)}
#=> adds the "current" class to the div if current? method
%div{add_class("highlight", :unless => logged_in?)}
#=> adds the "highlight" class to the div unless logged_in? method returns true
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/view_fu/tag_helper.rb', line 129 def add_class(css_class, = {}) return {} unless css_class if .has_key?(:unless) if [:unless] return {} else return {:class => css_class} end end if .has_key?(:if) if [:if] return {:class => css_class} else return {} end end {:class => css_class} end |
#add_class_if(css_class, condition) ⇒ Object
151 152 153 |
# File 'lib/view_fu/tag_helper.rb', line 151 def add_class_if(css_class, condition) add_class(css_class, :if => condition) end |
#add_class_unless(css_class, condition) ⇒ Object
155 156 157 |
# File 'lib/view_fu/tag_helper.rb', line 155 def add_class_unless(css_class, condition) add_class(css_class, :unless => condition) end |
#anchor(anchor_name, options = {}) ⇒ Object
Writes an anchor tag
89 90 91 92 93 |
# File 'lib/view_fu/tag_helper.rb', line 89 def anchor(anchor_name, = {}) tag(:a, .merge(:name => anchor_name)) do "" end end |
#auto_discovery_link_tag(type = :rss, url = nil, tag_options = {}) ⇒ Object
ported from rails
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/view_fu/tag_helper.rb', line 66 def auto_discovery_link_tag(type = :rss, url = nil, = {}) # theres gotta be a better way of setting mimetype for a file extensionin Merb.. unless [:type] if type.to_s == "rss" [:type] = "application/rss+xml" elsif type.to_s == "atom" [:type] = "application/atom+xml" end end tag(:link, :rel => ([:rel] || "alternate"), :type => [:type].to_s, :title => ([:title] || type.to_s.upcase), :href => (url || "#")) end |
#br ⇒ Object
Writes a br tag
51 52 53 |
# File 'lib/view_fu/tag_helper.rb', line 51 def br "<br />" end |
#clear(direction = nil) ⇒ Object
Writes a clear div tag
109 110 111 |
# File 'lib/view_fu/tag_helper.rb', line 109 def clear(direction = nil) clear_tag(:div, direction) end |
#clear_tag(tag, direction = nil) ⇒ Object
Writes a clear tag
96 97 98 99 100 101 102 |
# File 'lib/view_fu/tag_helper.rb', line 96 def clear_tag(tag, direction = nil) if tag == :br "<br class=\"clear#{direction}\" />" else "<#{tag} class=\"clear#{direction}\"></#{tag}>" end end |
#clearbit_icon(icon, color, options = {}) ⇒ Object
clearbit icons
212 213 214 |
# File 'lib/view_fu/tag_helper.rb', line 212 def clearbit_icon(icon, color, = {}) image_tag "clearbits/#{icon}.gif", {:class => "clearbits #{color}", :alt => icon}.merge() end |
#current_year ⇒ Object
104 105 106 |
# File 'lib/view_fu/tag_helper.rb', line 104 def current_year Time.now.strftime("%Y") end |
#delete_link(*args) ⇒ Object
Wrap a delete link
188 189 190 191 192 |
# File 'lib/view_fu/tag_helper.rb', line 188 def delete_link(*args) = {:method => :delete, :confirm => "Are you sure you want to delete this?"}.merge((args)||{}) args << link_to(*args) end |
#hide(options = {}) ⇒ Object Also known as:
Return a hidden attribute hash (useful in Haml tags - %div#hidden)
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/view_fu/tag_helper.rb', line 160 def hide( = {}) if .has_key?(:unless) && [:unless] return {} end if .has_key?(:if) && ![:if] return {} end {:style => "display:none"} end |
#hide_if(condition) ⇒ Object Also known as: show_unless ,
Return a hidden attribute hash if a condition evaluates to true
174 175 176 |
# File 'lib/view_fu/tag_helper.rb', line 174 def hide_if(condition) hide(:if => condition) end |
#hide_unless(condition) ⇒ Object Also known as: show_if ,
Return a hidden attribute hash if a condition evaluates to false
181 182 183 |
# File 'lib/view_fu/tag_helper.rb', line 181 def hide_unless(condition) hide(:unless => condition) end |
#hr ⇒ Object
Writes an hr tag
56 57 58 |
# File 'lib/view_fu/tag_helper.rb', line 56 def hr "<hr />" end |
#is_first(i) ⇒ Object
check to see if an index is the first item in a collection
222 223 224 |
# File 'lib/view_fu/tag_helper.rb', line 222 def is_first(i) i.to_i.zero? ? {:class => "first"} : {} end |
#link_to_block(*args, &block) ⇒ Object
Wrap a block with a link
195 196 197 198 |
# File 'lib/view_fu/tag_helper.rb', line 195 def link_to_block(*args, &block) content = capture(&block) return link_to(content, *args) end |
#lorem ⇒ Object
Return some lorem text
114 115 116 |
# File 'lib/view_fu/tag_helper.rb', line 114 def lorem "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." end |
#nbsp ⇒ Object
Writes a nonbreaking space
61 62 63 |
# File 'lib/view_fu/tag_helper.rb', line 61 def nbsp " " end |
#paging(page_data, style = :sabros) ⇒ Object
Display will_paginate paging links
206 207 208 209 |
# File 'lib/view_fu/tag_helper.rb', line 206 def paging(page_data, style = :sabros) return unless page_data.is_a? WillPaginate::Collection will_paginate(page_data, :class => "pagination #{style}", :inner_window => 3) end |
#parent_layout(layout, &block) ⇒ Object
Allows Easy Nested Layouts in Merb
Usage Example:
Parent Layout: layout/application.html.erb
<html>
<head>
<title>Title</title>
</head>
<body>
<%= catch_content %>
</body>
</html>
SubLayout: layout/alternate.html.erb
<%= parent_layout “application” do %>
<div class="inner_layout">
<%= catch_content %>
</div>
<% end =%>
Now you can use the alternate layout in any of your views as normal and it will reuse the wrapping html on application.html.erb
46 47 48 |
# File 'lib/view_fu/tag_helper.rb', line 46 def parent_layout(layout, &block) render capture(&block), :layout => layout end |
#partial_block(template, options = {}, &block) ⇒ Object
Calls a Merb Partial with a block, which you can catch content from
Usage Example: <%= partial_block :fieldset, :legend => “Login” do %>
.. inner partial content
<% end =%>
Associated Partial (_fieldset.html.erb) <fieldset>
<legend><%= locals[:legend] %></legend>
<%= catch_content %>
</fieldset>
16 17 18 19 |
# File 'lib/view_fu/tag_helper.rb', line 16 def partial_block(template, ={}, &block) throw_content(:for_layout, block_given? ? capture(&block) : "") partial(template, ) end |
#pixel(options = {}) ⇒ Object
pixel spacing helper
217 218 219 |
# File 'lib/view_fu/tag_helper.rb', line 217 def pixel( = {}) image_tag "pixel.png", end |
#production? ⇒ Boolean
Check if we’re on production environment
201 202 203 |
# File 'lib/view_fu/tag_helper.rb', line 201 def production? Merb.env?(:production) end |
#space ⇒ Object
Writes an hr space tag
84 85 86 |
# File 'lib/view_fu/tag_helper.rb', line 84 def space "<hr class='space' />" end |