Module: Platform::ActionViewExtension::InstanceMethods

Defined in:
lib/platform/extensions/action_view_extension.rb

Instance Method Summary collapse

Instance Method Details

#platform_app_icon_tag(app, options = {}) ⇒ Object



129
130
131
132
133
# File 'lib/platform/extensions/action_view_extension.rb', line 129

def platform_app_icon_tag(app, options = {})
  options[:style] ||= ""
  options[:style] << "width:16px;height:16px;"
  image_tag(app.icon_url, :style => options[:style])
end

#platform_app_logo_tag(app, options = {}) ⇒ Object



135
136
137
138
139
# File 'lib/platform/extensions/action_view_extension.rb', line 135

def platform_app_logo_tag(app, options = {})
  options[:style] ||= ""
  options[:style] << "width:75px;height:75px;"
  image_tag(app.logo_url, :style => options[:style])
end

#platform_app_rank_tag(app, rank = nil, opts = {}) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/platform/extensions/action_view_extension.rb', line 73

def platform_app_rank_tag(app, rank = nil, opts = {})
  return "" unless app

  rank ||= app.rank || 0
  rank = rank * 100 / 5

  html = "<span dir='ltr'>"
  1.upto(5) do |i|
    if rank > i * 20 - 10  and rank < i * 20  
      html << image_tag("platform/rating_star05.png")
    elsif rank < i * 20 - 10 
      html << image_tag("platform/rating_star0.png")
    else
      html << image_tag("platform/rating_star1.png")
    end 
  end
  html << "</span>"
  html.html_safe
end

#platform_display_time(time, format) ⇒ Object



183
184
185
# File 'lib/platform/extensions/action_view_extension.rb', line 183

def platform_display_time(time, format)
  time.tr(format).gsub('/ ', '/').sub(/^[0:]*/,"")
end

#platform_documentation_api_decorators_tag(api) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/platform/extensions/action_view_extension.rb', line 61

def platform_documentation_api_decorators_tag(api)
  return unless api[:status]
  return image_tag("platform/exclamation.png", :style=>"vertical-align:top;height:10px;", :title => trl("The API structure has changed")) if ['changed'].include?(api[:status]) 
  return image_tag("platform/cancel.png", :style=>"vertical-align:top;height:10px;", :title => trl("The API has been removed")) if ['removed', 'deprecated'].include?(api[:status]) 
  return image_tag("platform/add.png", :style=>"vertical-align:top;height:10px;", :title => trl("This API has been added")) if api[:status] == 'added'
  return image_tag("platform/accept.png", :style=>"vertical-align:top;height:10px;", :title => trl("This API has been updated")) if api[:status] == 'updated'
end

#platform_documentation_field_decorators_tag(field) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/platform/extensions/action_view_extension.rb', line 53

def platform_documentation_field_decorators_tag(field)
  return unless field[:status]
  return image_tag("platform/cancel.png", :style=>"vertical-align:top;height:10px;", :title => trl("This field has been deprecated and will no longer be supported in the future versions")) if ['deprecated', 'removed'].include?(field[:status]) 
  return image_tag("platform/exclamation.png", :style=>"vertical-align:top;height:10px;", :title => trl("This field will be changed in the future versions")) if field[:status] == 'changed'
  return image_tag("platform/add.png", :style=>"vertical-align:top;height:10px;", :title => trl("This field has been added")) if field[:status] == 'added'
  return image_tag("platform/accept.png", :style=>"vertical-align:top;height:10px;", :title => trl("This field has been changed")) if field[:status] == 'updated'
end

#platform_documentation_tag(url_options = {}) ⇒ Object



49
50
51
# File 'lib/platform/extensions/action_view_extension.rb', line 49

def platform_documentation_tag(url_options = {})
  link_to(image_tag("platform/bullet_go.png", :style=>"vertical-align:middle;"), url_options.merge({:controller => "/platform/developer/help", :action => "api"}))
end

#platform_help_icon_tag(path = "index", opts = {}) ⇒ Object



171
172
173
# File 'lib/platform/extensions/action_view_extension.rb', line 171

def platform_help_icon_tag(path = "index", opts = {})
  link_to(image_tag("platform/help.png", :style => "border:0px; vertical-align:middle;", :title => trl("Help")), opts.merge({:controller => "/platform/developer/help", :action => path}), :target => "_new")
end

#platform_login_url_tag(label) ⇒ Object



159
160
161
# File 'lib/platform/extensions/action_view_extension.rb', line 159

def (label)
  link_to(label, platform_stringify_url(Platform::Config., :display => params[:display], :client_id => params[:client_id]))
end

#platform_logout_url_tag(label) ⇒ Object



163
164
165
# File 'lib/platform/extensions/action_view_extension.rb', line 163

def platform_logout_url_tag(label)
  link_to(label, platform_stringify_url(Platform::Config.logout_url, :display => params[:display], :client_id => params[:client_id]))
end

#platform_paginator_tag(collection, options = {}) ⇒ Object



167
168
169
# File 'lib/platform/extensions/action_view_extension.rb', line 167

def platform_paginator_tag(collection, options = {})  
  render :partial => "/platform/common/paginator", :locals => {:collection => collection, :options => options}
end

#platform_rating_tag(rating, opts = {}) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/platform/extensions/action_view_extension.rb', line 93

def platform_rating_tag(rating, opts = {})
  return "" unless rating

  value = rating.value || 0
  style = []
  style << "width:#{opts[:width]}" if opts[:width]

  html = "<span dir='ltr'>"
  1.upto(5) do |i|
    if i <= value  
      html << image_tag("platform/rating_star1.png", :style => style.join(";"))
    else
      html << image_tag("platform/rating_star0.png", :style => style.join(";"))
    end 
  end
  html << "</span>"
  html.html_safe
end

#platform_scripts_tag(opts = {}) ⇒ Object



69
70
71
# File 'lib/platform/extensions/action_view_extension.rb', line 69

def platform_scripts_tag(opts = {})
  render(:partial => '/platform/common/scripts', :locals => {:opts => opts})    
end

#platform_spinner_tag(id = "spinner", label = nil, cls = 'spinner') ⇒ Object



112
113
114
115
116
117
# File 'lib/platform/extensions/action_view_extension.rb', line 112

def platform_spinner_tag(id = "spinner", label = nil, cls='spinner')
  html = "<div id='#{id}' class='#{cls}' style='display:none'>"
  html << image_tag("platform/spinner.gif", :style => "vertical-align:middle;")
  html << " #{trl(label)}" if label
  html << "</div>"
end

#platform_stringify_url(path, params) ⇒ Object



175
176
177
# File 'lib/platform/extensions/action_view_extension.rb', line 175

def platform_stringify_url(path, params)
  "#{path}#{path.index('?') ? '&' : '?'}#{params.collect{|n,v| "#{n}=#{CGI.escape(v.to_s)}"}.join("&")}"
end

#platform_toggler_tag(content_id, label = "", open = true, opts = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/platform/extensions/action_view_extension.rb', line 33

def platform_toggler_tag(content_id, label = "", open = true, opts = {})
  style = opts[:style] || 'text-align:center; vertical-align:middle'

  html = "<span id='#{content_id}_open' "
  html << "style='display:none'" unless open
  html << ">"
  html << link_to_function("#{image_tag("platform/arrow_down.gif", :style=>style)} #{label}".html_safe, "Tr8n.Effects.hide('#{content_id}_open'); Tr8n.Effects.show('#{content_id}_closed'); Tr8n.Effects.blindUp('#{content_id}');", :style=> "text-decoration:none")
  html << "</span>" 
  html << "<span id='#{content_id}_closed' "
  html << "style='display:none'" if open
  html << ">"
  html << link_to_function("#{image_tag("platform/arrow_right.gif", :style=>style)} #{label}".html_safe, "Tr8n.Effects.show('#{content_id}_open'); Tr8n.Effects.hide('#{content_id}_closed'); Tr8n.Effects.blindDown('#{content_id}');", :style=> "text-decoration:none")
  html << "</span>"
  html.html_safe 
end

#platform_user_login_tag(opts = {}) ⇒ Object



28
29
30
31
# File 'lib/platform/extensions/action_view_extension.rb', line 28

def (opts = {})
  opts[:class] ||= 'tr8n_right_horiz_list'
  render(:partial => '/platform/common/user_login', :locals => {:opts => opts})    
end

#platform_user_mugshot_tag(user, options = {}) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/platform/extensions/action_view_extension.rb', line 141

def platform_user_mugshot_tag(user, options = {})
  if user and !Platform::Config.user_mugshot(user).blank?
    img_url = Platform::Config.user_mugshot(user)
  else
    img_url = Platform::Config.silhouette_image(user)
  end

  img_tag = "<img src='#{img_url}' style='width:48px'>"

  if user and options[:linked]
    link_to(img_tag, Platform::Config.user_link(user))
  else  
    img_tag
  end

  img_tag.html_safe
end

#platform_user_tag(user, options = {}) ⇒ Object



119
120
121
122
123
124
125
126
127
# File 'lib/platform/extensions/action_view_extension.rb', line 119

def platform_user_tag(user, options = {})
  return "Deleted Translator" unless user

  if options[:linked]
    link_to(Platform::Config.user_name(user), Platform::Config.user_link(user))
  else
    Platform::Config.user_name(user)
  end
end

#platform_when_string_tag(time, opts = {}) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/platform/extensions/action_view_extension.rb', line 187

def platform_when_string_tag(time, opts = {})
  elapsed_seconds = Time.now - time
  return platform_when_string_tr("Today") if time.today_in_time_zone? if opts[:days_only]
  return platform_when_string_tr('In the future, Marty!') if elapsed_seconds < 0
  return platform_when_string_tr('A moment ago') if elapsed_seconds < 2.minutes
  return platform_when_string_tr("{minutes||minute} ago", :minutes => (elapsed_seconds / 1.minute).to_i) if elapsed_seconds < 1.hour
  return platform_when_string_tr("{hours||hour} ago", :hours => 1) if elapsed_seconds < 1.75.hours
  return platform_when_string_tr("{hours||hour} ago", :hours => 2) if elapsed_seconds < 2.hours
  return platform_when_string_tr("{hours||hour} ago", :hours => (elapsed_seconds / 1.hour).to_i) if elapsed_seconds < 1.day
  return platform_when_string_tr("Yesterday") if elapsed_seconds < 48.hours
  return platform_when_string_tr("{days||day} ago", :days => elapsed_seconds.to_i / 1.day) if elapsed_seconds < 14.days
  return platform_when_string_tr("{weeks||week} ago", :weeks => (elapsed_seconds / 1.day / 7).to_i) if elapsed_seconds < 4.weeks
  return platform_display_time(time, :monthname_abbr) if Date.today.year == time.year
  return platform_display_time(time, :monthname_abbr_year)
end

#platform_when_string_tr(key, opts = {}) ⇒ Object



179
180
181
# File 'lib/platform/extensions/action_view_extension.rb', line 179

def platform_when_string_tr(key, opts = {})
  tr(key, 'Time reference', opts)
end