class BBS::WindowSpec
Declarative window definition used inside Application.define:
window :compose, type: :form do |w| w.title { |ctx| " Post to #{ctx[:board].title} " } w.width 70 w.field :body, type: :textarea, max_length: 1000 w.on_submit do |values, form, ctx| case ctx[:boards].post(ctx[:board].id, ctx[:username], values[:body]) when :empty then form.error('Message cannot be empty.'); :keep else :close end end end
w.maximizable true gives the window the zoom gadget (F5, Alt-Enter): it fills the screen and back. Worth it for windows with a lot to read.
Open with app.open_window(:compose, board: some_board). Block callbacks receive a ctx hash combining the app’s services, app.context, and any extras passed to open_window.
The type picks the window class: :info (BBS::Windows::Info), :form (BBS::Windows::Form), :master_detail (BBS::Windows::MasterDetail) or :stream (BBS::Windows::Stream). Each name in SCALAR_ATTRS and BLOCK_ATTRS is a setter method that takes a value or a block; a block is called with ctx (and the callback’s own arguments first, for the callbacks) when the window opens.
Constants
- BLOCK_ATTRS
-
The attributes usually given as blocks: content (
body,items,initial_lines,prefill), item rendering (item_label,render_detail,bottom_meta) and callbacks (on_submit,on_cancel,on_poll,on_activate). Each is a setter method that takes a value or a block. - CALLBACKS
-
The callbacks each type passes on, called with their own arguments and
ctxlast. - DEFAULTS
-
What a type’s window gets for an attribute that is not set.
- SCALAR_ATTRS
-
The attributes usually given as plain values, each a setter method with an
=alias; a block given instead is called withctx. - VALUES
-
The attributes each type passes to its window’s
open, resolved withctx; anilone is left out. - WINDOWS
-
The window class of each type.
Attributes
The window’s name (as used with open_window) and its type Symbol.
The window’s name (as used with open_window) and its type Symbol.
Public Class Methods
Source
# File lib/bbs/window_spec.rb, line 87 def initialize(name, type:) @name = name @type = type @attrs = {} @fields = [] @actions = [] @buttons = nil end
Creates an empty spec for the window name of type (:info, :form, :master_detail or :stream).
Public Instance Methods
Source
# File lib/bbs/window_spec.rb, line 116 def action(**opts, &block) opts = opts.merge(on_click: block) if block @actions << opts end
Adds an action button to a master/detail window. opts is a BBS::Windows::ButtonBar descriptor; the block, when given, becomes its on_click and is called with the window and ctx.
Source
# File lib/bbs/window_spec.rb, line 109 def field(key, **opts) @fields << opts.merge(key: key) end
Adds a form field stored under key. opts is a BBS::Windows::Form field descriptor (label, type, max_length, …); a Proc value is called with ctx, and a field without a value takes it from the prefill Hash.
Source
# File lib/bbs/window_spec.rb, line 135 def open(app, **extras) ctx = build_ctx(app, extras) window = WINDOWS.fetch(@type).open(app, **options(ctx)) window.maximizable = resolve(:maximizable, ctx) ? true : false if window.respond_to?(:maximizable=) window.accent = resolve(:accent, ctx) if window.respond_to?(:accent=) window end
Resolves the attributes, wraps the callbacks with the runtime ctx, then opens the underlying rubbs window on app. extras flow into ctx (e.g. board:).
Returns the opened BBS::Window.