Sha256: 063ef30c5a971bdb65f31f6cabadf388cba8786041d2e786bce99111b82c7073

Contents?: true

Size: 913 Bytes

Versions: 46

Compression:

Stored size: 913 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_namespaced_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

46 entries across 46 versions & 1 rubygems

Version Path
rubysmith-6.10.0 lib/rubysmith/renderers/erb.rb
rubysmith-6.9.0 lib/rubysmith/renderers/erb.rb
rubysmith-6.6.0 lib/rubysmith/renderers/erb.rb
rubysmith-6.5.0 lib/rubysmith/renderers/erb.rb
rubysmith-6.4.0 lib/rubysmith/renderers/erb.rb
rubysmith-6.3.0 lib/rubysmith/renderers/erb.rb
rubysmith-6.2.1 lib/rubysmith/renderers/erb.rb
rubysmith-6.2.0 lib/rubysmith/renderers/erb.rb
rubysmith-6.1.0 lib/rubysmith/renderers/erb.rb
rubysmith-6.0.0 lib/rubysmith/renderers/erb.rb
rubysmith-5.9.0 lib/rubysmith/renderers/erb.rb
rubysmith-5.8.1 lib/rubysmith/renderers/erb.rb
rubysmith-5.8.0 lib/rubysmith/renderers/erb.rb
rubysmith-5.7.0 lib/rubysmith/renderers/erb.rb
rubysmith-5.6.0 lib/rubysmith/renderers/erb.rb
rubysmith-5.5.0 lib/rubysmith/renderers/erb.rb
rubysmith-5.4.0 lib/rubysmith/renderers/erb.rb
rubysmith-5.3.0 lib/rubysmith/renderers/erb.rb
rubysmith-5.2.0 lib/rubysmith/renderers/erb.rb
rubysmith-5.1.0 lib/rubysmith/renderers/erb.rb