Class: ChatSDK::Cards::ActionsContext
- Inherits:
-
Object
- Object
- ChatSDK::Cards::ActionsContext
- Defined in:
- lib/chat_sdk/cards/actions_context.rb
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
- #button(text, id:, style: nil, value: nil) ⇒ Object
-
#initialize ⇒ ActionsContext
constructor
A new instance of ActionsContext.
- #link_button(text, url:) ⇒ Object
- #select(id:, placeholder: nil, &block) ⇒ Object
Constructor Details
#initialize ⇒ ActionsContext
Returns a new instance of ActionsContext.
8 9 10 |
# File 'lib/chat_sdk/cards/actions_context.rb', line 8 def initialize @nodes = [] end |
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
6 7 8 |
# File 'lib/chat_sdk/cards/actions_context.rb', line 6 def nodes @nodes end |
Instance Method Details
#button(text, id:, style: nil, value: nil) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/chat_sdk/cards/actions_context.rb', line 12 def (text, id:, style: nil, value: nil) attrs = {text: text, id: id} attrs[:style] = style if style attrs[:value] = value if value @nodes << Node.new(:button, attributes: attrs) end |
#link_button(text, url:) ⇒ Object
19 20 21 |
# File 'lib/chat_sdk/cards/actions_context.rb', line 19 def (text, url:) @nodes << Node.new(:link_button, attributes: {text: text, url: url}) end |
#select(id:, placeholder: nil, &block) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/chat_sdk/cards/actions_context.rb', line 23 def select(id:, placeholder: nil, &block) ctx = SelectContext.new ctx.instance_eval(&block) attrs = {id: id} attrs[:placeholder] = placeholder if placeholder @nodes << Node.new(:select, attributes: attrs, children: ctx.nodes) end |