Module: PaidUp::FeaturesHelper

Includes:
PaidUpHelper
Defined in:
app/helpers/paid_up/features_helper.rb

Overview

PaidUp Features Helper

Instance Method Summary collapse

Methods included from PaidUpHelper

#date_range, #paid_up_google_analytics_data_layer

Instance Method Details

#feature_abilities_table(options = {}) ⇒ Object



70
71
72
73
74
75
76
# File 'app/helpers/paid_up/features_helper.rb', line 70

def feature_abilities_table(options = {})
  features = PaidUp::Feature.all
  render(
    partial: 'paid_up/features/abilities_table',
    locals: { features: features, html_options: options }
  )
end

#feature_display(feature, plan) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/paid_up/features_helper.rb', line 17

def feature_display(feature, plan)
  if feature.setting_type == 'boolean'
    if plan.feature_setting(feature.slug)
      icon 'ok'
    else
      icon 'remove'
    end
  elsif plan.feature_unlimited?(feature.slug)
    :unlimited.l
  else
    plan.feature_setting(feature.slug)
  end
end

#features_dl(plan) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'app/helpers/paid_up/features_helper.rb', line 6

def features_dl(plan)
  data = {}
  features = PaidUp::Feature.all

  features.each do |feature|
    data[feature.title] = feature_display feature, plan
  end

  dl data
end

#features_table(options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/paid_up/features_helper.rb', line 31

def features_table(options = {})
  features = PaidUp::Feature.all

  if !options[:should_add_buttons].nil?
    should_add_buttons = options[:should_add_buttons]
    options.delete(:should_add_buttons)
  else
    should_add_buttons = true
  end

  plans = PaidUp::Plan.subscribable
  if options[:only].present?
    plans = plans.where(id: options[:only])
    options.delete(:only)
  end
  if options[:except].present?
    plans = plans.where.not(id: options[:except])
    options.delete(:except)
  end

  if options[:highlight].present?
    highlight_plan = options[:highlight]
    options.delete(:highlight)
  else
    highlight_plan = nil
  end

  render(
    partial: 'paid_up/features/table',
    locals: {
      should_add_buttons: should_add_buttons,
      plans: plans,
      features: features,
      highlight_plan: highlight_plan,
      html_options: options
    }
  )
end