Class: Arara::Tags::CountrySelect

Inherits:
ActionView::Helpers::Tags::Base
  • Object
show all
Includes:
CountrySelect::TagHelper
Defined in:
app/components/arara/tags/country_select.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(object_name, method_name, template_object, options, html_options) ⇒ CountrySelect

super(object_name, method_name, template_object, options) end



16
17
18
19
20
# File 'app/components/arara/tags/country_select.rb', line 16

def initialize(object_name, method_name, template_object, options, html_options)
  @html_options = html_options

  super(object_name, method_name, template_object, options)
end

Instance Method Details

#options_for_select(container, selected = nil) ⇒ Object

my method



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/components/arara/tags/country_select.rb', line 53

def options_for_select(container, selected = nil)
  return container if String === container

  selected, disabled = extract_selected_and_disabled(selected).map do |r|
    Array(r).map(&:to_s)
  end

  container.map do |element|
    html_attributes = option_html_attributes(element)
    text, value = option_text_and_value(element).map(&:to_s)

    html_attributes[:selected] ||= option_value_selected?(value, selected)
    html_attributes[:disabled] ||= disabled && option_value_selected?(value, disabled)
    html_attributes[:value] = value

    # also set the label
    html_attributes[:label] = text

    # and render our component
    @template_object.template.render(Arara::SelectItemComponent, html_attributes.symbolize_keys)
  end.join("\n").html_safe
end

#renderObject

select_content_tag(option_tags, @options, @html_options) end



48
49
50
# File 'app/components/arara/tags/country_select.rb', line 48

def render
  (country_option_tags, @options, @html_options)
end

#select_content_tag(option_tags, options, html_options) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/components/arara/tags/country_select.rb', line 76

def (option_tags, options, html_options)
  html_options = html_options.stringify_keys
  add_default_name_and_id(html_options)
  
  if placeholder_required?(html_options)
    raise ArgumentError, "include_blank cannot be false for a required field." if options[:include_blank] == false
    options[:include_blank] ||= true unless options[:prompt]
  end
  
  value = options.fetch(:selected) { value() }
  select = ("select", add_options(option_tags, options, value), html_options)
  
  if html_options["multiple"] && options.fetch(:include_hidden, true)
    tag("input", disabled: html_options["disabled"], name: html_options["name"], type: "hidden", value: "") + select
  else
    select
  end

  select_options = options.merge(html_options)
  @template_object.template.render(Arara::SelectComponent, select_options.symbolize_keys) do
    option_tags
  end
end