class Voom::Presenters::DSL::Components::TextField
Constants
- VALID_CASE_TYPES
Attributes
auto_complete[R]
behavior[R]
case_type[R]
full_width[R]
required[R]
Public Class Methods
new(**attribs_, &block)
click to toggle source
Calls superclass method
Voom::Presenters::DSL::Components::Input::new
# File lib/voom/presenters/dsl/components/text_field.rb, line 15 def initialize(**attribs_, &block) super(type: :text_field, **attribs_, &block) @required = attribs.delete(:required){ false } @full_width = attribs.delete(:full_width){ true } @case_type = validate_case_type(attribs.delete(:case_type) { :mixed }) @auto_complete = validate_auto_complete(attribs.delete(:auto_complete) { :off }) @behavior = determine_behavior(attribs.delete(:password), attribs.delete(:behavior)) label(attribs.delete(:label))if attribs.key?(:label) value(attribs.delete(:value))if attribs.key?(:value) expand! end
Public Instance Methods
hint(hint=nil)
click to toggle source
# File lib/voom/presenters/dsl/components/text_field.rb, line 48 def hint(hint=nil) return @hint if locked? @hint = hint end
icon(icon=nil, **attribs, &block)
click to toggle source
# File lib/voom/presenters/dsl/components/text_field.rb, line 32 def icon(icon=nil, **attribs, &block) return @icon if locked? @icon = Components::Icon.new(parent: self, icon: icon, position: attribs.delete(:position){:right}, **attribs, &block) end
label(text=nil)
click to toggle source
# File lib/voom/presenters/dsl/components/text_field.rb, line 27 def label(text=nil) return @label if locked? @label = text end
pattern(pattern=nil)
click to toggle source
# File lib/voom/presenters/dsl/components/text_field.rb, line 43 def pattern(pattern=nil) return @pattern if locked? @pattern = json_regexp(Regexp.new(pattern)) end
value(value=nil)
click to toggle source
# File lib/voom/presenters/dsl/components/text_field.rb, line 38 def value(value=nil) return @value if locked? @value = value end
Private Instance Methods
determine_behavior(password, behavior)
click to toggle source
# File lib/voom/presenters/dsl/components/text_field.rb, line 92 def determine_behavior(password, behavior) unless password.nil? logger.warn( 'The `password` attribute of text_field is deprecated. ' \ 'Use `text_field behavior: :password` instead.' ) end case password when nil behavior when true :password when false :text end end
json_regexp(regexp)
click to toggle source
# File lib/voom/presenters/dsl/components/text_field.rb, line 60 def json_regexp(regexp) str = regexp.inspect. sub('\\A', '^'). sub('\\Z', '$'). sub('\\z', '$'). sub(/^\//, ''). sub(/\/[a-z]*$/, ''). gsub(/\(\?#.+\)/, ''). gsub(/\(\?-\w+:/, '('). gsub(/\s/, '') Regexp.new(str).source end
validate_auto_complete(value)
click to toggle source
# File lib/voom/presenters/dsl/components/text_field.rb, line 73 def validate_auto_complete(value) case value when false, :disabled, 'disabled', 'off', nil :off when true, :enabled, 'enabled', 'on' :on else # :on, :off, client-specific values value end end
validate_case_type(case_type)
click to toggle source
# File lib/voom/presenters/dsl/components/text_field.rb, line 84 def validate_case_type(case_type) return unless case_type case_type = case_type.to_sym raise Errors::ParameterValidation, "Invalid case type specified: #{case_type}" unless VALID_CASE_TYPES.include?(case_type) case_type end