Class: Inquirex::UI::DSL::StepBuilder

Inherits:
DSL::StepBuilder
  • Object
show all
Defined in:
lib/inquirex/ui/dsl/step_builder.rb

Overview

Extends Inquirex::DSL::StepBuilder with widget rendering hint methods. Used by FlowBuilder whenever a step block is evaluated inside Inquirex::UI.define.

Additional DSL methods:

widget :radio_group, columns: 2     # desktop/default hint
widget_mobile :dropdown             # mobile-specific hint

Instance Method Summary collapse

Constructor Details

#initialize(verb) ⇒ StepBuilder

Returns a new instance of StepBuilder.



13
14
15
16
# File 'lib/inquirex/ui/dsl/step_builder.rb', line 13

def initialize(verb)
  super
  @widget_hints = {}
end

Instance Method Details

#build(id) ⇒ UI::Node

Builds a UI::Node with widget hints (explicit or registry defaults).

Parameters:

  • id (Symbol)

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/inquirex/ui/dsl/step_builder.rb', line 37

def build(id)
  effective_type = resolve_type
  hints = @widget_hints.dup

  # Fill in registry defaults for any targets not explicitly set.
  %i[desktop mobile].each do |target|
    hints[target] ||= WidgetRegistry.default_hint_for(effective_type, context: target)
  end
  hints.compact!

  UI::Node.new(
    id:,
    verb:         @verb,
    type:         effective_type,
    question:     @question,
    text:         @text,
    options:      @options,
    transitions:  @transitions,
    skip_if:      @skip_if,
    default:      @default,
    widget_hints: hints.empty? ? nil : hints
  )
end

#widget(type:, target: :desktop, **opts) ⇒ Object

Sets a rendering hint for the given target context. Call once per target. Recognized targets: :desktop, :mobile (and any future targets adapters may define).

Examples:

widget target: :desktop, type: :radio_group, columns: 2
widget target: :mobile,  type: :dropdown

Parameters:

  • target (Symbol) (defaults to: :desktop)

    rendering context (default: :desktop)

  • type (Symbol)

    widget type (see WidgetRegistry::WIDGET_TYPES)

  • opts (Hash)

    widget-specific options (e.g. columns: 2)



29
30
31
# File 'lib/inquirex/ui/dsl/step_builder.rb', line 29

def widget(type:, target: :desktop, **opts)
  @widget_hints[target.to_sym] = WidgetHint.new(type:, options: opts)
end