Sha256: 2a517b09aad444be80106735227798bf6ce8339c8dbcb6ced111a6dadf091626

Contents?: true

Size: 593 Bytes

Versions: 2

Compression:

Stored size: 593 Bytes

Contents

require 'tilt'

module TurnipFormatter
  module Printer
    #
    # @example
    #   render_template(:main, { name: 'user' })
    #     # => Tilt.new('/path/to/main.erb') render { name: 'user' }
    #
    def render_template(name, params = {})
      render_template_list(name).render(self, params)
    end

    private

    def render_template_list(name)
      if templates[name].nil?
        path = File.dirname(__FILE__) + "/template/#{name}.haml"
        templates[name] = Tilt.new(path)
      end

      templates[name]
    end

    def templates
      @templates ||= {}
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
turnip_formatter-0.3.1 lib/turnip_formatter/printer.rb
turnip_formatter-0.3.0 lib/turnip_formatter/printer.rb