Module: WidgetsHelper

Defined in:
app/helpers/widgets_helper.rb

Instance Method Summary collapse

Instance Method Details

#clearfix(options = {}) ⇒ Object



43
44
45
46
47
48
49
# File 'app/helpers/widgets_helper.rb', line 43

def clearfix options={}
  opt = {:class => " clearfix"}
  options[:class] += opt[:class] if options[:class]
  (options[:class] || opt[:class]).strip!
  opt = opt.merge(options)
  (:div, nil, opt)
end

#cta(text, url, html_options = {}) ⇒ Object

call to action



109
110
111
112
113
114
115
# File 'app/helpers/widgets_helper.rb', line 109

def cta text, url, html_options={}
  default_html_options = {:class => "cta"}
  html_options = default_html_options.merge(html_options)
  html_options[:class] = (html_options[:class].to_s + " cta").strip

  link_to (:span, text), url, html_options
end

#current_or_null(condition) ⇒ Object



128
129
130
# File 'app/helpers/widgets_helper.rb', line 128

def current_or_null(condition)
  condition ? "current" : nil
end


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/helpers/widgets_helper.rb', line 51

def link_to_user(user, options={})

  default_options = {
    :href => user,
    :avatar => false,
    :title => user.name,
    :class => ""
  }

  options = default_options.merge(options)

  if options[:avatar]
    return unless user.avatar?

    text = image_tag(user.avatar.url(options[:avatar]), :alt => user.name, :class => "avatar")

    options[:class] += " avatar".strip
  else
    text = user.name
  end

  #raise url_for(user)#user_path(:subdomain => "aaa").inspect
  link_to(text, options[:href], :title => options[:title], :class => options[:class])
end

navigation helper by Felix

the helper matches params with request.request_uri

example: sections = { ‘radio’=>=> ‘Station’, :url => radio_path, ‘edit_station’=>=> ‘Radio’, :url => edit_station_path } options =

:id => 'test_menu'
:current => 'current'

outputs: <ul id=“test_menu”>

<li><a href="/station">Station</a></li>
<li class="current"><a href="/radio/">Radio</a></li>

</ul> :title



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/widgets_helper.rb', line 24

def menu(sections, options=nil)
  items = Array.new

  # default options
  options ||= Hash.new
  options[:id] ||= nil
  options[:class] ||= nil
  options[:current] ||= 'current' # jquery ui tabs plugin needs the later one

  sections.each do |section|
    klass = section[:current] ? "#{options[:current]} #{section[:class]}".strip : section[:class]
    items << (:li, link_to(section[:title], section[:url], :class => klass))   
  end

  return  :ul, :id => options[:id], :class => options[:class] do
    items.collect {|item| concat(item)}
  end
end

#paginator(collections, options = {}) ⇒ Object

paginator



120
121
122
# File 'app/helpers/widgets_helper.rb', line 120

def paginator(collections, options={})
  will_paginate collections, options
end

#random_disable_with_statusObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/helpers/widgets_helper.rb', line 91

def random_disable_with_status
  status = [
    "Just a moment",
    "Let's stay together",
    "On the highway to hell",
    "Don't worry baby",
    "Let it be",
    "Getting you away from here",
    "Let's get it started",
    "It's now or never"
  ]

  status.shuffle.first + "..."
end

#scope_button(scopes, options = {}) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
# File 'app/helpers/widgets_helper.rb', line 132

def scope_button scopes, options={}
   :ul, class: :scopes do
    scopes.collect do |scope|
      count = options[:count][scope[:key]]
      url = eval("#{options[:path].to_s}(scope: :#{scope[:key]})")
      current = ((params[:scope] == scope[:key].to_s) or (scope[:default] and params[:scope].blank?))

      concat (:li, link_to("#{(:span, scope[:text])} (#{count})".html_safe, url, class: current_or_null(current)))
    end
  end
end

#time_difference(time) ⇒ Object



124
125
126
# File 'app/helpers/widgets_helper.rb', line 124

def time_difference time
  "#{distance_of_time_in_words(time, Time.now, true)} ago" if time
end

#title(*titles) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/helpers/widgets_helper.rb', line 76

def title(*titles)
  seperator = " - "

  default_options = {:sitename => true}
  options = titles.last.is_a?(Hash) ? titles.pop : {}
  options = default_options.merge(options)

  page_title = page_title_for_return = titles.join(seperator)
  page_title = t("logo") + seperator + page_title_for_return if options[:sitename]

  content_for(:title, page_title)

  page_title_for_return
end