2010-05-14 15:12:31 -07:00
|
|
|
module ApplicationHelper
|
2012-12-29 22:46:36 -08:00
|
|
|
include FragmentLocalization
|
|
|
|
|
2012-07-29 13:45:12 -07:00
|
|
|
def absolute_url(path_or_url)
|
|
|
|
if path_or_url.include?('://') # already an absolute URL
|
|
|
|
path_or_url
|
|
|
|
else # a relative path
|
|
|
|
request.protocol + request.host_with_port + path_or_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-08 17:40:03 -08:00
|
|
|
def add_body_class(class_name)
|
|
|
|
@body_class ||= ''
|
|
|
|
@body_class << " #{class_name}"
|
|
|
|
end
|
2011-05-13 05:20:29 -07:00
|
|
|
|
2010-11-05 15:45:05 -07:00
|
|
|
def body_class
|
2010-11-08 17:40:03 -08:00
|
|
|
"#{params[:controller]} #{params[:controller]}-#{params[:action]}".tap do |output|
|
|
|
|
output << @body_class if @body_class
|
|
|
|
end
|
2010-11-05 15:45:05 -07:00
|
|
|
end
|
2011-05-13 05:20:29 -07:00
|
|
|
|
2015-02-25 11:49:18 -08:00
|
|
|
def advertise_campaign_progress(campaign, &block)
|
|
|
|
if campaign && campaign.advertised?
|
|
|
|
campaign_progress(campaign, &block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-11 15:40:37 -07:00
|
|
|
def campaign_progress(campaign, &block)
|
|
|
|
if campaign
|
2011-10-10 20:06:46 -07:00
|
|
|
if block_given?
|
|
|
|
content = capture(&block)
|
|
|
|
else
|
2014-09-11 16:09:00 -07:00
|
|
|
content = link_to(
|
|
|
|
content_tag(:span, 'Help Dress to Impress stay online!') +
|
|
|
|
content_tag(:span, 'Learn more', :class => 'button'), donate_path)
|
2011-10-10 20:06:46 -07:00
|
|
|
end
|
|
|
|
|
2014-09-11 15:40:37 -07:00
|
|
|
meter = content_tag(:div, nil, :class => 'campaign-progress',
|
|
|
|
style: "width: #{campaign.progress_percent}%;")
|
|
|
|
label = content_tag(:div, content, :class => 'campaign-progress-label')
|
|
|
|
content_tag(:div, meter + label, :class => 'campaign-progress-wrapper')
|
2011-07-09 08:45:30 -07:00
|
|
|
end
|
2011-07-01 12:38:13 -07:00
|
|
|
end
|
|
|
|
|
2011-07-26 15:56:14 -07:00
|
|
|
def canonical_path(resource)
|
2013-01-25 13:09:48 -08:00
|
|
|
I18n.with_locale(I18n.default_locale) do
|
|
|
|
content_for :meta, tag(:link, :rel => 'canonical', :href => url_for(resource))
|
|
|
|
end
|
2011-07-26 15:56:14 -07:00
|
|
|
end
|
|
|
|
|
2011-07-30 21:59:29 -07:00
|
|
|
def contact_email
|
|
|
|
"webmaster@openneo.net"
|
|
|
|
end
|
|
|
|
|
|
|
|
def feedback_url
|
2015-08-05 15:36:28 -07:00
|
|
|
"https://openneo.uservoice.com/forums/40720-dress-to-impress"
|
2011-07-30 21:59:29 -07:00
|
|
|
end
|
|
|
|
|
2010-05-15 10:47:46 -07:00
|
|
|
def flashes
|
2010-11-05 15:45:05 -07:00
|
|
|
raw(flash.inject('') do |html, pair|
|
2010-05-15 10:47:46 -07:00
|
|
|
key, value = pair
|
2011-07-15 14:21:18 -07:00
|
|
|
html + content_tag('p', value, :class => "flash #{key}")
|
2010-11-05 15:45:05 -07:00
|
|
|
end)
|
|
|
|
end
|
2011-05-13 05:20:29 -07:00
|
|
|
|
2010-11-30 13:52:38 -08:00
|
|
|
def hide_home_link
|
|
|
|
@hide_home_link = true
|
|
|
|
end
|
2011-05-13 05:20:29 -07:00
|
|
|
|
2010-11-30 13:52:38 -08:00
|
|
|
def home_link?
|
|
|
|
!@hide_home_link
|
|
|
|
end
|
2011-05-13 05:20:29 -07:00
|
|
|
|
2010-12-06 15:50:13 -08:00
|
|
|
JAVASCRIPT_LIBRARIES = {
|
2015-08-05 15:36:28 -07:00
|
|
|
:addthis => '//s7.addthis.com/js/250/addthis_widget.js#username=openneo',
|
|
|
|
:bitly => '//bit.ly/javascript-api.js?version=latest&login=openneo&apiKey=R_4d0438829b7a99860de1d3edf55d8dc8',
|
|
|
|
:html5 => '//html5shim.googlecode.com/svn/trunk/html5.js',
|
|
|
|
:jquery => '//ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js',
|
|
|
|
:jquery20 => '//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js',
|
|
|
|
:jquery_tmpl => '//ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js',
|
|
|
|
:swfobject => '//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js'
|
2010-12-06 15:50:13 -08:00
|
|
|
}
|
2011-05-13 05:20:29 -07:00
|
|
|
|
2010-12-06 15:50:13 -08:00
|
|
|
def include_javascript_libraries(*library_names)
|
|
|
|
raw(library_names.inject('') do |html, name|
|
|
|
|
html + javascript_include_tag(JAVASCRIPT_LIBRARIES[name])
|
|
|
|
end)
|
|
|
|
end
|
2012-12-29 22:46:36 -08:00
|
|
|
|
2013-01-11 09:46:14 -08:00
|
|
|
def locale_options
|
2013-01-17 20:16:34 -08:00
|
|
|
current_locale_is_public = false
|
|
|
|
options = I18n.public_locales.map do |available_locale|
|
|
|
|
current_locale_is_public = true if I18n.locale == available_locale
|
2013-02-06 08:59:25 -08:00
|
|
|
# Include fallbacks data on the tag. Right now it's used in blog
|
|
|
|
# localization, but may conceivably be used for something else later.
|
|
|
|
[translate('locale_name', :locale => available_locale), available_locale,
|
|
|
|
{'data-fallbacks' => I18n.fallbacks[available_locale].join(',')}]
|
2013-01-11 09:46:14 -08:00
|
|
|
end
|
2013-01-17 20:16:34 -08:00
|
|
|
|
|
|
|
unless current_locale_is_public
|
|
|
|
name = translate('locale_name', :locale => I18n.locale) + ' (alpha)'
|
|
|
|
options << [name, I18n.locale]
|
|
|
|
end
|
|
|
|
|
|
|
|
options
|
2013-01-11 09:46:14 -08:00
|
|
|
end
|
|
|
|
|
2013-01-04 17:28:00 -08:00
|
|
|
def localized_cache(key={}, &block)
|
2012-12-29 22:46:36 -08:00
|
|
|
localized_key = localize_fragment_key(key, locale)
|
|
|
|
cache(localized_key, &block)
|
|
|
|
end
|
2011-05-13 05:20:29 -07:00
|
|
|
|
2010-10-18 15:17:08 -07:00
|
|
|
def login_path_with_return_to
|
2010-11-10 13:59:54 -08:00
|
|
|
login_path :return_to => request.fullpath
|
|
|
|
end
|
2011-05-13 05:20:29 -07:00
|
|
|
|
2010-11-10 13:59:54 -08:00
|
|
|
def logout_path_with_return_to
|
|
|
|
logout_path :return_to => request.fullpath
|
2010-10-18 15:17:08 -07:00
|
|
|
end
|
2011-05-13 05:20:29 -07:00
|
|
|
|
2010-11-05 17:09:03 -07:00
|
|
|
def origin_tag(value)
|
|
|
|
hidden_field_tag 'origin', value, :id => nil
|
|
|
|
end
|
2012-07-29 13:45:12 -07:00
|
|
|
|
|
|
|
def open_graph(properties)
|
|
|
|
if @open_graph
|
|
|
|
@open_graph.merge! properties
|
|
|
|
else
|
|
|
|
@open_graph = properties
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def open_graph_tags
|
|
|
|
if @open_graph
|
|
|
|
@open_graph.inject('') do |output, property|
|
|
|
|
key, value = property
|
|
|
|
output + tag(:meta, :property => "og:#{key}", :content => value)
|
|
|
|
end.html_safe
|
|
|
|
end
|
|
|
|
end
|
2011-05-13 05:20:29 -07:00
|
|
|
|
2011-07-15 20:14:26 -07:00
|
|
|
def return_to_field_tag
|
|
|
|
hidden_field_tag :return_to, request.fullpath
|
|
|
|
end
|
2012-10-20 15:56:38 -07:00
|
|
|
|
|
|
|
def safely_to_json(obj)
|
|
|
|
obj.to_json.gsub('/', '\/')
|
|
|
|
end
|
2011-07-15 20:14:26 -07:00
|
|
|
|
2011-07-29 07:52:04 -07:00
|
|
|
def secondary_nav(&block)
|
|
|
|
content_for :before_flashes,
|
|
|
|
content_tag(:nav, :id => 'secondary-nav', &block)
|
|
|
|
end
|
|
|
|
|
2011-05-13 05:20:29 -07:00
|
|
|
def show_title_header?
|
|
|
|
params[:controller] != 'items'
|
|
|
|
end
|
|
|
|
|
2010-11-11 10:43:22 -08:00
|
|
|
def signed_in_meta_tag
|
|
|
|
%(<meta name="user-signed-in" content="#{user_signed_in?}">).html_safe
|
|
|
|
end
|
2014-01-18 19:54:11 -08:00
|
|
|
|
|
|
|
def current_user_id_meta_tag
|
|
|
|
%(<meta name="current-user-id" content="#{current_user.id}">).html_safe
|
|
|
|
end
|
2012-12-29 23:13:58 -08:00
|
|
|
|
|
|
|
def labeled_time_ago_in_words(time)
|
|
|
|
content_tag :abbr, time_ago_in_words(time), :title => time
|
|
|
|
end
|
2011-05-13 05:20:29 -07:00
|
|
|
|
2010-11-06 08:52:58 -07:00
|
|
|
def title(value)
|
|
|
|
content_for :title, value
|
|
|
|
end
|
2014-04-02 21:00:50 -07:00
|
|
|
|
|
|
|
def md(text)
|
|
|
|
RDiscount.new(text).to_html.html_safe
|
|
|
|
end
|
2012-12-29 22:46:36 -08:00
|
|
|
|
2013-01-04 17:28:00 -08:00
|
|
|
def translate_markdown(key, options={})
|
2014-04-02 21:00:50 -07:00
|
|
|
md translate("#{key}_markdown", options)
|
2013-01-04 17:28:00 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
alias_method :tmd, :translate_markdown
|
|
|
|
|
2013-01-04 15:58:25 -08:00
|
|
|
def translate_with_links(key, options={})
|
|
|
|
nonlink_options = {}
|
|
|
|
link_urls = {}
|
|
|
|
|
|
|
|
options.each do |key, value|
|
|
|
|
str_key = key.to_s
|
|
|
|
if str_key.end_with? '_link_url'
|
|
|
|
link_key = str_key[0..-5] # "abcdef_link_url" => "abcdef_link"
|
|
|
|
link_urls[link_key] = value
|
|
|
|
else
|
|
|
|
nonlink_options[key] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
link_options = {}
|
|
|
|
link_urls.each do |link_key, url|
|
|
|
|
content = translate("#{key}.#{link_key}_content", nonlink_options)
|
|
|
|
link_options[link_key.to_sym] = link_to(content, url)
|
|
|
|
end
|
|
|
|
|
|
|
|
converted_options = link_options.merge(nonlink_options)
|
|
|
|
translate("#{key}.main_html", converted_options)
|
|
|
|
end
|
|
|
|
|
|
|
|
alias_method :twl, :translate_with_links
|
|
|
|
|
2012-12-29 22:46:36 -08:00
|
|
|
def userbar_contributions_summary(user)
|
2013-01-08 17:23:22 -08:00
|
|
|
translate_with_links '.userbar.contributions_summary',
|
|
|
|
:contributions_link_url => user_contributions_path(user),
|
|
|
|
:user_points => user.points
|
2012-12-29 22:46:36 -08:00
|
|
|
end
|
2015-08-05 16:41:42 -07:00
|
|
|
|
|
|
|
def camo_image_url(image_url)
|
2015-08-05 17:11:08 -07:00
|
|
|
Image.from_insecure_url(image_url).secure_url
|
2015-08-05 16:41:42 -07:00
|
|
|
end
|
2010-05-14 15:12:31 -07:00
|
|
|
end
|
2011-05-13 05:20:29 -07:00
|
|
|
|