class HighLine::Statement
@see HighLine#render_statement
when necessary. It’s used by {HighLine#render_statement}
pagination, indentation and color rendering
on a HighLine context, applying wrapping,
This class handles proper formatting based
def self.const_missing(constant)
def self.const_missing(constant) HighLine.const_get(constant) end
def format_statement
def format_statement return template_string if template_string.empty? statement = render_template statement = HighLine::Wrapper.wrap(statement, highline.wrap_at) statement = HighLine::Paginator.new(highline).page_print(statement) statement = statement.gsub(/\n(?!$)/, "\n#{highline.indentation}") if highline.multi_indent statement end
def initialize(source, highline)
-
highline
(HighLine
) -- context -
source
(#to_s
) --
def initialize(source, highline) @highline = highline @source = source @template_string = stringfy(source) end
def render_template
def render_template # Assigning to a local var so it may be # used inside instance eval block template_renderer = TemplateRenderer.new(template, source, highline) template_renderer.render end
def statement
-
(String)
- formated statement
def statement @statement ||= format_statement end
def stringfy(template_string)
def stringfy(template_string) String(template_string || "").dup end
def template
def template @template ||= if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ ERB.new(template_string, trim_mode: "%") else ERB.new(template_string, nil, "%") end end
def to_s
(see #statement)
def to_s statement end