Sha256: 6638a661e5923cb247b0e3a9401f8522108f3c3757f08ee35433e8ea78c0a716

Contents?: true

Size: 888 Bytes

Versions: 11

Compression:

Stored size: 888 Bytes

Contents

# frozen_string_literal: true

require "erb"

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

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

      private

      attr_accessor :buffer
      attr_reader :settings, :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

11 entries across 11 versions & 1 rubygems

Version Path
rubysmith-8.0.0 lib/rubysmith/renderers/erb.rb
rubysmith-7.9.0 lib/rubysmith/renderers/erb.rb
rubysmith-7.8.0 lib/rubysmith/renderers/erb.rb
rubysmith-7.7.0 lib/rubysmith/renderers/erb.rb
rubysmith-7.6.0 lib/rubysmith/renderers/erb.rb
rubysmith-7.5.0 lib/rubysmith/renderers/erb.rb
rubysmith-7.4.0 lib/rubysmith/renderers/erb.rb
rubysmith-7.3.0 lib/rubysmith/renderers/erb.rb
rubysmith-7.2.0 lib/rubysmith/renderers/erb.rb
rubysmith-7.1.0 lib/rubysmith/renderers/erb.rb
rubysmith-7.0.0 lib/rubysmith/renderers/erb.rb