lib/tapioca/helpers/test/template.rb in tapioca-0.6.4 vs lib/tapioca/helpers/test/template.rb in tapioca-0.7.0
- old
+ new
@@ -5,19 +5,22 @@
module Tapioca
module Helpers
module Test
module Template
- include Kernel
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))
+ ::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
@@ -25,9 +28,17 @@
else
::ERB.new(src, nil, ">")
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