richer_text 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b163192b82f3d7dd12dc87947662ec0d48ac222d725c69a08c937b235b712ee6
4
- data.tar.gz: f70ee93612cb1b8c1604e76801fcd621ac50afa337a10b957fb99004dbb71cd8
3
+ metadata.gz: 8a947d5f1461be04bb30aeee9b343ec6e033d7ff3e88b508c1462bf6d52aba31
4
+ data.tar.gz: 2a9147231b5d14578330bdec5c4dd44abb5dd47f04e1af29980e996b2ba2430b
5
5
  SHA512:
6
- metadata.gz: 90ba2c059d81782a76bf12e24b905f0a95736496176349555a7f2b8fe9808e231518163b64fee3d341c66768a56f3a1994e8ebf7c29ecb3328caaf8a28f06ae3
7
- data.tar.gz: 31f544b425897ab96918320afe4b4e59eb852c9f7430ec2712794063a7573cdc25c2115a25493960f8836da31924ae1c68b13d6b9a125d3d92c9eeeb5c536a80
6
+ metadata.gz: 49f192fc0f347e0e378f1763af8524acdd9cd6cd225a96aa8eed8343ee13c165d7e87f98c4c8b3c6dc650d4eee683e6f9fb8e482d416176bbb8c45f1b85d5710
7
+ data.tar.gz: 526353531c7358164814011501f473622102e75f168150edf0f6cdf223256632a6335148231bcc3ce442fe0651fe13658b33c095797a5a0abee72501c9340d78
data/README.md CHANGED
@@ -39,9 +39,6 @@ document.addEventListener("turbo:load", (event) => {
39
39
 
40
40
  ## Usage
41
41
 
42
- > [!WARNING]
43
- > You probably shouldn't use this gem / npm package (yet!) for anything serious. It's still undergoing development. But please do try it on a non-production app!
44
-
45
42
  To use RicherText, once you've completed the installation process is a matter of doing the following:
46
43
 
47
44
  **Add has_richer_text to a model**
@@ -19,6 +19,10 @@ module RicherText
19
19
  RicherText.default_renderer.visit(document)
20
20
  end
21
21
 
22
+ def to_plain_text
23
+ RicherText.default_text_renderer.visit(document)
24
+ end
25
+
22
26
  def mentionees
23
27
  gids = mention_nodes.map(&:id).compact_blank
24
28
 
@@ -0,0 +1,93 @@
1
+ module RicherText
2
+ class TextVisitor
3
+ def visit(node)
4
+ node.accept(self)
5
+ end
6
+
7
+ def visit_attachment_figure(node)
8
+ visit_children(node)
9
+ end
10
+
11
+ def visit_attachment_gallery(node)
12
+ visit_children(node)
13
+ end
14
+
15
+ def visit_blockquote(node)
16
+ visit_children(node)
17
+ end
18
+
19
+ def visit_bullet_list(node)
20
+ visit_children(node)
21
+ end
22
+
23
+ def visit_callout(node)
24
+ visit_children(node)
25
+ end
26
+
27
+ def visit_children(node)
28
+ node.children.map { |child| visit(child) }.join(" ")
29
+ end
30
+
31
+ def visit_code_block(node)
32
+ end
33
+
34
+ def visit_doc(node)
35
+ visit_children(node)
36
+ end
37
+
38
+ def visit_iframely_embed(node)
39
+ end
40
+
41
+ def visit_mention(node, _marks)
42
+ node.name
43
+ end
44
+
45
+ def visit_paragraph(node)
46
+ visit_children(node)
47
+ end
48
+
49
+ def visit_richer_text_embed(node)
50
+ end
51
+
52
+ def visit_list_item(node)
53
+ visit_children(node)
54
+ end
55
+
56
+ def visit_ordered_list(node)
57
+ visit_children(node)
58
+ end
59
+
60
+ def visit_heading(node)
61
+ visit_children(node)
62
+ end
63
+
64
+ def visit_hard_break(_node)
65
+ end
66
+
67
+ def visit_horizontal_rule(_node)
68
+ end
69
+
70
+ def visit_image(_node)
71
+ end
72
+
73
+ def visit_text(node, _marks)
74
+ node.text
75
+ end
76
+
77
+ def visit_table(node)
78
+ visit_children(node)
79
+ end
80
+
81
+ def visit_table_row(node)
82
+ visit_children(node)
83
+ end
84
+
85
+ def visit_table_cell(node)
86
+ visit_children(node)
87
+ end
88
+
89
+ def visit_table_header(node)
90
+ visit_children(node)
91
+ end
92
+ end
93
+ end
@@ -1,3 +1,3 @@
1
1
  module RicherText
2
- VERSION = "0.16.0"
2
+ VERSION = "0.17.0"
3
3
  end
data/lib/richer_text.rb CHANGED
@@ -20,6 +20,7 @@ module RicherText
20
20
  autoload :Node
21
21
  autoload :Mark
22
22
  autoload :HTMLVisitor
23
+ autoload :TextVisitor
23
24
 
24
25
  module Nodes
25
26
  extend ActiveSupport::Autoload
@@ -53,10 +54,14 @@ module RicherText
53
54
  @default_renderer ||= RicherText::HTMLVisitor.new
54
55
  end
55
56
 
57
+ def default_text_renderer
58
+ @default_text_renderer ||= RicherText::TextVisitor.new
59
+ end
60
+
56
61
  def default_form_options
57
62
  @default_form_options ||= {}
58
63
  end
59
64
 
60
- attr_writer :default_renderer, :default_form_options
65
+ attr_writer :default_renderer, :default_text_renderer, :default_form_options
61
66
  end
62
67
  end
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.16.0
4
+ version: 0.17.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: 2024-06-28 00:00:00.000000000 Z
11
+ date: 2024-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -104,6 +104,7 @@ files:
104
104
  - lib/richer_text/rendering.rb
105
105
  - lib/richer_text/serialization.rb
106
106
  - lib/richer_text/tag_helper.rb
107
+ - lib/richer_text/text_visitor.rb
107
108
  - lib/richer_text/version.rb
108
109
  - lib/tasks/richer_text_tasks.rake
109
110
  homepage: https://github.com/afomera/richer_text