Class: Avo::LexxyField::Fields::LexxyField
- Inherits:
-
Fields::BaseField
- Object
- Fields::BaseField
- Avo::LexxyField::Fields::LexxyField
- Defined in:
- lib/avo/lexxy_field/fields/lexxy_field.rb
Constant Summary collapse
- EDITOR_OPTIONS =
Lexxy's per-editor options, which it reads off the element as dasherized attributes and JSON-parses.
attachmentsis omitted on purpose —attachments_disabledbelow owns it. See https://lexxy.dev/docs/ for what each one takes. %i[ preset markdown rich_text multi_line headings toolbar highlight permitted_attachment_types ].freeze
Instance Attribute Summary collapse
-
#always_show ⇒ Object
readonly
Returns the value of attribute always_show.
Instance Method Summary collapse
- #attachments_disabled ⇒ Object
- #component_for_view(view) ⇒ Object
-
#editor_attributes ⇒ Object
The editor options as element attributes.
-
#initialize(id, **args, &block) ⇒ LexxyField
constructor
A new instance of LexxyField.
-
#is_action_text? ⇒ Boolean
Identify if field is bonded to a rich text model attribute.
- #view_component_namespace ⇒ Object
Constructor Details
#initialize(id, **args, &block) ⇒ LexxyField
Returns a new instance of LexxyField.
25 26 27 28 29 30 31 32 33 |
# File 'lib/avo/lexxy_field/fields/lexxy_field.rb', line 25 def initialize(id, **args, &block) super(id, **args, &block) hide_on :index @always_show = args[:always_show] || false @attachments_disabled = args[:attachments_disabled] @editor_options = args.slice(*EDITOR_OPTIONS) end |
Instance Attribute Details
#always_show ⇒ Object (readonly)
Returns the value of attribute always_show.
23 24 25 |
# File 'lib/avo/lexxy_field/fields/lexxy_field.rb', line 23 def always_show @always_show end |
Instance Method Details
#attachments_disabled ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/avo/lexxy_field/fields/lexxy_field.rb', line 50 def # Return the value of attachments_disabled if explicitly provided return @attachments_disabled unless @attachments_disabled.nil? # Lexxy uploads through Active Storage direct uploads and relies on # Action Text to attach the blobs to the record on save. On plain # columns the uploads would remain orphaned blobs, so disable them. !is_action_text? end |
#component_for_view(view) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/avo/lexxy_field/fields/lexxy_field.rb', line 64 def component_for_view(view) view = Avo::ViewInquirer.new(view) if view.edit? && (is_readonly? || is_disabled?) Avo::Fields::LexxyField::ShowComponent else super end end |
#editor_attributes ⇒ Object
The editor options as element attributes. Anything that isn't already a string goes over as JSON, which is what Lexxy parses it back from.
37 38 39 40 41 |
# File 'lib/avo/lexxy_field/fields/lexxy_field.rb', line 37 def editor_attributes @editor_options.to_h do |name, value| [name.to_s.dasherize, value.is_a?(String) || value.is_a?(Symbol) ? value.to_s : value.to_json] end end |
#is_action_text? ⇒ Boolean
Identify if field is bonded to a rich text model attribute
44 45 46 47 48 |
# File 'lib/avo/lexxy_field/fields/lexxy_field.rb', line 44 def is_action_text? return false if !defined?(ActionText::RichText) || record.nil? || !record.respond_to?(id) record.send(id).is_a?(ActionText::RichText) end |
#view_component_namespace ⇒ Object
60 61 62 |
# File 'lib/avo/lexxy_field/fields/lexxy_field.rb', line 60 def view_component_namespace "Avo::Fields::LexxyField" end |