tiptap-ruby 0.4.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60b5aada7f1e70f5781974f227c6957baa22edda85692a1d788a43757c675f2c
4
- data.tar.gz: 39b3b083e5fb3023e912ec7b8e778f8c0223feebf20c447a7d46952df03a2ca9
3
+ metadata.gz: fd7f762d8377a8a4b86b901315b1b4d3d5bc96abd58f6b469861e84ba87b6296
4
+ data.tar.gz: cfaa3409507308edef86236e01b3d563d023546f2fa75eb0c4d7a0b476bbb7d3
5
5
  SHA512:
6
- metadata.gz: fb67a28e811555d08ef569c6827c1b7c3f1bdd97b986d52f48661007abd9163da8fc54b1631b45e310b8a5d3ff073fab8780626c7712017a2806c9294fae7cb5
7
- data.tar.gz: db4dec5f0e8004e0387e934d3bda318518e2e552cacdef30e3d547dd116f2d3b70c924e9da9eeb21e3b5897df684ac9d98224bc846a662c3a189f7c72e06298b
6
+ metadata.gz: 99ceb0b18400d9c1549e433d4c5ed488797f9599366859ebd10d17d75b64a80ffb58628786e464abddb7caea42a58d2d1a498ce901ed96d14b026dcfda85c7b1
7
+ data.tar.gz: ac01ac19fd18f06518711922821b5477fc03bc56ea98797b7e4c8e2f35d4d6f9c59c333583a6c136a66d0007f7a1241987baa9c9e657dba812c6ae1b34b97c46
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.
@@ -4,6 +4,8 @@ require "active_support/core_ext/hash"
4
4
 
5
5
  module TipTap
6
6
  module HasContent
7
+ include Enumerable
8
+
7
9
  attr_reader :attrs, :content
8
10
 
9
11
  def self.included(base)
@@ -20,13 +22,23 @@ module TipTap
20
22
  yield self if block_given?
21
23
  end
22
24
 
23
- def find_node(node_type)
24
- content.find { |child| child.is_a?(node_type) }
25
+ def each
26
+ content.each { |child| yield child }
27
+ end
28
+
29
+ def find_node(type_class_or_name)
30
+ node_type = type_class_or_name.is_a?(String) ? TipTap.node_for(type_class_or_name) : type_class_or_name
31
+ find { |child| child.is_a?(node_type) }
25
32
  end
26
33
 
27
34
  def add_content(node)
28
35
  @content << node
29
36
  end
37
+ alias_method :<<, :add_content
38
+
39
+ def size
40
+ content.size
41
+ end
30
42
 
31
43
  module ClassMethods
32
44
  # Create a new instance from a TipTap JSON object.
@@ -1,23 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "tip_tap/registerable"
4
- require "tip_tap/json_renderable"
5
- require "tip_tap/html_renderable"
3
+ require "tip_tap/node"
6
4
 
7
5
  module TipTap
8
6
  module Nodes
9
- class Text
10
- include Registerable
11
- include JsonRenderable
12
- include HtmlRenderable
13
-
7
+ class Text < Node
14
8
  attr_reader :text, :marks
15
9
 
16
10
  self.type_name = "text"
17
11
 
18
- def initialize(text, marks: [])
19
- @text = text
20
- @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?
21
16
  end
22
17
 
23
18
  def self.from_json(json)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TipTap
4
- VERSION = "0.4.0"
4
+ VERSION = "0.6.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.4.0
4
+ version: 0.6.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-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview