Module: JapMagWidgetsHelper
- Defined in:
- app/helpers/jap_mag_widgets_helper.rb
Instance Method Summary collapse
- #clearfix(options = {}) ⇒ Object
-
#cta(text, url, html_options = {}) ⇒ Object
call to action.
- #current_or_null(condition) ⇒ Object
- #get_body_class ⇒ Object
- #get_body_id ⇒ Object
- #get_wrapper_class ⇒ Object
- #is_mobile_device? ⇒ Boolean
- #last_deployed_at ⇒ 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
67 68 69 70 71 72 73 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 67 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
133 134 135 136 137 138 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 133 def cta text, url, ={} [:class] = ([:class].to_s + " cta").strip link_to content_tag(:span, text), url, end |
#current_or_null(condition) ⇒ Object
151 152 153 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 151 def current_or_null(condition) condition ? "current" : nil end |
#get_body_class ⇒ Object
8 9 10 11 12 13 14 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 8 def get_body_class c = [] c << controller.controller_name c << "mobile" if is_mobile_device? c.collect{|e| e.titleize.gsub(/\s/, "")}.join " " end |
#get_body_id ⇒ Object
16 17 18 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 16 def get_body_id content_for(:id).to_s.titleize.gsub(/\s/, "") unless content_for(:id).blank? end |
#get_wrapper_class ⇒ Object
20 21 22 23 24 25 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 20 def get_wrapper_class c = [] c << controller.action_name c.collect{|e| e.titleize.gsub(/\s/, "")}.join " " end |
#is_mobile_device? ⇒ Boolean
3 4 5 6 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 3 def is_mobile_device? mobile_user_agents = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|webos|amoi|novarra|cdm|alcatel|pocket|iphone|mobileexplorer|mobile' request.user_agent.to_s.downcase =~ Regexp.new(mobile_user_agents) end |
#last_deployed_at ⇒ Object
167 168 169 170 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 167 def last_deployed_at file = File.join("tmp", "restart.txt") File.exists?(file) ? File.atime(file) : nil end |
#link_to_user(user, options = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 75 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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 48 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] ? "#{options[: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
143 144 145 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 143 def paginator(collections, ={}) will_paginate collections, end |
#random_disable_with_status ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 115 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
155 156 157 158 159 160 161 162 163 164 165 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 155 def scopes, ={} content_tag :ul, class: :scopes do scopes.collect do |scope| count = [: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 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
147 148 149 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 147 def time_difference time "#{distance_of_time_in_words(time, Time.now, true)} ago" if time end |
#title(*titles) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/helpers/jap_mag_widgets_helper.rb', line 100 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 |