class HighLine::TemplateRenderer

Renders an erb template taking a {Question} and a {HighLine} instance as context.

Attributes

highline[R]

@return [HighLine] HighLine instance used as context

source[R]

@return [Question, Menu] Question instance used as context

template[R]

@return [ERB] ERB template being rendered

Public Class Methods

const_missing(name) click to toggle source

If some constant is missing at this TemplateRenderer instance, get it from HighLine. Useful to get color and style contants. @param name [Symbol] automatically passed constant’s name as Symbol

# File lib/highline/template_renderer.rb, line 58
def self.const_missing(name)
  HighLine.const_get(name)
end
new(template, source, highline) click to toggle source

Initializes the TemplateRenderer object with its template and HighLine and Question contexts.

@param template [ERB] ERB template. @param source [Question] question object. @param highline [HighLine] HighLine instance.

# File lib/highline/template_renderer.rb, line 30
def initialize(template, source, highline)
  @template = template
  @source   = source
  @highline = highline
end

Public Instance Methods

menu() click to toggle source

@return [Question, Menu] {#source} attribute.

method_missing(method, *args) click to toggle source

Returns an error message when the called method is not available. @return [String] error message.

# File lib/highline/template_renderer.rb, line 44
def method_missing(method, *args)
  "Method #{method} with args #{args.inspect} " \
    "is not available on #{inspect}. " \
    "Try #{methods(false).sort.inspect}"
end
render() click to toggle source

@return [String] rendered template

# File lib/highline/template_renderer.rb, line 37
def render
  template.result(binding)
end