richer_text 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/helpers/richer_text/tag_helper.rb +37 -0
- data/app/models/richer_text/json_text.rb +15 -2
- data/lib/richer_text/html_visitor.rb +22 -0
- data/lib/richer_text/node.rb +2 -2
- data/lib/richer_text/nodes/attachment_figure.rb +17 -0
- data/lib/richer_text/nodes/attachment_gallery.rb +6 -0
- data/lib/richer_text/version.rb +1 -1
- data/lib/richer_text.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a91f47881a33b61d264e59fe2500da26b0ba346f3fe1eda0b2f2a3e8759e6700
|
4
|
+
data.tar.gz: a5a605c07462c979d3b30cce5c9756cb65a7d4a271ca463edb2e75e81192a859
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d4faf62c78eb8bc372f11c2f0c9209eb14d0c0c622b79cab2c19de14a01da6c9fd4705a7384548bdb810fea8ad7cce4ca87c28fb9e7181974962054af217746
|
7
|
+
data.tar.gz: e462e01e68d7edbb0cea0882e28469fdf8b9aaed92df8f7df7ed405abda49b78e9bb1f7c9dff62df081bbdfff30d0d8dbade9b7c9cc88a71aac77c8cdc6a15f8
|
@@ -17,16 +17,40 @@ module ActionView::Helpers
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
class Tags::RhinoEditor < Tags::Base
|
21
|
+
include Tags::Placeholderable
|
22
|
+
|
23
|
+
delegate :dom_id, to: ActionView::RecordIdentifier
|
24
|
+
|
25
|
+
def render
|
26
|
+
options = @options.stringify_keys
|
27
|
+
add_default_name_and_id(options)
|
28
|
+
options["input"] ||= dom_id(object, [options["id"], :rhino_text_input].compact.join("_")) if object
|
29
|
+
options["value"] = options.fetch("value") { value&.to_editor_format }
|
30
|
+
options["serializer"] = options.fetch("serializer") { "html"}
|
31
|
+
|
32
|
+
@template_object.rhino_text_area_tag(options.delete("name"), options["value"], options.except("value"))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
20
36
|
module FormHelper
|
21
37
|
def richer_text_area(object_name, method, options = {})
|
22
38
|
Tags::Editor.new(object_name, method, self, options).render
|
23
39
|
end
|
40
|
+
|
41
|
+
def rhino_text_area(object_name, method, options = {})
|
42
|
+
Tags::RhinoEditor.new(object_name, method, self, options).render
|
43
|
+
end
|
24
44
|
end
|
25
45
|
|
26
46
|
class FormBuilder
|
27
47
|
def richer_text_area(method, options = {})
|
28
48
|
@template.richer_text_area(@object_name, method, objectify_options(options))
|
29
49
|
end
|
50
|
+
|
51
|
+
def rhino_text_area(method, options = {})
|
52
|
+
@template.rhino_text_area(@object_name, method, objectify_options(options))
|
53
|
+
end
|
30
54
|
end
|
31
55
|
end
|
32
56
|
|
@@ -49,5 +73,18 @@ module RicherText
|
|
49
73
|
|
50
74
|
input_tag + editor_tag
|
51
75
|
end
|
76
|
+
|
77
|
+
def rhino_text_area_tag(name, value = nil, options = {})
|
78
|
+
options = options.symbolize_keys
|
79
|
+
options[:input] ||= "rhino_text_input_#{RicherText::TagHelper.id += 1}"
|
80
|
+
|
81
|
+
# So we can choose the serializer to use, e.g. "html" or "json"
|
82
|
+
options[:serializer] ||= "html"
|
83
|
+
|
84
|
+
input_tag = hidden_field_tag(name, value, id: options[:input])
|
85
|
+
editor_tag = tag("rhino-editor", { input: options[:input], serializer: "json", data: { "blob-url-template": rails_service_blob_url(":signed_id", ":filename"), "direct-upload-url": rails_direct_uploads_url }}.merge(options))
|
86
|
+
|
87
|
+
input_tag + editor_tag
|
88
|
+
end
|
52
89
|
end
|
53
90
|
end
|
@@ -7,8 +7,9 @@ module RicherText
|
|
7
7
|
serialize :body, JSON, default: DEFAULT_BODY.to_json
|
8
8
|
|
9
9
|
has_many_attached :images
|
10
|
+
has_many_attached :rhino_attachments # For handling attachments in the Rhino Editor
|
10
11
|
|
11
|
-
before_save :
|
12
|
+
before_save :update_attachments
|
12
13
|
|
13
14
|
def to_editor_format
|
14
15
|
body
|
@@ -20,16 +21,28 @@ module RicherText
|
|
20
21
|
|
21
22
|
private
|
22
23
|
|
23
|
-
def
|
24
|
+
def update_attachments
|
24
25
|
self.images = image_nodes.map(&:signed_id)
|
26
|
+
self.rhino_attachments = rhino_attachment_records.map(&:signed_id)
|
25
27
|
end
|
26
28
|
|
27
29
|
def image_nodes
|
28
30
|
find_nodes_of_type(RicherText::Nodes::Image).flatten.compact_blank
|
29
31
|
end
|
30
32
|
|
33
|
+
def rhino_attachment_nodes
|
34
|
+
find_nodes_of_type(RicherText::Nodes::AttachmentFigure).flatten.compact_blank
|
35
|
+
end
|
36
|
+
|
37
|
+
def rhino_attachment_records
|
38
|
+
sgids = rhino_attachment_nodes.map(&:sgid).compact_blank
|
39
|
+
GlobalID::Locator.locate_many_signed(sgids, for: "attachable")
|
40
|
+
end
|
41
|
+
|
31
42
|
def find_nodes_of_type(type, node = document)
|
32
43
|
if node.children.any?
|
44
|
+
return node if node.is_a?(type)
|
45
|
+
|
33
46
|
node.children.map { |child| find_nodes_of_type(type, child) }
|
34
47
|
else
|
35
48
|
node.is_a?(type) ? node : nil
|
@@ -6,6 +6,18 @@ module RicherText
|
|
6
6
|
node.accept(self)
|
7
7
|
end
|
8
8
|
|
9
|
+
def visit_attachment_figure(node)
|
10
|
+
"<figure sgid=#{node.attrs["sgid"]}>
|
11
|
+
#{node_previewable?(node) ? "<img src=#{node.url} />" : "<a href=#{node.url} target='_blank'>"}
|
12
|
+
<figcaption class='attachment__caption'>#{visit_children(node).join}</figcaption>
|
13
|
+
#{node_previewable?(node) ? "" : "</a>"}
|
14
|
+
</figure>"
|
15
|
+
end
|
16
|
+
|
17
|
+
def visit_attachment_gallery(node)
|
18
|
+
"<div class='attachment-gallery'>#{visit_children(node).join}</div>"
|
19
|
+
end
|
20
|
+
|
9
21
|
def visit_blockquote(node)
|
10
22
|
"<blockquote>#{visit_children(node).join}</blockquote>"
|
11
23
|
end
|
@@ -81,5 +93,15 @@ module RicherText
|
|
81
93
|
def visit_table_header(node)
|
82
94
|
"<th>#{visit_children(node).join}</th>"
|
83
95
|
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def previewable_regex
|
100
|
+
/^image(\/(gif|png|jpe?g)|$)/
|
101
|
+
end
|
102
|
+
|
103
|
+
def node_previewable?(node)
|
104
|
+
node.attrs["contentType"].match(previewable_regex)
|
105
|
+
end
|
84
106
|
end
|
85
107
|
end
|
data/lib/richer_text/node.rb
CHANGED
@@ -8,8 +8,8 @@ module RicherText
|
|
8
8
|
|
9
9
|
def self.build(json)
|
10
10
|
node = json.is_a?(String) ? JSON.parse(json) : json
|
11
|
-
klass = "RicherText::Nodes::#{node["type"].underscore.classify}".
|
12
|
-
klass.new(node)
|
11
|
+
klass = "RicherText::Nodes::#{node["type"].underscore.classify}".constantize
|
12
|
+
klass.new(node) if klass
|
13
13
|
end
|
14
14
|
|
15
15
|
def initialize(json)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RicherText
|
2
|
+
module Nodes
|
3
|
+
class AttachmentFigure < ::RicherText::Node
|
4
|
+
def previewable?
|
5
|
+
@attrs["previewable"]
|
6
|
+
end
|
7
|
+
|
8
|
+
def url
|
9
|
+
@attrs["url"].presence || @attrs["src"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def sgid
|
13
|
+
@attrs["sgid"]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/richer_text/version.rb
CHANGED
data/lib/richer_text.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: richer_text
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrea Fomera
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -59,6 +59,8 @@ files:
|
|
59
59
|
- lib/richer_text/html_visitor.rb
|
60
60
|
- lib/richer_text/mark.rb
|
61
61
|
- lib/richer_text/node.rb
|
62
|
+
- lib/richer_text/nodes/attachment_figure.rb
|
63
|
+
- lib/richer_text/nodes/attachment_gallery.rb
|
62
64
|
- lib/richer_text/nodes/blockquote.rb
|
63
65
|
- lib/richer_text/nodes/bullet_list.rb
|
64
66
|
- lib/richer_text/nodes/callout.rb
|