Module: WidgetsHelper
- Defined in:
- app/helpers/widgets_helper.rb
Instance Method Summary collapse
- #clearfix(options = {}) ⇒ Object
-
#cta(text, url, html_options = {}) ⇒ Object
call to action.
- #current_or_null(condition) ⇒ Object
- #link_to_user(user, options = {}) ⇒ Object
-
#menu(sections, options = nil) ⇒ Object
navigation helper by Felix.
-
#paginator(collections, options = {}) ⇒ Object
paginator.
- #random_disable_with_status ⇒ Object
- #scope_button(scopes, options = {}) ⇒ Object
- #time_difference(time) ⇒ Object
- #title(*titles) ⇒ Object
Instance Method Details
#clearfix(options = {}) ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/helpers/widgets_helper.rb', line 43 def clearfix ={} opt = {:class => " clearfix"} [:class] += opt[:class] if [:class] ([:class] || opt[:class]).strip! opt = opt.merge() content_tag(: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, ={} = {:class => "cta"} = .merge() [:class] = ([:class].to_s + " cta").strip link_to content_tag(:span, text), url, 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 |
#link_to_user(user, options = {}) ⇒ Object
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, ={}) = { :href => user, :avatar => false, :title => user.name, :class => "" } = .merge() if [:avatar] return unless user.avatar? text = image_tag(user.avatar.url([:avatar]), :alt => user.name, :class => "avatar") [:class] += " avatar".strip else text = user.name end #raise url_for(user)#user_path(:subdomain => "aaa").inspect link_to(text, [:href], :title => [:title], :class => [:class]) end |
#menu(sections, options = nil) ⇒ Object
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 (sections, =nil) items = Array.new # default options ||= Hash.new [:id] ||= nil [:class] ||= nil [:current] ||= 'current' # jquery ui tabs plugin needs the later one sections.each do |section| klass = section[:current] ? "#{[:current]} #{section[:class]}".strip : section[:class] items << content_tag(:li, link_to(section[:title], section[:url], :class => klass)) end return content_tag :ul, :id => [:id], :class => [: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, ={}) will_paginate collections, end |
#random_disable_with_status ⇒ Object
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 scopes, ={} content_tag :ul, class: :scopes do scopes.collect do |scope| count = [:count][scope[:key]] url = eval("#{[:path].to_s}(scope: :#{scope[:key]})") current = ((params[:scope] == scope[:key].to_s) or (scope[:default] and params[:scope].blank?)) concat content_tag(:li, link_to("#{content_tag(: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 = " - " = {:sitename => true} = titles.last.is_a?(Hash) ? titles.pop : {} = .merge() page_title = page_title_for_return = titles.join(seperator) page_title = t("logo") + seperator + page_title_for_return if [:sitename] content_for(:title, page_title) page_title_for_return end |