Class: TipTap::Nodes::Text
Instance Attribute Summary collapse
#output_buffer
Attributes included from HasContent
#attrs, #content
Class Method Summary
collapse
Instance Method Summary
collapse
#include_empty_content_in_json?
#html_class_name, #html_tag, included
Methods included from HasContent
#add_content, #blank?, #each, #find_node, included, #size
included, #type_name
Constructor Details
#initialize(content, **attributes) {|_self| ... } ⇒ Text
Returns a new instance of Text.
12
13
14
15
16
|
# File 'lib/tip_tap/nodes/text.rb', line 12
def initialize(content, **attributes)
@text = content
@marks = Array(attributes[:marks]).map(&:deep_stringify_keys)
yield self if block_given?
end
|
Instance Attribute Details
#marks ⇒ Object
Returns the value of attribute marks.
8
9
10
|
# File 'lib/tip_tap/nodes/text.rb', line 8
def marks
@marks
end
|
#text ⇒ Object
Returns the value of attribute text.
8
9
10
|
# File 'lib/tip_tap/nodes/text.rb', line 8
def text
@text
end
|
Class Method Details
.from_json(json) ⇒ Object
18
19
20
21
22
|
# File 'lib/tip_tap/nodes/text.rb', line 18
def self.from_json(json)
json.deep_stringify_keys!
new(json["text"], marks: Array(json["marks"]))
end
|
Instance Method Details
#bold? ⇒ Boolean
53
54
55
|
# File 'lib/tip_tap/nodes/text.rb', line 53
def bold?
has_mark_with_type?("bold")
end
|
#code? ⇒ Boolean
69
70
71
|
# File 'lib/tip_tap/nodes/text.rb', line 69
def code?
has_mark_with_type?("code")
end
|
#highlight? ⇒ Boolean
81
82
83
|
# File 'lib/tip_tap/nodes/text.rb', line 81
def highlight?
has_mark_with_type?("highlight")
end
|
#italic? ⇒ Boolean
49
50
51
|
# File 'lib/tip_tap/nodes/text.rb', line 49
def italic?
has_mark_with_type?("italic")
end
|
#link? ⇒ Boolean
61
62
63
|
# File 'lib/tip_tap/nodes/text.rb', line 61
def link?
has_mark_with_type?("link")
end
|
#strike? ⇒ Boolean
65
66
67
|
# File 'lib/tip_tap/nodes/text.rb', line 65
def strike?
has_mark_with_type?("strike")
end
|
#subscript? ⇒ Boolean
77
78
79
|
# File 'lib/tip_tap/nodes/text.rb', line 77
def subscript?
has_mark_with_type?("subscript")
end
|
#superscript? ⇒ Boolean
73
74
75
|
# File 'lib/tip_tap/nodes/text.rb', line 73
def superscript?
has_mark_with_type?("superscript")
end
|
#text_style? ⇒ Boolean
85
86
87
|
# File 'lib/tip_tap/nodes/text.rb', line 85
def text_style?
has_mark_with_type?("textStyle")
end
|
#to_h ⇒ Object
24
25
26
27
28
|
# File 'lib/tip_tap/nodes/text.rb', line 24
def to_h
data = {type: type_name, text: text || ""}
data[:marks] = marks.map(&:deep_symbolize_keys) unless marks.empty?
data
end
|
#to_html ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/tip_tap/nodes/text.rb', line 30
def to_html
value = text
value = content_tag(:sup, value) if superscript?
value = content_tag(:sub, value) if subscript?
value = highlight_tag(value) if highlight?
value = content_tag(:code, value) if code?
value = content_tag(:u, value) if underline?
value = content_tag(:em, value) if italic?
value = content_tag(:strong, value) if bold?
value = content_tag(:s, value) if strike?
value = content_tag(:a, value, href: link_href, target: link_target) if link?
value = content_tag(:span, value, style: inline_style_content(text_styles)) if text_style?
value
end
|
#to_plain_text(separator: " ") ⇒ Object
45
46
47
|
# File 'lib/tip_tap/nodes/text.rb', line 45
def to_plain_text(separator: " ")
text
end
|
#underline? ⇒ Boolean
57
58
59
|
# File 'lib/tip_tap/nodes/text.rb', line 57
def underline?
has_mark_with_type?("underline")
end
|