Sha256: 0ff822010c3c984dbbd6971ffcb64e01c0c54cf95f269167bb753600280036ff

Contents?: true

Size: 902 Bytes

Versions: 2

Compression:

Stored size: 902 Bytes

Contents

# frozen_string_literal: true

require "erb"

module Rubysmith
  module Renderers
    # Renders ERB templates as fully functional files.
    class ERB
      def initialize configuration,
                     scope: Renderers::Namespace.new(configuration.project_class),
                     client: ::ERB
        @configuration = configuration
        @scope = scope
        @client = client
      end

      def call(content) = client.new(content, trim_mode: "<>", eoutvar: "@buffer").result(binding)

      private

      attr_accessor :buffer
      attr_reader :configuration, :scope, :client

      def namespace
        source = buffer.dup

        self.buffer = source + if block_given?
                                 scope.call yield.sub(source, "")
                               else
                                 scope.call
                               end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubysmith-1.3.0 lib/rubysmith/renderers/erb.rb
rubysmith-1.2.0 lib/rubysmith/renderers/erb.rb