Class: ChatSDK::Cards::Builder
- Inherits:
-
Object
- Object
- ChatSDK::Cards::Builder
- Defined in:
- lib/chat_sdk/cards/builder.rb
Instance Method Summary collapse
- #actions(&block) ⇒ Object
- #build ⇒ Object
- #divider ⇒ Object
- #fields(&block) ⇒ Object
- #image(url:, alt: nil) ⇒ Object
-
#initialize(title: nil, subtitle: nil, &block) ⇒ Builder
constructor
A new instance of Builder.
- #section(title = nil, &block) ⇒ Object
- #text(content) ⇒ Object
Constructor Details
#initialize(title: nil, subtitle: nil, &block) ⇒ Builder
Returns a new instance of Builder.
6 7 8 9 10 11 |
# File 'lib/chat_sdk/cards/builder.rb', line 6 def initialize(title: nil, subtitle: nil, &block) @title = title @subtitle = subtitle @children = [] instance_eval(&block) if block end |
Instance Method Details
#actions(&block) ⇒ Object
45 46 47 48 49 |
# File 'lib/chat_sdk/cards/builder.rb', line 45 def actions(&block) ctx = ActionsContext.new ctx.instance_eval(&block) @children << Node.new(:actions, children: ctx.nodes) end |
#build ⇒ Object
13 14 15 16 17 18 |
# File 'lib/chat_sdk/cards/builder.rb', line 13 def build attrs = {} attrs[:title] = @title if @title attrs[:subtitle] = @subtitle if @subtitle Node.new(:card, attributes: attrs, children: @children) end |
#divider ⇒ Object
24 25 26 |
# File 'lib/chat_sdk/cards/builder.rb', line 24 def divider @children << Node.new(:divider) end |
#fields(&block) ⇒ Object
32 33 34 35 36 |
# File 'lib/chat_sdk/cards/builder.rb', line 32 def fields(&block) ctx = FieldsContext.new ctx.instance_eval(&block) @children << Node.new(:fields, children: ctx.nodes) end |
#image(url:, alt: nil) ⇒ Object
28 29 30 |
# File 'lib/chat_sdk/cards/builder.rb', line 28 def image(url:, alt: nil) @children << Node.new(:image, attributes: {url: url, alt: alt}) end |
#section(title = nil, &block) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/chat_sdk/cards/builder.rb', line 38 def section(title = nil, &block) ctx = Builder.new ctx.instance_eval(&block) attrs = title ? {title: title} : {} @children << Node.new(:section, attributes: attrs, children: ctx.build.children) end |