26 lines
561 B
Ruby
26 lines
561 B
Ruby
module Adr
|
|
# Renders templates/adr.md by substituting {{key}} placeholders.
|
|
# Arrays render as YAML flow sequences; missing keys render empty.
|
|
class Template
|
|
def initialize(path:)
|
|
@path = path
|
|
end
|
|
|
|
def render(values)
|
|
File.read(@path).gsub(/\{\{(\w+)\}\}/) do
|
|
format_value(values[Regexp.last_match(1).to_sym])
|
|
end.gsub(/ +$/, "")
|
|
end
|
|
|
|
private
|
|
|
|
def format_value(value)
|
|
case value
|
|
when nil then ""
|
|
when Array then "[#{value.join(', ')}]"
|
|
else value.to_s
|
|
end
|
|
end
|
|
end
|
|
end
|