Skip to Content Skip to Search
Methods
A
C
E
F
G
M
P
R
S
T
Included Modules

Constants

TRANSLATIONS_FOR_JS = [ "stripe.errors", "member.payment_forms.coupon_applied", "member.payment_forms.coupon_discount", "member.payment_forms.coupon_apply_button", "member.payment_forms.processing" ].freeze
 

Instance Public methods

allowed_html_filter(text)

# File app/helpers/application_helper.rb, line 106
def allowed_html_filter(text)
  sanitize text.gsub("href=", 'target="_blank" href=')
end

content_video_player(args = {})

# File app/helpers/application_helper.rb, line 88
def content_video_player(args = {})
  video = args.fetch(:video)
  player = ""
  if video.youtube?
    player << "<style>.embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; } .embed-container iframe, .embed-container object, .embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style><div class='embed-container'><iframe src='https://www.youtube.com/embed/#{video.player_id}?rel=0' frameborder='0' allowfullscreen></iframe></div>"
  elsif video.vimeo?
    player << "<style>.embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; } .embed-container iframe, .embed-container object, .embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style><div class='embed-container'><iframe src='https://player.vimeo.com/video/#{video.player_id}' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>"
  elsif video.vimeo_recurring?
    player << "<style>.embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; } .embed-container iframe, .embed-container object, .embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style><div class='embed-container'><iframe src='https://vimeo.com/event/#{video.player_id}/embed/#{video.player_id}' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>"
  elsif video.wistia?
    player << "<style>.embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; } .embed-container iframe, .embed-container object, .embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style><div class='embed-container'><iframe src='//fast.wistia.net/embed/iframe/#{video.player_id}?seo=false&videoFoam=true&fullscreenButton=true' style='border:0' allowfullscreen mozallowfullscreen webkitallowfullscreen oallowfullscreen msallowfullscreen></iframe></div>"
    player << "<script src='//fast.wistia.net/assets/external/E-v1.js' async></script>"
  else
    player = "Please use a YouTube, Vimeo, or Wistia link URL only</h2>"
  end
  player.html_safe
end

coupon_duration(duration:, duration_in_months: 0)

# File app/helpers/application_helper.rb, line 144
def coupon_duration(duration:, duration_in_months: 0)
  case duration
  when "repeating"
    "for #{duration_in_months} months"
  when "forever"
    "forever"
  when "once"
    "once"
  else
    ""
  end
end

css_vars(site = current_site)

# File app/helpers/application_helper.rb, line 171
def css_vars(site = current_site)
  site.theme_custom_styles.map { |key, value|
    # Add quotes to font names so they are not treated as identifiers
    value = "'#{value}'" if key.ends_with?("font_family".freeze)

    "--#{key.gsub("__", "-").tr("_", "-")}: #{value};"
  }.join(" ")
end

errors_for(field_key, field_name, model)

# File app/helpers/application_helper.rb, line 133
def errors_for(field_key, field_name, model)
  errors = ""
  if model.errors.messages.key?(field_key)
    model.errors.messages[field_key].each_with_index do |message, i|
      error = (i == 0) ? model.errors.full_message(field_name, message) : ", " + message
      errors += error
    end
  end
  allowed_html_filter errors
end

format_money(object, amount_method)

# File app/helpers/application_helper.rb, line 64
def format_money(object, amount_method)
  # FIXME: this helper and service would not be necessary with money-rails
  Service::Money.new(object.public_send(amount_method), object.currency).format
end

membership_status_tag(plan, member)

# File app/helpers/application_helper.rb, line 41
def membership_status_tag(plan, member)
  membership = member.plannings.find_by!(plan:)
  status_tag(membership.status, membership.status_text, member.site)
end

plan_custom_description(plan)

# File app/helpers/application_helper.rb, line 27
def plan_custom_description(plan)
  if plan.description
    allowed_html_filter(". <div class='custom-description'>#{plan.description}</div>")
  end
end

plan_expiration_description(plan, args = {})

# File app/helpers/application_helper.rb, line 33
def plan_expiration_description(plan, args = {})
  Service::PlanDetails.new(plan: plan, **args).expiration_description
end

plan_format_amount(amount, currency)

# File app/helpers/application_helper.rb, line 69
def plan_format_amount(amount, currency)
  # TODO: use `format_money` instead
  Service::Money.new(amount, currency).format
end

plan_pricing_description(plan, args = {})

# File app/helpers/application_helper.rb, line 23
def plan_pricing_description(plan, args = {})
  Service::PlanDetails.new(plan: plan, **args).pricing_description
end

plan_purchase_cta(plan, member)

# File app/helpers/application_helper.rb, line 74
def plan_purchase_cta(plan, member)
  if plan.trial_period_days.present? && !member.subscriptions.exists?
    te_payment("subscription_trial_button", plan.site_id)
  elsif plan.subscription_plan_type?
    te_payment("subscription_plan_button", plan.site_id)
  elsif plan.one_time_payment_plan_type?
    te_payment("one_time_charge_plan_button", plan.site_id)
  elsif plan.multi_payment_plan_type?
    te_payment("multiple_payments_plan_button", plan.site_id)
  elsif plan.free_plan_type?
    te_payment("free_plan_button", plan.site_id)
  end
end

planning_expiration_description(plan, member)

# File app/helpers/application_helper.rb, line 37
def planning_expiration_description(plan, member)
  member.plannings.find_by!(plan:).expiration_description
end

prepared_label_text(text, required = false)

# File app/helpers/application_helper.rb, line 110
def prepared_label_text(text, required = false)
  return allowed_html_filter(text) unless required

  allowed_html_filter(text) + " *"
end

referrer()

# File app/helpers/application_helper.rb, line 190
def referrer
  request.env["HTTP_REFERER"]
end

status_tag(status, status_text = nil, site = nil)

# File app/helpers/application_helper.rb, line 46
def status_tag(status, status_text = nil, site = nil)
  text = status.titleize

  if status_text
    string = status_text.index("(") ?
      status_text[0..(status_text.index("(") - 2)] :
      status_text

    text = site ?
      I18n.t("member.your_account.#{string.gsub(/( )/, "_").downcase}_plan", site_id: site.id).titleize :
      I18n.t("membership_status.#{string.gsub(/( )/, "_").downcase}").titleize

    text += status_text[(status_text.index("(") - 1)..] if status_text.index("(")
  end

  "<span class='#{status} tag'>[#{text}]</span>".html_safe
end

submit_button(args = {})

# File app/helpers/application_helper.rb, line 157
def submit_button(args = {})
  button_class = args.fetch(:button_class, "")
  button_content = args.fetch(:button_content, "")
  button_name = args.fetch(:name, "")
  button_value = args.fetch(:value, "")
  button_tag({type: "submit",
              name: button_name,
              value: button_value,
              class: button_class,
              data: {disable_with: button_content}}) do
    button_content.html_safe
  end
end

te_payment(key, site_id, options = {})

# File app/helpers/application_helper.rb, line 12
def te_payment(key, site_id, options = {})
  I18n.t("member.payment_forms.#{key}", site_id: site_id, **options)
end

translations_for(locale:, scopes:, site_id:, fallbacks: true)

# File app/helpers/application_helper.rb, line 116
def translations_for(locale:, scopes:, site_id:, fallbacks: true)
  translations = Service::Translations.new(
    locale: locale,
    site_id: site_id
  ).get_translations_group_for_keys(scopes)

  content_tag :div, {id: "translations"} do
    content_tag "script", {type: "text/javascript"} do
      raw(
        "I18n.fallbacks = #{fallbacks};
         I18n.locale = '#{locale}';
         I18n.translations = #{translations.to_json};"
      )
    end
  end
end