Class: EditInPlace::FieldType Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/edit_in_place/field_type.rb

Overview

This class is abstract.

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.

Author:

  • Jacob Lockard

Since:

  • 0.1.0

Instance Method Summary collapse

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:

  1. uses #validate_mode! to ensure that the mode is supported, and

  2. 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.

Parameters:

  • options (FieldOptions)

    options passed by the Builder instance that should be used to render the field.

  • args (Array<Object>)

    the arguments passed by the field creator.

Returns:

  • (String)

    the rendered HTML.

Since:

  • 0.1.0



25
26
27
28
# File 'lib/edit_in_place/field_type.rb', line 25

def render(options, *args)
  validate_mode!(options.mode)
  send("render_#{options.mode}", options, *args)
end

#supported_modesArray<Symbol>

Note:

Subclasses should override this method as appropriate.

Gets the modes that are supported by this field type, :viewing and :editing by default.

Returns:

  • (Array<Symbol>)

    the modes supported by this field type.

Since:

  • 0.1.0



33
34
35
# File 'lib/edit_in_place/field_type.rb', line 33

def supported_modes
  %i[viewing editing]
end