Class: Dato::Span
Instance Attribute Summary
Attributes inherited from Node
#node, #parent, #root
Instance Method Summary
collapse
Methods inherited from DastNode
#generated_tag
Methods inherited from Node
#blocks, #debug_node, #find_ancestor, #links, #node_type, #overrides, #parent_type, #render_node
Constructor Details
#initialize(node, root = nil, parent = nil) ⇒ Span
Returns a new instance of Span.
4
5
6
|
# File 'app/components/dato/span.rb', line 4
def initialize(node, root = nil, parent = nil)
super(node, "span", root, parent)
end
|
Instance Method Details
#code_span? ⇒ Boolean
38
39
40
|
# File 'app/components/dato/span.rb', line 38
def code_span?
@node.marks.present? && @node.marks.include?("code")
end
|
#conditional_tag(name, condition, options = nil, &block) ⇒ Object
42
43
44
45
46
47
48
|
# File 'app/components/dato/span.rb', line 42
def conditional_tag(name, condition, options = nil, &block)
if condition
content_tag name, capture(&block), options
else
capture(&block)
end
end
|
#styles ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'app/components/dato/span.rb', line 16
def styles
return unless @node.marks.present?
mapping = {
emphasis: "font-style: italic",
strong: "font-weight: bold",
highlight: "background-color: var(--dato-highlight-color, yellow)"
}.with_indifferent_access
text_decoration_mappings = {
underline: "underline",
strikethrough: "line-through"
}.with_indifferent_access
styles = @node.marks.map { |m| mapping[m] }.compact
text_decorations = @node.marks.map { |m| text_decoration_mappings[m] }.compact
if text_decorations.any?
styles << "text-decoration: #{text_decorations.join(" ")}"
end
styles.join("; ")
end
|
#wrap_styles(&block) ⇒ Object
8
9
10
11
12
13
14
|
# File 'app/components/dato/span.rb', line 8
def wrap_styles(&block)
wrapping_symbols = ""
wrapping_symbols += "**" if @node.marks&.include?("strong")
wrapping_symbols += "`" if @node.marks&.include?("code")
wrapping_symbols += "_" if @node.marks&.include?("emphasis")
"#{wrapping_symbols}#{capture(&block)}#{wrapping_symbols.reverse}"
end
|