Sha256: c861ba912a30ff6a05a58e6d36372931382dc9a0eabffe1bd95077bcf535ecad

Contents?: true

Size: 1.74 KB

Versions: 14

Compression:

Stored size: 1.74 KB

Contents

module PaidUp
  module FeaturesHelper
    include PaidUp::PaidUpHelper

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

      for feature in features
        data[feature.title] = feature_display feature, plan
      end

      dl data
    end

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

    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 IN (?)', options[:only])
        options.delete(:only)
      end
      if options[:except].present?
        plans = plans.where('NOT ( id IN (?) )', 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

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
paid_up-0.2.4 app/helpers/paid_up/features_helper.rb
paid_up-0.2.3 app/helpers/paid_up/features_helper.rb
paid_up-0.2.2 app/helpers/paid_up/features_helper.rb
paid_up-0.2.1 app/helpers/paid_up/features_helper.rb
paid_up-0.2.0 app/helpers/paid_up/features_helper.rb
paid_up-0.1.9 app/helpers/paid_up/features_helper.rb
paid_up-0.1.8 app/helpers/paid_up/features_helper.rb
paid_up-0.1.7 app/helpers/paid_up/features_helper.rb
paid_up-0.1.6 app/helpers/paid_up/features_helper.rb
paid_up-0.1.5 app/helpers/paid_up/features_helper.rb
paid_up-0.1.4 app/helpers/paid_up/features_helper.rb
paid_up-0.1.3 app/helpers/paid_up/features_helper.rb
paid_up-0.1.1 app/helpers/paid_up/features_helper.rb
paid_up-0.1.0 app/helpers/paid_up/features_helper.rb