Module: Pageflow::Admin::FeaturesHelper

Defined in:
app/helpers/pageflow/admin/features_helper.rb

Instance Method Summary collapse

Instance Method Details

#feature_state_display_name(state) ⇒ Object



30
31
32
33
# File 'app/helpers/pageflow/admin/features_helper.rb', line 30

def feature_state_display_name(state)
  I18n.t(FeatureTarget::STATE_MAPPING[state],
         scope: 'pageflow.admin.features.states')
end

#feature_state_input_name(feature_target, feature_name) ⇒ Object



15
16
17
18
# File 'app/helpers/pageflow/admin/features_helper.rb', line 15

def feature_state_input_name(feature_target, feature_name)
  param_key = feature_target.class.model_name.param_key
  "#{param_key}[feature_states][#{feature_name}]"
end

#feature_state_select_tag(feature_target, feature_name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'app/helpers/pageflow/admin/features_helper.rb', line 4

def feature_state_select_tag(feature_target, feature_name)
  own_state = feature_target.own_feature_state(feature_name)
  inherited_state = feature_target.inherited_feature_state(feature_name)

  value = FeatureTarget::STATE_MAPPING[own_state]
  collection = feature_states_collection(inherited_state)

  select_tag(feature_state_input_name(feature_target, feature_name),
             options_for_select(collection, value))
end

#feature_states_collection(inherited_feature_state) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'app/helpers/pageflow/admin/features_helper.rb', line 20

def feature_states_collection(inherited_feature_state)
  default_item_label = I18n.t('pageflow.admin.features.states.default',
                              inherited: feature_state_display_name(inherited_feature_state))
  {
    default_item_label => FeatureTarget::STATE_MAPPING[nil],
    feature_state_display_name(true) => FeatureTarget::STATE_MAPPING[true],
    feature_state_display_name(false) => FeatureTarget::STATE_MAPPING[false]
  }
end