Sha256: 44802317a20c37eeb06f821c8e0b358c7a09645dbcb61ef1b50504a1a5bb0baa

Contents?: true

Size: 1.7 KB

Versions: 79

Compression:

Stored size: 1.7 KB

Contents

# coding: utf-8

require "forwardable"

class HighLine
  # Renders an erb template taking a {Question} and a {HighLine} instance
  # as context.
  class TemplateRenderer
    extend Forwardable

    def_delegators :@highline, :color, :list, :key
    def_delegators :@source, :answer_type, :prompt, :header, :answer

    # @return [ERB] ERB template being rendered
    attr_reader :template

    # @return [Question, Menu] Question instance used as context
    attr_reader :source

    # @return [HighLine] HighLine instance used as context
    attr_reader :highline

    # 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.

    def initialize(template, source, highline)
      @template = template
      @source   = source
      @highline = highline
    end

    # @return [String] rendered template
    def render
      template.result(binding)
    end

    # Returns an error message when the called method
    # is not available.
    # @return [String] error message.
    def method_missing(method, *args)
      "Method #{method} with args #{args.inspect} " \
        "is not available on #{inspect}. " \
        "Try #{methods(false).sort.inspect}"
    end

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

    # 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
    def self.const_missing(name)
      HighLine.const_get(name)
    end
  end
end

Version data entries

79 entries across 65 versions & 4 rubygems

Version Path
brakeman-5.2.3 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-5.2.2 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-5.2.1 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-5.2.0 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-5.1.2 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-5.1.1 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-5.1.0 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-5.0.4 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-5.0.2 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-5.0.1 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-5.0.0 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-4.10.1 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-5.0.0.pre1 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-4.10.0 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-4.9.1 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-4.9.0 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-4.8.2 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-4.8.1 bundle/ruby/2.4.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
brakeman-4.8.0 bundle/ruby/2.7.0/gems/highline-2.0.3/lib/highline/template_renderer.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/brakeman-4.7.2/bundle/ruby/2.6.0/gems/highline-2.0.3/lib/highline/template_renderer.rb