tiptap-ruby 0.1.0 → 0.2.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 +4 -4
- data/lib/tip_tap/document.rb +12 -0
- data/lib/tip_tap/nodes/blockquote.rb +19 -0
- data/lib/tip_tap/nodes/codeblock.rb +16 -0
- data/lib/tip_tap/nodes/text.rb +23 -0
- data/lib/tip_tap/version.rb +1 -1
- data/lib/tip_tap.rb +2 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b25282777f07a60a51ad6298ef3d560ea67d23a947fcbfa999f953e424f6aae1
|
4
|
+
data.tar.gz: 83fcce564417e31608ea8315416b30b00f88e9882d868e36a1ee8f078bb2f192
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8715f566110cd3eef48d2419c6e7b1dc8ff8e82969644261ca66c98cbef3499944432ecd2cd0b083eeabad07f4128028e774c816b006dff264d749acfc725a83
|
7
|
+
data.tar.gz: 32ce38b1974c195034589724405594d313eb132c82558664a407d544471ba4793081dbeb2dad7fb0ea04fa3bf1a7a36d6d69f47d7d59153362a66ea1e7740a89
|
data/lib/tip_tap/document.rb
CHANGED
@@ -43,5 +43,17 @@ module TipTap
|
|
43
43
|
def image(src:)
|
44
44
|
add_content(Nodes::Image.new(src: src))
|
45
45
|
end
|
46
|
+
|
47
|
+
def blockquote(&block)
|
48
|
+
raise ArgumentError, "Block required" if block.nil?
|
49
|
+
|
50
|
+
add_content(Nodes::Blockquote.new(&block))
|
51
|
+
end
|
52
|
+
|
53
|
+
def codeblock(&block)
|
54
|
+
raise ArgumentError, "Block required" if block.nil?
|
55
|
+
|
56
|
+
add_content(Nodes::Codeblock.new(&block))
|
57
|
+
end
|
46
58
|
end
|
47
59
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tip_tap/node"
|
4
|
+
|
5
|
+
module TipTap
|
6
|
+
module Nodes
|
7
|
+
class Blockquote < Node
|
8
|
+
self.type_name = "blockquote"
|
9
|
+
self.html_tag = :blockquote
|
10
|
+
self.html_class_name = "blockquote"
|
11
|
+
|
12
|
+
def paragraph(&block)
|
13
|
+
raise ArgumentError, "Block required" if block.nil?
|
14
|
+
|
15
|
+
add_content(Paragraph.new(&block))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "tip_tap/node"
|
4
|
+
|
5
|
+
module TipTap
|
6
|
+
module Nodes
|
7
|
+
class Codeblock < Node
|
8
|
+
self.type_name = "codeBlock"
|
9
|
+
self.html_tag = :pre
|
10
|
+
|
11
|
+
def code(text)
|
12
|
+
add_content(Text.new(text, marks: [{type: "code"}]))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/tip_tap/nodes/text.rb
CHANGED
@@ -30,10 +30,13 @@ module TipTap
|
|
30
30
|
|
31
31
|
def to_html
|
32
32
|
value = text
|
33
|
+
value = content_tag(:code, value) if code?
|
33
34
|
value = content_tag(:u, value) if underline?
|
34
35
|
value = content_tag(:em, value) if italic?
|
35
36
|
value = content_tag(:strong, value) if bold?
|
37
|
+
value = content_tag(:s, value) if strike?
|
36
38
|
value = content_tag(:a, value, href: link_href, target: link_target) if link?
|
39
|
+
value = content_tag(:span, value, style: inline_style_content(text_styles)) if text_style?
|
37
40
|
value
|
38
41
|
end
|
39
42
|
|
@@ -57,6 +60,18 @@ module TipTap
|
|
57
60
|
has_mark_with_type?("link")
|
58
61
|
end
|
59
62
|
|
63
|
+
def strike?
|
64
|
+
has_mark_with_type?("strike")
|
65
|
+
end
|
66
|
+
|
67
|
+
def code?
|
68
|
+
has_mark_with_type?("code")
|
69
|
+
end
|
70
|
+
|
71
|
+
def text_style?
|
72
|
+
has_mark_with_type?("textStyle")
|
73
|
+
end
|
74
|
+
|
60
75
|
def link_href
|
61
76
|
marks.find { |mark| mark["type"] == "link" }&.dig("attrs", "href")
|
62
77
|
end
|
@@ -65,11 +80,19 @@ module TipTap
|
|
65
80
|
marks.find { |mark| mark["type"] == "link" }&.dig("attrs", "target")
|
66
81
|
end
|
67
82
|
|
83
|
+
def text_styles
|
84
|
+
marks.find { |mark| mark["type"] == "textStyle" }&.dig("attrs")
|
85
|
+
end
|
86
|
+
|
68
87
|
private
|
69
88
|
|
70
89
|
def has_mark_with_type?(type)
|
71
90
|
marks.any? { |mark| mark["type"] == type }
|
72
91
|
end
|
92
|
+
|
93
|
+
def inline_style_content(styles)
|
94
|
+
styles.reduce("") { |acc, val| acc + "#{val[0]}:#{val[1]};" }
|
95
|
+
end
|
73
96
|
end
|
74
97
|
end
|
75
98
|
end
|
data/lib/tip_tap/version.rb
CHANGED
data/lib/tip_tap.rb
CHANGED
@@ -14,6 +14,8 @@ require "tip_tap/nodes/task_item"
|
|
14
14
|
require "tip_tap/nodes/task_list"
|
15
15
|
require "tip_tap/nodes/text"
|
16
16
|
require "tip_tap/nodes/image"
|
17
|
+
require "tip_tap/nodes/blockquote"
|
18
|
+
require "tip_tap/nodes/codeblock"
|
17
19
|
|
18
20
|
module TipTap
|
19
21
|
class Error < StandardError; end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiptap-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Wilken
|
@@ -55,7 +55,9 @@ files:
|
|
55
55
|
- lib/tip_tap/html_renderable.rb
|
56
56
|
- lib/tip_tap/json_renderable.rb
|
57
57
|
- lib/tip_tap/node.rb
|
58
|
+
- lib/tip_tap/nodes/blockquote.rb
|
58
59
|
- lib/tip_tap/nodes/bullet_list.rb
|
60
|
+
- lib/tip_tap/nodes/codeblock.rb
|
59
61
|
- lib/tip_tap/nodes/hard_break.rb
|
60
62
|
- lib/tip_tap/nodes/heading.rb
|
61
63
|
- lib/tip_tap/nodes/horizontal_rule.rb
|