class Trenni::Formatters::HTML::OptionSelect
Standard drop-down select box:
Public Class Methods
call(formatter, builder, **options, &block)
click to toggle source
# File lib/trenni/formatters/html/option_select.rb, line 30 def self.call(formatter, builder, **options, &block) instance = self.new(formatter, builder, **options) instance.call(&block) end
new(formatter, builder, **options)
click to toggle source
# File lib/trenni/formatters/html/option_select.rb, line 36 def initialize(formatter, builder, **options) @formatter = formatter @builder = builder @options = options end
Public Instance Methods
call(&block)
click to toggle source
# File lib/trenni/formatters/html/option_select.rb, line 134 def call(&block) Builder.fragment(@builder) do |builder| builder.tag :select, select_attributes_for(**@options) do if self.optional? builder << item(title: optional_title_for(**@options), value: nil) end builder.capture(self, &block) end end end
group(**options, &block)
click to toggle source
# File lib/trenni/formatters/html/option_select.rb, line 109 def group(**options, &block) @builder.tag :optgroup, group_attributes_for(**options) do if options[:optional] item(title: optional_title_for(**options), value: nil) end @builder.capture(&block) end end
group_attributes_for(**options)
click to toggle source
# File lib/trenni/formatters/html/option_select.rb, line 100 def group_attributes_for(**options) return { :label => title_for(**options), :id => options[:id], :class => options[:class], :data => options[:data], } end
item(**options, &block)
click to toggle source
# File lib/trenni/formatters/html/option_select.rb, line 78 def item(**options, &block) options[:field] ||= 'id' Builder.fragment(block&.binding || @builder) do |builder| builder.inline(:option, option_attributes_for(**options)) do if block_given? builder.capture(self, &block) else builder.text title_for(**options) end end end end
name_for(**options)
click to toggle source
# File lib/trenni/formatters/html/option_select.rb, line 42 def name_for(**options) if name = @formatter.name_for(**options) if options[:multiple] name = "#{name}[]" end return name end end
option_attributes_for(**options)
click to toggle source
# File lib/trenni/formatters/html/option_select.rb, line 68 def option_attributes_for(**options) return { :value => value_for(**options), :selected => options.fetch(:selected) {raw_value == raw_value_for(**options)}, :id => options[:id], :class => options[:class], :data => options[:data], } end
optional?()
click to toggle source
# File lib/trenni/formatters/html/option_select.rb, line 130 def optional? @options[:optional] end
optional_title_for(**options)
click to toggle source
# File lib/trenni/formatters/html/option_select.rb, line 92 def optional_title_for(**options) if options[:optional] == true options[:blank] || '' else options[:optional] end end
raw_value()
click to toggle source
# File lib/trenni/formatters/html/option_select.rb, line 56 def raw_value @raw_value ||= raw_value_for(**@options) end
raw_value_for(**options)
click to toggle source
# File lib/trenni/formatters/html/option_select.rb, line 52 def raw_value_for(**options) @formatter.raw_value_for(**options) end
select_attributes_for(**options)
click to toggle source
# File lib/trenni/formatters/html/option_select.rb, line 119 def select_attributes_for(**options) return { :name => name_for(**options), :id => options[:id], :class => options[:class], :multiple => options[:multiple], :data => options[:data], :required => options[:required], } end
title_for(**options)
click to toggle source
# File lib/trenni/formatters/html/option_select.rb, line 64 def title_for(**options) @formatter.title_for(**options) end
value_for(**options)
click to toggle source
# File lib/trenni/formatters/html/option_select.rb, line 60 def value_for(**options) @formatter.value_for(**options) end