Class: CommandTower::Messaging::Rendering::InboxDocument::Builder

Inherits:
Object
  • Object
show all
Defined in:
app/services/command_tower/messaging/rendering/inbox_document.rb

Constant Summary collapse

UNSAFE_SCHEMES =
%w[javascript data vbscript].freeze
DEFAULT_CTA_LABEL =
"Open"

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Builder

Returns a new instance of Builder.



70
71
72
# File 'app/services/command_tower/messaging/rendering/inbox_document.rb', line 70

def initialize
  @blocks = []
end

Instance Method Details

#blocks ⇒ Object



95
96
97
# File 'app/services/command_tower/messaging/rendering/inbox_document.rb', line 95

def blocks
  @blocks
end

#cta(label, path: nil, href: nil) ⇒ Object



81
82
83
84
85
86
87
88
# File 'app/services/command_tower/messaging/rendering/inbox_document.rb', line 81

def cta(label, path: nil, href: nil)
  destination = cta_destination(path:, href:)
  return self unless destination

  resolved_label = label.is_a?(String) && !label.strip.empty? ? label : DEFAULT_CTA_LABEL
  @blocks << { type: "cta", label: resolved_label, destination: }.freeze
  self
end

#paragraph(text) ⇒ Object



74
75
76
77
78
79
# File 'app/services/command_tower/messaging/rendering/inbox_document.rb', line 74

def paragraph(text)
  return self unless text.is_a?(String) && !text.empty?

  @blocks << { type: "paragraph", text: }.freeze
  self
end

#presentation(key, variant: nil) ⇒ Object



90
91
92
93
# File 'app/services/command_tower/messaging/rendering/inbox_document.rb', line 90

def presentation(key, variant: nil)
  @blocks << { type: "presentation", key: key.to_s, variant: variant&.to_s }.freeze
  self
end