Sha256: a3041cf49469845f9b4069b7077e4eaa2ddb1f3afc0d07ef46b6e23e5c8e6fed
Contents?: true
Size: 1.08 KB
Versions: 4
Compression:
Stored size: 1.08 KB
Contents
# typed: strict # frozen_string_literal: true require "erb" 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(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 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
4 entries across 4 versions & 1 rubygems