Module: Tapioca::Helpers::Test::Template

Extended by:
T::Helpers, T::Sig
Included in:
DslCompiler
Defined in:
lib/tapioca/helpers/test/template.rb

Constant Summary collapse

ERB_SUPPORTS_KVARGS =
T.let(
  ::ERB.instance_method(:initialize).parameters.assoc(:key), T.nilable([Symbol, Symbol])
)

Instance Method Summary collapse

Instance Method Details

#indented(str, indent) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/tapioca/helpers/test/template.rb', line 36

def indented(str, indent)
  str.lines.map! do |line|
    next line if line.chomp.empty?

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

#ruby_version(selector) ⇒ Object



20
21
22
# File 'lib/tapioca/helpers/test/template.rb', line 20

def ruby_version(selector)
  ::Gem::Requirement.new(selector).satisfied_by?(::Gem::Version.new(RUBY_VERSION))
end

#template(src) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/tapioca/helpers/test/template.rb', line 25

def template(src)
  erb = if ERB_SUPPORTS_KVARGS
    ::ERB.new(src, trim_mode: ">")
  else
    ::ERB.new(src, nil, ">")
  end

  erb.result(binding)
end