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.
-
#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.
-
#pixel(options = {}) ⇒ Object
pixel spacing helper.
-
#production? ⇒ Boolean
Check if we’re on production environment.
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
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/view_fu/tag_helper.rb', line 57 def add_class(css_class, = {}) return {} unless css_class attributes = {:class => css_class} if .has_key?(:unless) return [:unless] ? {} : attributes end if .has_key?(:if) return [:if] ? attributes : {} end attributes end |
#add_class_if(css_class, condition) ⇒ Object
73 74 75 |
# File 'lib/view_fu/tag_helper.rb', line 73 def add_class_if(css_class, condition) add_class(css_class, :if => condition) end |
#add_class_unless(css_class, condition) ⇒ Object
77 78 79 |
# File 'lib/view_fu/tag_helper.rb', line 77 def add_class_unless(css_class, condition) add_class(css_class, :unless => condition) end |
#anchor(anchor_name, options = {}) ⇒ Object
Writes an anchor tag
19 20 21 |
# File 'lib/view_fu/tag_helper.rb', line 19 def anchor(anchor_name, = {}) content_tag(:a, "", .merge(:name => anchor_name)) end |
#br ⇒ Object
Writes a br tag
4 5 6 |
# File 'lib/view_fu/tag_helper.rb', line 4 def br "<br />".html_safe end |
#clear(direction = nil) ⇒ Object
Writes a clear div tag
37 38 39 |
# File 'lib/view_fu/tag_helper.rb', line 37 def clear(direction = nil) clear_tag(:div, direction) end |
#clear_tag(tag, direction = nil) ⇒ Object
Writes a clear tag
24 25 26 27 28 29 30 |
# File 'lib/view_fu/tag_helper.rb', line 24 def clear_tag(tag, direction = nil) if tag == :br "<br class=\"clear#{direction}\" />".html_safe else "<#{tag} class=\"clear#{direction}\"></#{tag}>".html_safe end end |
#clearbit_icon(icon, color, options = {}) ⇒ Object
clearbit icons
130 131 132 |
# File 'lib/view_fu/tag_helper.rb', line 130 def clearbit_icon(icon, color, = {}) image_tag "clearbits/#{icon}.gif", {:class => "clearbits #{color}", :alt => icon}.merge() end |
#current_year ⇒ Object
32 33 34 |
# File 'lib/view_fu/tag_helper.rb', line 32 def current_year Time.now.strftime("%Y") end |
#delete_link(*args) ⇒ Object
Wrap a delete link
112 113 114 115 116 |
# File 'lib/view_fu/tag_helper.rb', line 112 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)
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/view_fu/tag_helper.rb', line 82 def hide( = {}) attributes = {:style => "display:none"} if .has_key?(:unless) return [:unless] ? {} : attributes end if .has_key?(:if) return [:if] ? attributes : {} end attributes end |
#hide_if(condition) ⇒ Object Also known as: show_unless ,
Return a hidden attribute hash if a condition evaluates to true
98 99 100 |
# File 'lib/view_fu/tag_helper.rb', line 98 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
105 106 107 |
# File 'lib/view_fu/tag_helper.rb', line 105 def hide_unless(condition) hide(:unless => condition) end |
#hr ⇒ Object
Writes an hr tag
9 10 11 |
# File 'lib/view_fu/tag_helper.rb', line 9 def hr "<hr />".html_safe end |
#is_first(i) ⇒ Object
check to see if an index is the first item in a collection
140 141 142 |
# File 'lib/view_fu/tag_helper.rb', line 140 def is_first(i) i.to_i.zero? ? {:class => "first"} : {} end |
#link_to_block(*args, &block) ⇒ Object
Wrap a block with a link
119 120 121 122 |
# File 'lib/view_fu/tag_helper.rb', line 119 def link_to_block(*args, &block) content = capture(&block) return link_to(content, *args) end |
#lorem ⇒ Object
Return some lorem text
42 43 44 |
# File 'lib/view_fu/tag_helper.rb', line 42 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
14 15 16 |
# File 'lib/view_fu/tag_helper.rb', line 14 def nbsp " ".html_safe end |
#pixel(options = {}) ⇒ Object
pixel spacing helper
135 136 137 |
# File 'lib/view_fu/tag_helper.rb', line 135 def pixel( = {}) image_tag "pixel.png", end |
#production? ⇒ Boolean
Check if we’re on production environment
125 126 127 |
# File 'lib/view_fu/tag_helper.rb', line 125 def production? Rails.env.production? end |