Class: EOTS::Field
- Inherits:
-
Object
- Object
- EOTS::Field
- Defined in:
- app/models/eots/field.rb
Constant Summary collapse
- AlreadyDefinedError =
Class.new(RuntimeError)
- InvalidSectionError =
Class.new(RuntimeError)
Instance Attribute Summary collapse
-
#caption ⇒ Object
readonly
Returns the value of attribute caption.
-
#html_options ⇒ Object
readonly
Returns the value of attribute html_options.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#must_match ⇒ Object
readonly
Returns the value of attribute must_match.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#section ⇒ Object
readonly
Returns the value of attribute section.
Instance Method Summary collapse
- #html(form) ⇒ Object
-
#initialize(name, label, options = {}) ⇒ Field
constructor
A new instance of Field.
- #required? ⇒ Boolean
Constructor Details
#initialize(name, label, options = {}) ⇒ Field
Returns a new instance of Field.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/models/eots/field.rb', line 8 def initialize(name, label, ={}) @name = name.to_s @label = label opts = .dup @caption = opts.delete(:caption) @section = opts.delete(:section) || :body @must_match = opts.delete(:must_match) unless [:header, :body, :footer].include? @section raise(InvalidSectionError, "Invalid section '#{@section}' -- must be :header, :body, or :footer") end apply_defaults(opts) @html_options = opts end |
Instance Attribute Details
#caption ⇒ Object (readonly)
Returns the value of attribute caption.
6 7 8 |
# File 'app/models/eots/field.rb', line 6 def caption @caption end |
#html_options ⇒ Object (readonly)
Returns the value of attribute html_options.
6 7 8 |
# File 'app/models/eots/field.rb', line 6 def @html_options end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
6 7 8 |
# File 'app/models/eots/field.rb', line 6 def label @label end |
#must_match ⇒ Object (readonly)
Returns the value of attribute must_match.
6 7 8 |
# File 'app/models/eots/field.rb', line 6 def must_match @must_match end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'app/models/eots/field.rb', line 6 def name @name end |
#section ⇒ Object (readonly)
Returns the value of attribute section.
6 7 8 |
# File 'app/models/eots/field.rb', line 6 def section @section end |
Instance Method Details
#html(form) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/eots/field.rb', line 23 def html(form) star = "* " if required? result = form.label_tag(name, "#{star}#{label}".html_safe) type = [:type] if type.to_sym == :checkbox # to_sym 'cuz it could be string or symbol result << form.content_tag(:span, " ") # just to provide a spacer opts = .dup checked = opts.delete :checked result << form.check_box_tag(name, name, checked, opts) else result << form.tag(:br) tag = "#{type}_field_tag".gsub("textarea_field", "text_area").to_sym result << form.send(tag, name, nil, ) end if caption result << form.tag(:br) result << form.content_tag(:small, caption.html_safe) end result end |
#required? ⇒ Boolean
44 45 46 |
# File 'app/models/eots/field.rb', line 44 def required? [:required] end |