本体は ERB.new().result を呼ぶだけで、それをmrubyでdarwin/linuxのx86_64/aarch64向けにビルドした。
以下のようにシングルバイナリプログラムを通してテンプレートファイルを処理できる。
<%-
to = ENV["MAIL_TO"]
priorities = ENV["PRIORITIES"].split(",").map(&:strip)
-%>
From: James <james@example.com>
To: <%= to %>
Subject: Addressing Needs
<%= to[/\w+/] %>:
Just wanted to send a quick note assuring that your needs are being
addressed.
I want you to know that my team will keep working on the issues,
especially:
<%# ignore numerous minor requests -- focus on priorities %>
<%- priorities.each do |priority| -%>
* <%= priority %>
<%- end -%>
Thanks for your patience.
James
$ export MAIL_TO="Community Spokesman <spokesman@example.com>" $ export PRIORITIES="Run Ruby Quiz,Document Modules,Answer Questions on Ruby Talk" $ minierb mail.erb From: James <james@example.com> To: Community Spokesman <spokesman@example.com> Subject: Addressing Needs Community: Just wanted to send a quick note assuring that your needs are being addressed. I want you to know that my team will keep working on the issues, especially: * Run Ruby Quiz * Document Modules * Answer Questions on Ruby Talk Thanks for your patience. James
Dockerコンテナを動かすときに設定値の注入のため環境変数経由で設定ファイルを書き換えることがよくある。 sedで頑張っているDockerイメージもあるし、Docker社の提供するnginxイメージだと組み込みでenvsubstがついてくる。
しかし、単純にプレースホルダを環境変数で置換するだけだと、全然機能が足りないと思っていて、条件分岐や繰り返し、デフォルト値の設定が欲しくなる。 Rubyには組み込みでERBが含まれているが、nginxなどのコンテナにRubyランタイム一式をインストールはしたくない。 そうすると選択肢が限られてきて、自分はGoのテンプレートが使えるsigilを使うことが多かった。
Goのテンプレートは個人的には結構好きだが、パイプラインのような書き方を好まない人もいそうだなとか、もう少しだけテキスト処理を便利にしてほしいなどのニーズがありそうだな…ということで、minierbを作ってみた。
他のエンジニアがDocker向けにどのようなテンプレートプロセッサーを利用しているのか、とても気になる。
