Sha256: 162b3758300092e1e13f934962c351b3baa901167565d7c4d67ca28765fe79ef

Contents?: true

Size: 815 Bytes

Versions: 5

Compression:

Stored size: 815 Bytes

Contents

# typed: strict
# frozen_string_literal: true

require "erb"

module Tapioca
  module Helpers
    module Test
      module Template
        include Kernel
        extend T::Sig
        ERB_SUPPORTS_KVARGS = T.let(
          ::ERB.instance_method(:initialize).parameters.assoc(:key), T.nilable([Symbol, Symbol])
        )

        sig { params(selector: String).returns(T::Boolean) }
        def ruby_version(selector)
          Gem::Requirement.new(selector).satisfied_by?(Gem::Version.new(RUBY_VERSION))
        end

        sig { params(src: String).returns(String) }
        def template(src)
          erb = if ERB_SUPPORTS_KVARGS
            ::ERB.new(src, trim_mode: ">")
          else
            ::ERB.new(src, nil, ">")
          end

          erb.result(binding)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tapioca-0.6.4 lib/tapioca/helpers/test/template.rb
tapioca-0.6.3 lib/tapioca/helpers/test/template.rb
tapioca-0.6.2 lib/tapioca/helpers/test/template.rb
tapioca-0.6.1 lib/tapioca/helpers/test/template.rb
tapioca-0.6.0 lib/tapioca/helpers/test/template.rb