Module: LexxyRealtime::FormBuilder
- Defined in:
- lib/lexxy_realtime/form_builder.rb
Overview
Renders a Lexxy editor with collaboration configured for the record and field. LexxyRealtime.identity supplies the cursor name and color.
Instance Method Summary collapse
- #collaborative_rich_textarea(method, name: nil, color: nil, **options) ⇒ Object (also: #collaborative_rich_text_area)
Instance Method Details
#collaborative_rich_textarea(method, name: nil, color: nil, **options) ⇒ Object Also known as: collaborative_rich_text_area
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lexxy_realtime/form_builder.rb', line 7 def collaborative_rich_textarea(method, name: nil, color: nil, **) record = object unless record.respond_to?(:collaborative_rich_text?) && record.collaborative_rich_text?(method) raise ArgumentError, "#{record.class.name}##{method} is not collaborative (declare has_collaborative_rich_text :#{method})" end raise ArgumentError, "#{record.class.name} must be persisted to collaborate on it" unless record.persisted? identity = LexxyRealtime.identity.call(@template) collaborator = name || identity[:name] public_send(lexxy_editor_method, method, ) do # The client-side Yjs binding key, shared by peers of this # attribute. The server never sees it. @template.content_tag("lexxy-collaboration", "", "doc-id" => "#{record.model_name.param_key}-#{record.id}-#{method}", "name" => collaborator, "color" => color || identity[:color] || LexxyRealtime.collaborator_color(collaborator), "channel-name" => LexxyRealtime::CHANNEL_NAME, "channel-params" => { sgid: record.to_sgid(for: LexxyRealtime.sgid_purpose(method)).to_s, field: method }.to_json) end end |