Skip to content

Instantly share code, notes, and snippets.

@hrdmtr
Created October 25, 2012 06:29
Show Gist options
  • Save hrdmtr/3950843 to your computer and use it in GitHub Desktop.
Save hrdmtr/3950843 to your computer and use it in GitHub Desktop.
MiniTemplatorの使い方のメモです。

VBAでテンプレートエンジンを使う

MiniTemplatorとは

MiniTemplatorのウェブサイトに、

MiniTemplator is a compact template engine for HTML files.

と紹介されている。 HTMLの生成を目的としたコンパクトなテンプレートエンジンのよう。

MiniTemplatorの導入

  1. ここから ZIPファイルをダウンロードし解凍する。
  2. 解凍したファイルに、「MiniTemplator.cls」というファイルがあるので、 このファイルをVB Script Editorにインポートする。

VBAでMiniTemplatorを使う方法

  1. テンプレートファイルを予め作っておく。
  2. テンプレートエンジン(オブジェクト)を作成する。
  3. テンプレートエンジンにテンプレートファイルを読み込む。
  4. テンプレートエンジンに変数やブロックを設定する。
  5. 結果ファイルを出力する。

ひな形

' テンプレートエンジン生成
Dim templator As New MiniTemplator

' テンプレートファイル読込
templator.ReadTemplateFromFile {fullfilename}

' 変数を設定する
templator.SetVariable "key", {値}

' ブロックを指定する
templator.AddBlock {ブロック名}

' 適用結果をファイル出力する
templator.GenerateOutputToFile {filename}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment