Class: ActionText::Editor

Inherits:
Object show all
Extended by:
ActiveSupport::Autoload
Defined in:
actiontext/lib/action_text/editor.rb

Overview

:nodoc:

Direct Known Subclasses

TrixEditor

Defined Under Namespace

Classes: Configurator, Registry, Tag, TrixEditor

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ActiveSupport::Autoload

autoload, autoload_at, autoload_under, eager_autoload, eager_load!

Constructor Details

#initialize(options = {}) ⇒ Editor

Returns a new instance of Editor.



12
13
14
# File 'actiontext/lib/action_text/editor.rb', line 12

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'actiontext/lib/action_text/editor.rb', line 10

def options
  @options
end

Instance Method Details

#as_canonical(editable_fragment) ⇒ Object

Convert fragments served by the editor into the canonical form that Action Text stores.

def as_canonical(editable_fragment)
  editable_fragment.replace "my-editor-attachment" do |editor_attachment|
    ActionText::Attachment.from_attributes(
      "sgid" => editor_attachment["sgid"],
      "content-type" => editor_attachment["content-type"]
    )
  end
end


26
27
28
# File 'actiontext/lib/action_text/editor.rb', line 26

def as_canonical(editable_fragment)
  editable_fragment
end

#as_editable(canonical_fragment) ⇒ Object

Convert fragments from the canonical form that Action Text stores into a format that is supported by the editor.

def as_editable(canonical_fragment)
  canonical_fragment.replace ActionText::Attachment.tag_name do |action_text_attachment|
    attachment_attributes = {
      "sgid" => action_text_attachment["sgid"],
      "content-type" => action_text_attachment["content-type"]
    }

    ActionText::HtmlConversion.create_element("my-editor-attachment", attachment_attributes)
  end
end


42
43
44
# File 'actiontext/lib/action_text/editor.rb', line 42

def as_editable(canonical_fragment)
  canonical_fragment
end

#editor_nameObject



46
47
48
# File 'actiontext/lib/action_text/editor.rb', line 46

def editor_name
  self.class.name.demodulize.delete_suffix("Editor").underscore
end

#editor_tagObject



50
51
52
# File 'actiontext/lib/action_text/editor.rb', line 50

def editor_tag(...)
  Tag.new(editor_name, ...)
end