Class: EditInPlace::FieldType Abstract
- Inherits:
-
Object
- Object
- EditInPlace::FieldType
- Defined in:
- lib/edit_in_place/field_type.rb
Overview
FieldType is a class that represents a single type of field. A field is a single, self-contained component that displays data in various “modes”, typically either “viewing” or “editing”. Field types provide the templates for similar fields.
Instance Method Summary collapse
-
#render(options, *args) ⇒ String
Render the field, given a FieldOptions instance and an array of arguments passed by the caller.
-
#supported_modes ⇒ Array<Symbol>
Gets the modes that are supported by this field type,
:viewing
and:editing
by default.
Instance Method Details
#render(options, *args) ⇒ String
Render the field, given a EditInPlace::FieldOptions instance and an array of arguments passed by the caller.
While subclasses may override this method as appropriate, the default implementation simply does two things:
-
uses #validate_mode! to ensure that the mode is supported, and
-
calls a
render_*
method.
For example, if the mode were :admin_editing
, then a render_admin_editing
method would be called. Naturally, the render_*
methods need to be defined by the subclass.
25 26 27 28 |
# File 'lib/edit_in_place/field_type.rb', line 25 def render(, *args) validate_mode!(.mode) send("render_#{.mode}", , *args) end |
#supported_modes ⇒ Array<Symbol>
Subclasses should override this method as appropriate.
Gets the modes that are supported by this field type, :viewing
and :editing
by default.
33 34 35 |
# File 'lib/edit_in_place/field_type.rb', line 33 def supported_modes %i[viewing editing] end |