Sha256: 7795b78b12a9b7b70d0cbc5af808ed81104bdb453f5905e9df48a285001f0066

Contents?: true

Size: 1.3 KB

Versions: 27

Compression:

Stored size: 1.3 KB

Contents

# typed: strict
# frozen_string_literal: true

module Tapioca
  module Helpers
    module Test
      module Template
        extend T::Sig
        extend T::Helpers

        requires_ancestor { Kernel }

        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(selector: String).returns(T::Boolean) }
        def rails_version(selector)
          ::Gem::Requirement.new(selector).satisfied_by?(ActiveSupport.gem_version)
        end

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

          erb.result(binding)
        end

        sig { params(str: String, indent: Integer).returns(String) }
        def indented(str, indent)
          str.lines.map! do |line|
            next line if line.chomp.empty?

            (" " * indent) + line
          end.join
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
tapioca-0.11.15 lib/tapioca/helpers/test/template.rb
tapioca-0.11.14 lib/tapioca/helpers/test/template.rb
tapioca-0.11.13 lib/tapioca/helpers/test/template.rb
tapioca-0.11.12 lib/tapioca/helpers/test/template.rb
tapioca-0.11.11 lib/tapioca/helpers/test/template.rb
tapioca-0.11.10 lib/tapioca/helpers/test/template.rb
tapioca-0.11.9 lib/tapioca/helpers/test/template.rb