Module: JapMagWidgetsHelper

Defined in:
app/helpers/jap_mag_widgets_helper.rb

Instance Method Summary collapse

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 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



133
134
135
136
137
138
# File 'app/helpers/jap_mag_widgets_helper.rb', line 133

def cta text, url, 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



151
152
153
# File 'app/helpers/jap_mag_widgets_helper.rb', line 151

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

#get_body_classObject



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_idObject



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_classObject



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

Returns:

  • (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_atObject



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


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, 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



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 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



143
144
145
# File 'app/helpers/jap_mag_widgets_helper.rb', line 143

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

#random_disable_with_statusObject



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 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("#{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 = " - "

  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