module LuckyTemplate::Fileable
Overview
An interface for a file
Simple example using IO:
class Hello
include LuckyTemplate::Fileable
def to_file(io : IO) : Nil
io << "hello"
end
end
Example using ECR templates:
require "ecr"
class Hello
include LuckyTemplate::Fileable
def to_file(io : IO) : Nil
to_s(io)
end
ECR.def_to_s "hello.ecr"
end
Example using Process to run envsubst
:
class Hello
include LuckyTemplate::Fileable
def to_file(io : IO) : Nil
input = IO::Memory.new("Hello $NAME!")
Process.run(
command: "envsubst",
input: input,
output: io,
env: {
"NAME" => "World",
}
)
end
end
Defined in:
lucky_template/file.crInstance Method Summary
-
#to_file(io : IO) : Nil
Appends contents to
IO
for a file