richer_text 0.15.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: d703c776c9c1eea2bddf68c2684bf642a5e788e24e67c2da86ab174a36375fd4
4
- data.tar.gz: 356b5961abe5334a0f1acfad1ed436e15021c9883bec94076a2658a46c8a7e14
3
+ metadata.gz: 8a947d5f1461be04bb30aeee9b343ec6e033d7ff3e88b508c1462bf6d52aba31
4
+ data.tar.gz: 2a9147231b5d14578330bdec5c4dd44abb5dd47f04e1af29980e996b2ba2430b
5
5
  SHA512:
6
- metadata.gz: 3229812766e24565f0cfd8f384f5bf1e62b5bfa4f4d6ff1e912223d475b67556bf54c6b6fb731cb1cbc7778a7c0bae5f86a54df8316d67bd0169e8ef8e1bb545
7
- data.tar.gz: 7aa2fa96a14b331270ed16ded0c5edf3b540d728664eb7465faeb2a694c52ff2dbdad0b1cf34d9ef21155d40e0b169be804a0887e893387d04758ab3ed48286f
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
 
@@ -27,10 +27,10 @@ module RicherText
27
27
  if destination.join("package.json").exist?
28
28
  say "Adding dependencies to package.json", :green
29
29
 
30
- run "npm install highlight.js @afomera/richer-text@beta" if destination.join("package-lock.json").exist?
31
- run "bun add highlight.js @afomera/richer-text@beta" if destination.join("bun.lockb").exist?
32
- run "yarn add highlight.js @afomera/richer-text@beta" if destination.join("yarn.lock").exist?
33
- run "pnpm add highlight.js @afomera/richer-text@beta" if destination.join("pnpm-lock.yaml").exist?
30
+ run "npm install highlight.js @afomera/richer-text" if destination.join("package-lock.json").exist?
31
+ run "bun add highlight.js @afomera/richer-text" if destination.join("bun.lockb").exist?
32
+ run "yarn add highlight.js @afomera/richer-text" if destination.join("yarn.lock").exist?
33
+ run "pnpm add highlight.js @afomera/richer-text" if destination.join("pnpm-lock.yaml").exist?
34
34
  end
35
35
 
36
36
  say "Adding import to application.js", :green
@@ -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.15.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.15.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-07 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