Class: Locomotive::CurrentSiteMetafieldsHelper::SchemaField
- Inherits:
-
Object
- Object
- Locomotive::CurrentSiteMetafieldsHelper::SchemaField
- Defined in:
- app/helpers/locomotive/current_site_metafields_helper.rb
Instance Method Summary collapse
- #default_input_options ⇒ Object
- #hint ⇒ Object
-
#initialize(site, namespace, attributes) ⇒ SchemaField
constructor
A new instance of SchemaField.
- #input_options ⇒ Object
- #label ⇒ Object
- #name ⇒ Object
- #position ⇒ Object
- #select_collection ⇒ Object
- #type ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(site, namespace, attributes) ⇒ SchemaField
Returns a new instance of SchemaField.
58 59 60 |
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 58 def initialize(site, namespace, attributes) @site, @namespace, @attributes = site, namespace, attributes end |
Instance Method Details
#default_input_options ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 106 def { label: self.label, hint: self.hint.try(:html_safe), as: self.type, required: false } end |
#hint ⇒ Object
70 71 72 |
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 70 def hint t(@attributes['hint']) end |
#input_options ⇒ Object
83 84 85 86 87 88 89 |
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 83 def case type when :select then { collection: select_collection } else {} end.merge() end |
#label ⇒ Object
66 67 68 |
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 66 def label t(@attributes['label'] || @attributes['name'].humanize) end |
#name ⇒ Object
62 63 64 |
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 62 def name t(@attributes['name']).downcase.underscore.gsub(' ', '_') end |
#position ⇒ Object
98 99 100 |
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 98 def position @attributes['position'] end |
#select_collection ⇒ Object
91 92 93 94 95 96 |
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 91 def select_collection @attributes['select_options'].map do |name, label| label = { 'default' => name.humanize } if label.blank? [(t(label) || name).html_safe, name] end end |
#type ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 74 def type @type ||= case (type = @attributes['type'].try(:to_sym)) when :boolean then :toggle when :text then :rte else type || :string end end |
#value ⇒ Object
102 103 104 |
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 102 def value t((@site.[@namespace] || {})[name], ::Mongoid::Fields::I18n.locale.to_s) end |