Class: Dato::Span

Inherits:
DastNode show all
Defined in:
app/components/dato/span.rb

Instance Attribute Summary

Attributes inherited from Node

#root

Instance Method Summary collapse

Methods inherited from DastNode

#generated_tag

Methods inherited from Node

#blocks, #debug_node, #overrides, #render_node

Constructor Details

#initialize(node, root = nil) ⇒ Span

Returns a new instance of Span.



4
5
6
# File 'app/components/dato/span.rb', line 4

def initialize(node, root = nil)
  super(node, "span", root)
end

Instance Method Details

#code_span?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'app/components/dato/span.rb', line 30

def code_span?
  @node.marks.present? && @node.marks.include?("code")
end

#conditional_tag(name, condition, options = nil, &block) ⇒ Object



34
35
36
37
38
39
40
# File 'app/components/dato/span.rb', line 34

def conditional_tag(name, condition, options = nil, &block)
  if condition
     name, capture(&block), options
  else
    capture(&block)
  end
end

#stylesObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/components/dato/span.rb', line 8

def styles
  return unless @node.marks.present?

  mapping = {
    emphasis: "font-style: italic",
    strong: "font-weight: bold",
    highlight: "background-color: #FFFF00"
  }.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