tiptap-ruby 0.1.0 → 0.2.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: 2347235752700026d263aa5a0616d89f99014c42da52edbf92c30374eb2cfded
4
- data.tar.gz: d97eefd5023412988280b6edf6741186f310452ab657a02c62419296de680334
3
+ metadata.gz: b25282777f07a60a51ad6298ef3d560ea67d23a947fcbfa999f953e424f6aae1
4
+ data.tar.gz: 83fcce564417e31608ea8315416b30b00f88e9882d868e36a1ee8f078bb2f192
5
5
  SHA512:
6
- metadata.gz: 79f61b79665a0a0d48cc69322c50b24d05a3b330c6f2a6dd8242f31dc628d8f9e1d69db06024b7bb642290c44a001df13379fcc45872a6c0f0f3e28df0bc4a3f
7
- data.tar.gz: 4b5ab21878bccf69ccdc8dfdc3fe04bbc5e3a91a65140b6d2b1759bce3ed13a6169fb47d2697415cd5d27261fa27c11f1d40c2e0387a1f0e30cf38fc296244a0
6
+ metadata.gz: 8715f566110cd3eef48d2419c6e7b1dc8ff8e82969644261ca66c98cbef3499944432ecd2cd0b083eeabad07f4128028e774c816b006dff264d749acfc725a83
7
+ data.tar.gz: 32ce38b1974c195034589724405594d313eb132c82558664a407d544471ba4793081dbeb2dad7fb0ea04fa3bf1a7a36d6d69f47d7d59153362a66ea1e7740a89
@@ -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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TipTap
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
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.1.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