Module: Pigeon::ChannelHelper
- Includes:
- ActionView::Helpers::CaptureHelper, ActionView::Helpers::FormHelper, ActionView::Helpers::FormOptionsHelper
- Included in:
- Renderer::ChannelRenderer
- Defined in:
- app/helpers/pigeon/channel_helper.rb
Instance Method Summary collapse
- #pigeon_attribute(attribute, value = nil, options = {}) ⇒ Object
- #pigeon_attribute_field(attribute, value = nil, options = {}) ⇒ Object
- #pigeon_attribute_label(attribute, options = {}) ⇒ Object
- #pigeon_channel_attribute(channel, attr_name, options = {}) ⇒ Object
- #pigeon_channel_attribute_field(channel, attr_name, options = {}) ⇒ Object
- #pigeon_channel_attribute_label(channel, attr_name, options = {}) ⇒ Object
Instance Method Details
#pigeon_attribute(attribute, value = nil, options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/pigeon/channel_helper.rb', line 52 def pigeon_attribute(attribute, value = nil, = {}) scope = .delete(:scope) field_with_errors = .delete(:field_with_errors) content_tag :div, do label = pigeon_attribute_label(attribute, scope: scope) field = pigeon_attribute_field(attribute, value, scope: scope) if field_with_errors.present? field = content_tag :div, field, :class => 'field_with_errors' end if attribute.type == :boolean safe_join([field, label]) elsif attribute.type == :hidden field else safe_join([label, tag(:br), field]) end end end |
#pigeon_attribute_field(attribute, value = nil, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/pigeon/channel_helper.rb', line 7 def pigeon_attribute_field(attribute, value = nil, = {}) scope = .delete(:scope) field_name = attribute.scoped_name(scope) field_value = value || '' forced_type = .delete(:type) render_type = (forced_type || attribute.type).to_s case render_type when "string" text_field_tag(field_name, field_value, ) when "password" password_field_tag(field_name, field_value, ) when "integer" number_field_tag(field_name, field_value, ) when "enum" choices = attribute. if choices.length > 0 && choices[0].is_a?(Hash) choices = choices.map { |h| [h["display"], h["value"]] } end select_tag(field_name, (choices, field_value), ) when "multi" choices = attribute. if choices.length > 0 && choices[0].is_a?(Hash) choices = choices.map { |h| [h["display"], h["value"]] } end select_tag(field_name, (choices, field_value), { :multiple => true }.merge()) when "timezone" select_tag(field_name, (field_value), ) when "boolean" check_box_tag(field_name, '1', field_value.present?, ) when "hidden" hidden_field_tag(field_name, field_value, ) else text_field_tag(field_name, field_value, { :type => render_type }.merge()) end end |
#pigeon_attribute_label(attribute, options = {}) ⇒ Object
45 46 47 48 49 50 |
# File 'app/helpers/pigeon/channel_helper.rb', line 45 def pigeon_attribute_label(attribute, = {}) return '' if attribute.type == :hidden scope = .delete(:scope) field_name = attribute.scoped_name(scope) label_tag(field_name, attribute.label, ) end |
#pigeon_channel_attribute(channel, attr_name, options = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'app/helpers/pigeon/channel_helper.rb', line 89 def pigeon_channel_attribute(channel, attr_name, = {}) value = channel.read_attribute(attr_name) attribute = channel.schema.try(:find_attribute, attr_name) attribute ||= ChannelAttribute.build_default(attr_name, value) if channel.errors.include?(attr_name.to_sym) [:field_with_errors] = true end pigeon_attribute(attribute, value, ) end |
#pigeon_channel_attribute_field(channel, attr_name, options = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/helpers/pigeon/channel_helper.rb', line 71 def pigeon_channel_attribute_field(channel, attr_name, = {}) value = channel.read_attribute(attr_name) attribute = channel.schema.try(:find_attribute, attr_name) attribute ||= ChannelAttribute.build_default(attr_name, value) field = pigeon_attribute_field(attribute, value, ) if channel.errors.include?(attr_name.to_sym) content_tag :div, field, :class => 'field_with_errors' else field end end |
#pigeon_channel_attribute_label(channel, attr_name, options = {}) ⇒ Object
83 84 85 86 87 |
# File 'app/helpers/pigeon/channel_helper.rb', line 83 def pigeon_channel_attribute_label(channel, attr_name, = {}) attribute = channel.schema.try(:find_attribute, attr_name) attribute ||= ChannelAttribute.build_default(attr_name) pigeon_attribute_label(attribute, ) end |