Module: ViewFu::TagHelper
- Defined in:
- lib/view_fu/tag_helper.rb
Instance Method Summary collapse
- #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.
-
#hidden ⇒ Object
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_edit? ⇒ Boolean
Check if we're on Edit or Update actions.
-
#is_first(i) ⇒ Object
check to see if an index is the first item in a collection.
-
#is_new? ⇒ Boolean
Check if we're on New or Create actions.
-
#link_to_block(*args, &block) ⇒ Object
Wrap a block with a link.
-
#link_to_image(image_path, label, url, options = {}) ⇒ Object
Easily link to an image.
-
#lorem ⇒ Object
Return some lorem text.
-
#nbsp ⇒ Object
Writes a nonbreaking space.
-
#paging(page_data, style = :sabros) ⇒ Object
Display will_paginate paging links.
-
#pixel(options = {}) ⇒ Object
pixel spacing helper.
-
#production? ⇒ Boolean
Check if we're on production environment.
-
#space ⇒ Object
Writes an hr space tag.
-
#use_cache? ⇒ Boolean
Whether or not to use caching.
Instance Method Details
#add_class_if(css_class, condition) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/view_fu/tag_helper.rb', line 75 def add_class_if(css_class, condition) if condition {:class => css_class} else {} end end |
#add_class_unless(css_class, condition) ⇒ Object
83 84 85 |
# File 'lib/view_fu/tag_helper.rb', line 83 def add_class_unless(css_class, condition) add_class_if(css_class, !condition) end |
#anchor(anchor_name, options = {}) ⇒ Object
Writes an anchor tag
25 26 27 28 29 |
# File 'lib/view_fu/tag_helper.rb', line 25 def anchor(anchor_name, = {}) content_tag(:a, {:name => anchor_name}.reverse_merge()) do "" end end |
#br ⇒ Object
Writes a br tag
5 6 7 |
# File 'lib/view_fu/tag_helper.rb', line 5 def br "<br />" end |
#clear(direction = nil) ⇒ Object
Writes a clear div tag
45 46 47 |
# File 'lib/view_fu/tag_helper.rb', line 45 def clear(direction = nil) clear_tag(:div, direction) end |
#clear_tag(tag, direction = nil) ⇒ Object
Writes a clear tag
32 33 34 35 36 37 38 |
# File 'lib/view_fu/tag_helper.rb', line 32 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
151 152 153 |
# File 'lib/view_fu/tag_helper.rb', line 151 def clearbit_icon(icon, color, = {}) image_tag "clearbits/#{icon}.gif", {:class => "clearbits #{color}", :alt => icon}.merge() end |
#current_year ⇒ Object
40 41 42 |
# File 'lib/view_fu/tag_helper.rb', line 40 def current_year Time.now.strftime("%Y") end |
#delete_link(*args) ⇒ Object
Wrap a delete link
110 111 112 113 114 |
# File 'lib/view_fu/tag_helper.rb', line 110 def delete_link(*args) = {:method => :delete, :confirm => "Are you sure you want to delete this?"}.merge(args.) args << link_to(*args) end |
#hidden ⇒ Object
Return a hidden attribute hash (useful in Haml tags - %div#hidden)
55 56 57 |
# File 'lib/view_fu/tag_helper.rb', line 55 def hidden {:style => "display:none"} end |
#hide_if(condition) ⇒ Object Also known as: , show_unless
Return a hidden attribute hash if a condition evaluates to true
88 89 90 91 92 93 94 |
# File 'lib/view_fu/tag_helper.rb', line 88 def hide_if(condition) if condition hidden else {} end end |
#hide_unless(condition) ⇒ Object Also known as: , show_if
Return a hidden attribute hash if a condition evaluates to false
99 100 101 102 103 104 105 |
# File 'lib/view_fu/tag_helper.rb', line 99 def hide_unless(condition) if !condition hidden else {} end end |
#hr ⇒ Object
Writes an hr tag
10 11 12 |
# File 'lib/view_fu/tag_helper.rb', line 10 def hr "<hr />" end |
#is_edit? ⇒ Boolean
Check if we're on Edit or Update actions
134 135 136 137 |
# File 'lib/view_fu/tag_helper.rb', line 134 def is_edit? action = params[:action] action == "edit" || action == "update" end |
#is_first(i) ⇒ Object
check to see if an index is the first item in a collection
161 162 163 |
# File 'lib/view_fu/tag_helper.rb', line 161 def is_first(i) i.to_i.zero? ? {:class => "first"} : {} end |
#is_new? ⇒ Boolean
Check if we're on New or Create actions
128 129 130 131 |
# File 'lib/view_fu/tag_helper.rb', line 128 def is_new? action = params[:action] action == "new" || action == "create" end |
#link_to_block(*args, &block) ⇒ Object
Wrap a block with a link
117 118 119 120 |
# File 'lib/view_fu/tag_helper.rb', line 117 def link_to_block(*args, &block) content = capture_haml(&block) return link_to(content, *args) end |
#link_to_image(image_path, label, url, options = {}) ⇒ Object
Easily link to an image
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/view_fu/tag_helper.rb', line 60 def link_to_image(image_path, label, url, ={}) # setup vertical alignment vert_align = .delete(:vert) if vert_align.nil? vert_style = "vertical-align: middle" elsif vert_align.blank? vert_style = "" else vert_style = "vertical-align: #{vert_align.to_i}px" end link_to(image_tag(image_path, :class => "vert-middle", :style => "#{vert_style}"), url, )+" "+ link_to(label, url, ) end |
#lorem ⇒ Object
Return some lorem text
50 51 52 |
# File 'lib/view_fu/tag_helper.rb', line 50 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
15 16 17 |
# File 'lib/view_fu/tag_helper.rb', line 15 def nbsp " " end |
#paging(page_data, style = :sabros) ⇒ Object
Display will_paginate paging links
145 146 147 148 |
# File 'lib/view_fu/tag_helper.rb', line 145 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 |
#pixel(options = {}) ⇒ Object
pixel spacing helper
156 157 158 |
# File 'lib/view_fu/tag_helper.rb', line 156 def pixel( = {}) image_tag "pixel.png", end |
#production? ⇒ Boolean
Check if we're on production environment
123 124 125 |
# File 'lib/view_fu/tag_helper.rb', line 123 def production? Rails.env == "production" end |
#space ⇒ Object
Writes an hr space tag
20 21 22 |
# File 'lib/view_fu/tag_helper.rb', line 20 def space "<hr class='space' />" end |
#use_cache? ⇒ Boolean
Whether or not to use caching
140 141 142 |
# File 'lib/view_fu/tag_helper.rb', line 140 def use_cache? ActionController::Base.perform_caching end |