richer_text 0.8.0 → 0.9.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/models/richer_text/json_text.rb +10 -0
- data/app/models/richer_text/rich_text.rb +6 -0
- data/lib/richer_text/content.rb +6 -0
- data/lib/richer_text/html_visitor.rb +11 -0
- data/lib/richer_text/nodes/mention.rb +30 -0
- data/lib/richer_text/version.rb +1 -1
- data/lib/richer_text.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03e9732ed2320f56a2c30cbcd6af7614b6840b601aab70d790c96e6e8412babf
|
4
|
+
data.tar.gz: 4413b9240e46d0153dff22c7b4dd7161a555f572ada62b69159f0c267ae7b0b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39f20dfc3cecd2f74f4cc4d01b396d9678ceeed635ff4dc2a35bc62ba0dc8f6361f882dfe1df67b9286d63b1c86fbd6b7e73b729175e8fd3948435eb041a7ade
|
7
|
+
data.tar.gz: 4718871930d84edd4de392d9ea2d321f6a04782e5f0c774906e468e8c70ecac6ea9c78fb4ed92dcf7aa8598fea600dea3d13a117beef8287d5b709a8547d2318
|
@@ -19,6 +19,12 @@ module RicherText
|
|
19
19
|
RicherText.default_renderer.visit(document)
|
20
20
|
end
|
21
21
|
|
22
|
+
def mentionees
|
23
|
+
gids = mention_nodes.map(&:id).compact_blank
|
24
|
+
|
25
|
+
GlobalID::Locator.locate_many(gids).uniq # Only return unique records
|
26
|
+
end
|
27
|
+
|
22
28
|
private
|
23
29
|
|
24
30
|
def update_attachments
|
@@ -30,6 +36,10 @@ module RicherText
|
|
30
36
|
find_nodes_of_type(RicherText::Nodes::Image).flatten.compact_blank
|
31
37
|
end
|
32
38
|
|
39
|
+
def mention_nodes
|
40
|
+
find_nodes_of_type(RicherText::Nodes::Mention).flatten.compact_blank
|
41
|
+
end
|
42
|
+
|
33
43
|
def rhino_attachment_nodes
|
34
44
|
find_nodes_of_type(RicherText::Nodes::AttachmentFigure).flatten.compact_blank
|
35
45
|
end
|
data/lib/richer_text/content.rb
CHANGED
@@ -28,6 +28,12 @@ module RicherText
|
|
28
28
|
end.uniq
|
29
29
|
end
|
30
30
|
|
31
|
+
def mentionees_global_ids
|
32
|
+
global_ids = fragment.find_all("span[data-type=mention]").map do |span|
|
33
|
+
span.attributes["data-id"].value
|
34
|
+
end.uniq
|
35
|
+
end
|
36
|
+
|
31
37
|
def image_blobs
|
32
38
|
image_blob_ids.map { |id| ActiveStorage::Blob.find_signed(id) }
|
33
39
|
end
|
@@ -42,6 +42,17 @@ module RicherText
|
|
42
42
|
"<div class='richer-text'>#{visit_children(node).join("\n")}</div>".html_safe
|
43
43
|
end
|
44
44
|
|
45
|
+
def visit_mention(node, marks)
|
46
|
+
if marks.any?
|
47
|
+
content_tag(marks[0].tag, visit_mention(node, marks[1..]), marks[0].attrs)
|
48
|
+
else
|
49
|
+
tag.span(
|
50
|
+
tag.img(src: node.avatar_url, class: "richer-text--mention-img") +
|
51
|
+
tag.span(node.name, class: "richer-text--mention-label"),
|
52
|
+
class: "richer-text--mention")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
45
56
|
def visit_paragraph(node)
|
46
57
|
"<p style='#{node.style}'>#{visit_children(node).join}</p>"
|
47
58
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RicherText
|
2
|
+
module Nodes
|
3
|
+
class Mention < ::RicherText::Node
|
4
|
+
def initialize(json)
|
5
|
+
@marks = json.fetch("marks", []).map { |mark| RicherText::Mark.new(mark) }
|
6
|
+
super(json)
|
7
|
+
end
|
8
|
+
|
9
|
+
def accept(visitor)
|
10
|
+
visitor.visit_mention(self, @marks)
|
11
|
+
end
|
12
|
+
|
13
|
+
def user
|
14
|
+
@user ||= GlobalID::Locator.locate(@attrs["id"])
|
15
|
+
end
|
16
|
+
|
17
|
+
def id
|
18
|
+
@attrs["id"]
|
19
|
+
end
|
20
|
+
|
21
|
+
def name
|
22
|
+
@user.respond_to?(:name) ? @user.name : @attrs["label"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def avatar_url
|
26
|
+
@user.respond_to?(:avatar_url) ? @user.avatar_url : @attrs["avatarUrl"]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
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.9.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-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/richer_text/nodes/horizontal_rule.rb
|
72
72
|
- lib/richer_text/nodes/image.rb
|
73
73
|
- lib/richer_text/nodes/list_item.rb
|
74
|
+
- lib/richer_text/nodes/mention.rb
|
74
75
|
- lib/richer_text/nodes/ordered_list.rb
|
75
76
|
- lib/richer_text/nodes/paragraph.rb
|
76
77
|
- lib/richer_text/nodes/table.rb
|