Class: Milk::Field
Overview
A field is a data type for part of a component. This way components can be quickly built without coding any logic. The fields take care of the heavy work.
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
Instance Method Summary collapse
- #form_field ⇒ Object
-
#initialize(props) ⇒ Field
constructor
Store the field configurations.
-
#name ⇒ Object
This is the name shown to the user for the field.
-
#render(component, prefix) ⇒ Object
This is called to render the html for a field’s form.
- #value ⇒ Object
Constructor Details
#initialize(props) ⇒ Field
Store the field configurations
11 12 13 14 15 |
# File 'lib/milk/field.rb', line 11 def initialize(props) props.each do |key, value| self.instance_variable_set('@' + key.to_s, value) end end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
8 9 10 |
# File 'lib/milk/field.rb', line 8 def field @field end |
Instance Method Details
#form_field ⇒ Object
22 23 24 |
# File 'lib/milk/field.rb', line 22 def form_field @prefix end |
#name ⇒ Object
This is the name shown to the user for the field.
18 19 20 |
# File 'lib/milk/field.rb', line 18 def name @label || self.class.to_s.rpartition('::').last end |
#render(component, prefix) ⇒ Object
This is called to render the html for a field’s form
31 32 33 34 35 36 37 |
# File 'lib/milk/field.rb', line 31 def render(component, prefix) @component = component @prefix = prefix name = self.class.to_s.rpartition('::').last.gsub(/([a-z])([A-Z])/) { "#{$1}_#{$2}" }.downcase haml("fields/#{name}") end |
#value ⇒ Object
26 27 28 |
# File 'lib/milk/field.rb', line 26 def value @component.instance_variable_get('@' + @field.to_s) end |