Module: ViewFu::TagHelper

Defined in:
lib/view_fu/tag_helper.rb

Instance Method Summary collapse

Instance Method Details

#anchor(anchor_name) ⇒ Object

Writes an anchor tag



20
21
22
# File 'lib/view_fu/tag_helper.rb', line 20

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



34
35
36
# File 'lib/view_fu/tag_helper.rb', line 34

def clear(direction = nil)
  clear_tag(:div, direction)
end

#clear_tag(tag, direction = nil) ⇒ Object

Writes a clear tag



25
26
27
28
29
30
31
# File 'lib/view_fu/tag_helper.rb', line 25

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



125
126
127
# File 'lib/view_fu/tag_helper.rb', line 125

def clearbit_icon(icon, color, options = {})
  image_tag "clearbits/#{icon}.gif", {:class => "clearbits #{color}", :alt => icon}.merge(options)
end

Wrap a delete link



84
85
86
87
88
# File 'lib/view_fu/tag_helper.rb', line 84

def delete_link(*args)
  options = {:method => :delete, :confirm => "Are you sure you want to delete this?"}.merge(args.extract_options!)
  args << options
  link_to(*args)
end

#hidden ⇒ Object

Return a hidden attribute hash (useful in Haml tags - %div#hidden)



44
45
46
# File 'lib/view_fu/tag_helper.rb', line 44

def hidden
  {:style => "display:none"}
end

#hide_if(condition) ⇒ Object

Return a hidden attribute hash if a condition evaluates to true



66
67
68
69
70
71
72
# File 'lib/view_fu/tag_helper.rb', line 66

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



75
76
77
78
79
80
81
# File 'lib/view_fu/tag_helper.rb', line 75

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

Returns:

  • (Boolean)


108
109
110
111
# File 'lib/view_fu/tag_helper.rb', line 108

def is_edit?
  action = params[:action]
  action == "edit" || action == "update"
end

#is_new? ⇒ Boolean

Check if we're on New or Create actions

Returns:

  • (Boolean)


102
103
104
105
# File 'lib/view_fu/tag_helper.rb', line 102

def is_new?
  action = params[:action]
  action == "new" || action == "create"
end

Wrap a block with a link



91
92
93
94
# File 'lib/view_fu/tag_helper.rb', line 91

def link_to_block(*args, &block)
  content = capture_haml(&block)
  return link_to(content, *args)
end

Easily link to an image



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/view_fu/tag_helper.rb', line 49

def link_to_image(image_path, label, url, options={})
  # setup vertical alignment
  vert_align = options.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, options)+"&nbsp;"+
  link_to(label, url, options)
end

#lorem ⇒ Object

Return some lorem text



39
40
41
# File 'lib/view_fu/tag_helper.rb', line 39

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

#paging(page_data, style = :sabros) ⇒ Object

Display will_paginate paging links



119
120
121
122
# File 'lib/view_fu/tag_helper.rb', line 119

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



130
131
132
# File 'lib/view_fu/tag_helper.rb', line 130

def pixel(options = {})
  image_tag "pixel.png", options
end

#production? ⇒ Boolean

Check if we're on production environment

Returns:

  • (Boolean)


97
98
99
# File 'lib/view_fu/tag_helper.rb', line 97

def production?
  Rails.env == "production"
end

#space ⇒ Object

Writes an hr space tag



15
16
17
# File 'lib/view_fu/tag_helper.rb', line 15

def space
  "<hr class='space' />"
end

#use_cache? ⇒ Boolean

Whether or not to use caching

Returns:

  • (Boolean)


114
115
116
# File 'lib/view_fu/tag_helper.rb', line 114

def use_cache?
  ActionController::Base.perform_caching
end