Module: ViewFu::TagHelper
- Defined in:
- lib/view_fu/tag_helper.rb
Instance Method Summary collapse
-
#anchor(anchor_name) ⇒ 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, #hidden_unless)
Return a hidden attribute hash if a condition evaluates to true.
-
#hide_unless(condition) ⇒ Object
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_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
#anchor(anchor_name) ⇒ Object
Writes an anchor tag
25 26 27 |
# File 'lib/view_fu/tag_helper.rb', line 25 def anchor(anchor_name) "<a name='#{anchor_name}'></a>" 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
43 44 45 |
# File 'lib/view_fu/tag_helper.rb', line 43 def clear(direction = nil) clear_tag(:div, direction) end |
#clear_tag(tag, direction = nil) ⇒ Object
Writes a clear tag
30 31 32 33 34 35 36 |
# File 'lib/view_fu/tag_helper.rb', line 30 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
137 138 139 |
# File 'lib/view_fu/tag_helper.rb', line 137 def clearbit_icon(icon, color, = {}) image_tag "clearbits/#{icon}.gif", {:class => "clearbits #{color}", :alt => icon}.merge() end |
#current_year ⇒ Object
38 39 40 |
# File 'lib/view_fu/tag_helper.rb', line 38 def current_year Time.now.strftime("%Y") end |
#delete_link(*args) ⇒ Object
Wrap a delete link
96 97 98 99 100 |
# File 'lib/view_fu/tag_helper.rb', line 96 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)
53 54 55 |
# File 'lib/view_fu/tag_helper.rb', line 53 def hidden {:style => "display:none"} end |
#hide_if(condition) ⇒ Object Also known as: ,
Return a hidden attribute hash if a condition evaluates to true
75 76 77 78 79 80 81 |
# File 'lib/view_fu/tag_helper.rb', line 75 def hide_if(condition) if condition hidden else {} end end |
#hide_unless(condition) ⇒ Object
Return a hidden attribute hash if a condition evaluates to false
85 86 87 88 89 90 91 |
# File 'lib/view_fu/tag_helper.rb', line 85 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
120 121 122 123 |
# File 'lib/view_fu/tag_helper.rb', line 120 def is_edit? action = params[:action] action == "edit" || action == "update" end |
#is_new? ⇒ Boolean
Check if we're on New or Create actions
114 115 116 117 |
# File 'lib/view_fu/tag_helper.rb', line 114 def is_new? action = params[:action] action == "new" || action == "create" end |
#link_to_block(*args, &block) ⇒ Object
Wrap a block with a link
103 104 105 106 |
# File 'lib/view_fu/tag_helper.rb', line 103 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
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/view_fu/tag_helper.rb', line 58 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
48 49 50 |
# File 'lib/view_fu/tag_helper.rb', line 48 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
131 132 133 134 |
# File 'lib/view_fu/tag_helper.rb', line 131 def paging(page_data, style = :sabros) return unless page_data.class == WillPaginate::Collection will_paginate(page_data, :class => "pagination #{style}", :inner_window => 3) end |
#pixel(options = {}) ⇒ Object
pixel spacing helper
142 143 144 |
# File 'lib/view_fu/tag_helper.rb', line 142 def pixel( = {}) image_tag "pixel.png", end |
#production? ⇒ Boolean
Check if we're on production environment
109 110 111 |
# File 'lib/view_fu/tag_helper.rb', line 109 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
126 127 128 |
# File 'lib/view_fu/tag_helper.rb', line 126 def use_cache? ActionController::Base.perform_caching end |