tiptap-ruby 0.3.0 → 0.5.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: 252bf239b4d5d2f754d1b57c21e5055206557f6f4288cb8e53b97d43d3a44a68
4
- data.tar.gz: b4973d5e59abbd29c5d5203c73c6dd76cdde57b7871cb72f32543a0aba512e1c
3
+ metadata.gz: 234920a15c4fa07aec094cdfc999631c005cbef531c13eb69ec706bca5ac866f
4
+ data.tar.gz: 2cdbb32cc437b0490027e94335ce7e57f7f1cd89184642a08590bc3e82e7e6d3
5
5
  SHA512:
6
- metadata.gz: ad79a5564011be35e9cf2d8eaec3c1ff2ed7e1eac790dbe1a5218034b126041e16a6dc8eda9148e3f922a6855bab52d3fd5e1e11e2733890cc448a128208e2d6
7
- data.tar.gz: a22012af8ba3daabc39f862d0269350e22978d2cf16c1f806f1ad1c3c7ae480fabaf4ebb198c6b70a64aa82e49732c385ea2851343321ecf452e97f032c33e2f
6
+ metadata.gz: 5999cd5ccc9e0772ebbb4c7e5df486499671ae4f34c881a9259bcf0d309a42ccb640ec63f83f901ced8c26909c0ef88c51fb72d1a5ac2cd8184c357b0fbd4e31
7
+ data.tar.gz: 60b0011c676856731fc1809c6fd8380282b0175ef235fa4a6edaf946275638dd0a9a4b21a307d267d3caf6cf5a1b11e919ccf458262f04f9218e78a9ff9dda4d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.0] - 2023-10-30
4
+
5
+ - Make `Text` a subclass of `Node`.
6
+ - Try to unify the interface a bit more for the initialize method.
7
+
8
+ ## [0.4.0] - 2023-10-29
9
+
10
+ - Extract `Registerable` module from `JsonRenderable` so that Node registration is separated from being JSON renderable.
11
+ - Make `Document` a subclass of `Node`.
12
+
3
13
  ## [0.3.0] - 2023-10-29
4
14
 
5
15
  - Tweak dependency version requirements to be greater than or equal to
data/README.md CHANGED
@@ -72,6 +72,51 @@ Rendering to plain text is useful if you want to search the contents of your Tip
72
72
  document.to_plain_text # => My Important Document
73
73
  ```
74
74
 
75
+ ### Custom Nodes
76
+
77
+ You can extend the library to add custom node types. First, define your `Node` subclass.
78
+
79
+ ```ruby
80
+ # lib/tip_tap/nodes/gallery.rb
81
+
82
+ module TipTap
83
+ module Nodes
84
+ class Gallery < Node
85
+ self.type_name = 'gallery'
86
+ self.html_tag = :div
87
+ self.html_class_name = 'gallery'
88
+ end
89
+ end
90
+ end
91
+ ```
92
+
93
+ Then create an initializer and define an extensions module and include it in the corresponding node. For example:
94
+
95
+ ```ruby
96
+ # config/initializers/tiptap.rb
97
+
98
+ require 'tip_tap'
99
+ require 'tip_tap/nodes/gallery'
100
+
101
+ module TipTap::DocumentAdditions
102
+ def gallery(&block)
103
+ raise ArgumentError, "Block required" if block.nil?
104
+ add_content(TipTap::Nodes::Gallery.new(&block))
105
+ end
106
+ end
107
+
108
+ TipTap::Document.include(TipTap::DocumentAdditions)
109
+ ```
110
+
111
+ Now you can generate gallery nodes on a `Document` instance:
112
+
113
+ ```ruby
114
+ document = TipTap::Document.new
115
+ document.gallery do |gallery|
116
+ gallery.gallery_item(src: 'example.com')
117
+ end
118
+ ```
119
+
75
120
  ## Development
76
121
 
77
122
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -1,19 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "tip_tap/html_renderable"
4
- require "tip_tap/json_renderable"
5
- require "tip_tap/plain_text_renderable"
6
- require "tip_tap/has_content"
3
+ require "tip_tap/node"
7
4
 
8
5
  # This is the class that all child nodes will be added to.
9
6
  # This is the root object for TipTap.
10
7
  module TipTap
11
- class Document
12
- include JsonRenderable
13
- include HtmlRenderable
14
- include PlainTextRenderable
15
- include HasContent
16
-
8
+ class Document < Node
17
9
  self.type_name = "doc"
18
10
  self.html_tag = :div
19
11
  self.html_class_name = "tiptap-document"
@@ -4,25 +4,6 @@ require "tip_tap/registry"
4
4
 
5
5
  module TipTap
6
6
  module JsonRenderable
7
- def self.included(base)
8
- base.extend(ClassMethods)
9
- end
10
-
11
- module ClassMethods
12
- def type_name=(type_name)
13
- @type_name = type_name
14
- Registry.register(type_name, self)
15
- end
16
-
17
- def type_name
18
- @type_name
19
- end
20
- end
21
-
22
- def type_name
23
- self.class.type_name
24
- end
25
-
26
7
  def include_empty_content_in_json?
27
8
  true
28
9
  end
data/lib/tip_tap/node.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "tip_tap/registerable"
3
4
  require "tip_tap/html_renderable"
4
5
  require "tip_tap/json_renderable"
5
6
  require "tip_tap/plain_text_renderable"
@@ -10,6 +11,7 @@ require "tip_tap/has_content"
10
11
  # converting to HTML, JSON, and plain text
11
12
  module TipTap
12
13
  class Node
14
+ include Registerable
13
15
  include HtmlRenderable
14
16
  include JsonRenderable
15
17
  include PlainTextRenderable
@@ -1,21 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "tip_tap/json_renderable"
4
- require "tip_tap/html_renderable"
3
+ require "tip_tap/node"
5
4
 
6
5
  module TipTap
7
6
  module Nodes
8
- class Text
9
- include JsonRenderable
10
- include HtmlRenderable
11
-
7
+ class Text < Node
12
8
  attr_reader :text, :marks
13
9
 
14
10
  self.type_name = "text"
15
11
 
16
- def initialize(text, marks: [])
17
- @text = text
18
- @marks = marks.map(&:deep_stringify_keys)
12
+ def initialize(content, **attributes)
13
+ @text = content
14
+ @marks = Array(attributes[:marks]).map(&:deep_stringify_keys)
15
+ yield self if block_given?
19
16
  end
20
17
 
21
18
  def self.from_json(json)
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tip_tap/registry"
4
+
5
+ module TipTap
6
+ module Registerable
7
+ def self.included(base)
8
+ base.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+ def type_name=(type_name)
13
+ @type_name = type_name
14
+ Registry.register(type_name, self)
15
+ end
16
+
17
+ def type_name
18
+ @type_name
19
+ end
20
+ end
21
+
22
+ def type_name
23
+ self.class.type_name
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TipTap
4
- VERSION = "0.3.0"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiptap-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Wilken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-29 00:00:00.000000000 Z
11
+ date: 2023-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -69,6 +69,7 @@ files:
69
69
  - lib/tip_tap/nodes/task_list.rb
70
70
  - lib/tip_tap/nodes/text.rb
71
71
  - lib/tip_tap/plain_text_renderable.rb
72
+ - lib/tip_tap/registerable.rb
72
73
  - lib/tip_tap/registry.rb
73
74
  - lib/tip_tap/version.rb
74
75
  - lib/tiptap.rb