tiptap-ruby 0.7.0 → 0.8.1

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: 4c3416b54084b6d2eee7cb1fa23e935d7fa495578a2dbfac7cb028f91c3bd62e
4
- data.tar.gz: 9e62d38585790d5efaaed7506f532c20fc6351644f71b370ba32d95638772ed5
3
+ metadata.gz: 6d5aa320891bbc36f97d9a0bcbaf59269285566e8820fcf8078a522c0b2a6d78
4
+ data.tar.gz: 410768b9c65ccd48712d53ca3cad4076897387c9f4f32c5a003e09a7cd32ab2c
5
5
  SHA512:
6
- metadata.gz: 9b8c3a916a053f93f21b0735285bf99c8840b0a5ffed9769cc91ce217fa3bbf4c3e3a9f5a247f8c1c02b5f2f47ff635999d33d6ba3aa9587b7bc5917d8245776
7
- data.tar.gz: 10e9ae09b3b816041d63d4c8a7feda62f804757608ca49a897955b3acc240911e66d694df86b310bb0874f369bcf84b0466b763c721d8cf932fd8cc42f325397
6
+ metadata.gz: dd2d14f97e03dbede36823313a78b16d2f6824abf7da54327410e9ed2995ffdae607eaa35152242278354325d7b217cbf2d2c4299379f63bbebd5ee2c4b5693f
7
+ data.tar.gz: e8ece329004dc1c77aecaf8a57e325efc849e30f47fd75e63a284c5002bcddc5c7036db785f96f49571ccb460054c8a3d500502c5d768f675c2748fc45c2d75a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.8.0] - 2023-11-02
4
+
5
+ ### Breaking
6
+
7
+ - Renamed `as_json` to `to_h` details outlined in https://github.com/chadwilken/tiptap-ruby/issues/10.
8
+
3
9
  ## [0.7.0] - 2023-11-02
4
10
 
5
11
  ### Breaking
data/README.md CHANGED
@@ -59,7 +59,7 @@ Once you have a Document with some content you can render it to HTML, JSON, and
59
59
  #### JSON
60
60
 
61
61
  ```ruby
62
- document.as_json # => { type: 'doc', content: […nodes]}
62
+ document.to_h # => { type: 'doc', content: […nodes]}
63
63
  ```
64
64
 
65
65
  ### HTML
@@ -9,13 +9,12 @@ module TipTap
9
9
  end
10
10
 
11
11
  # Generate a JSON object that is useable by the editor
12
- def as_json
12
+ def to_h
13
13
  json = {type: type_name}
14
- json = json.merge(content: content.map(&:as_json)) if should_include_content?
14
+ json = json.merge(content: content.map(&:to_h)) if should_include_content?
15
15
  json = json.merge(attrs: attrs.deep_symbolize_keys) if attrs.present?
16
16
  json
17
17
  end
18
- alias_method :to_h, :as_json
19
18
 
20
19
  private
21
20
 
data/lib/tip_tap/node.rb CHANGED
@@ -12,9 +12,9 @@ require "tip_tap/has_content"
12
12
  module TipTap
13
13
  class Node
14
14
  include Registerable
15
+ include HasContent
15
16
  include HtmlRenderable
16
17
  include JsonRenderable
17
18
  include PlainTextRenderable
18
- include HasContent
19
19
  end
20
20
  end
@@ -21,12 +21,15 @@ module TipTap
21
21
  new(json["text"], marks: Array(json["marks"]))
22
22
  end
23
23
 
24
- def as_json
24
+ def to_h
25
25
  {type: type_name, text: text, marks: marks.map(&:deep_symbolize_keys)}.compact_blank
26
26
  end
27
27
 
28
28
  def to_html
29
29
  value = text
30
+ value = content_tag(:sup, value) if superscript?
31
+ value = content_tag(:sub, value) if subscript?
32
+ value = highlight_tag(value) if highlight?
30
33
  value = content_tag(:code, value) if code?
31
34
  value = content_tag(:u, value) if underline?
32
35
  value = content_tag(:em, value) if italic?
@@ -65,10 +68,28 @@ module TipTap
65
68
  has_mark_with_type?("code")
66
69
  end
67
70
 
71
+ def superscript?
72
+ has_mark_with_type?("superscript")
73
+ end
74
+
75
+ def subscript?
76
+ has_mark_with_type?("subscript")
77
+ end
78
+
79
+ def highlight?
80
+ has_mark_with_type?("highlight")
81
+ end
82
+
68
83
  def text_style?
69
84
  has_mark_with_type?("textStyle")
70
85
  end
71
86
 
87
+ private
88
+
89
+ def has_mark_with_type?(type)
90
+ marks.any? { |mark| mark["type"] == type }
91
+ end
92
+
72
93
  def link_href
73
94
  marks.find { |mark| mark["type"] == "link" }&.dig("attrs", "href")
74
95
  end
@@ -81,15 +102,25 @@ module TipTap
81
102
  marks.find { |mark| mark["type"] == "textStyle" }&.dig("attrs")
82
103
  end
83
104
 
84
- private
85
-
86
- def has_mark_with_type?(type)
87
- marks.any? { |mark| mark["type"] == type }
105
+ def highlight_color
106
+ marks.find { |mark| mark["type"] == "highlight" }&.dig("attrs", "color")
88
107
  end
89
108
 
90
109
  def inline_style_content(styles)
110
+ return nil if styles.empty?
91
111
  styles.reduce("") { |acc, val| acc + "#{val[0]}:#{val[1]};" }
92
112
  end
113
+
114
+ def highlight_tag(value)
115
+ data = {}
116
+ styles = {}
117
+ if highlight_color
118
+ data[:color] = highlight_color
119
+ styles["background-color"] = highlight_color
120
+ styles[:color] = "inherit"
121
+ end
122
+ content_tag(:mark, text, data: data, style: inline_style_content(styles))
123
+ end
93
124
  end
94
125
  end
95
126
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TipTap
4
- VERSION = "0.7.0"
4
+ VERSION = "0.8.1"
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.7.0
4
+ version: 0.8.1
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-11-02 00:00:00.000000000 Z
11
+ date: 2023-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview