class BBS::Renderer
Renders the ERB screens of a flow: <name>.erb files in a screens directory, evaluated in a Renderer::Context that offers colour and banner helpers.
Public Class Methods
# File lib/bbs/renderer.rb, line 22 def self.render(name, vars = {}, dir: BBS.config.screens_dir) raise 'No screens_dir: set BBS.config.screens_dir or the flow\'s screens_dir' unless dir path = File.join(dir, "#{name}.erb") ctx = Context.new(vars) ERB.new(File.read(path), trim_mode: '-').result(ctx.ctx_binding).gsub("\n", Ansi::CRLF) end
Reads <name>.erb from dir, evaluates it with vars as instance variables ({ user: 'x' } becomes +@user+) and returns the result with every LF turned into CRLF. ERB trim mode '-' is on.
- name
-
the screen name, without the
.erbextension - vars
-
Hash of values the template sees as instance variables
- dir
-
the screens directory; default
BBS.config.screens_dir
Raises RuntimeError when dir is nil, and Errno::ENOENT when the file does not exist.