Home / v0.1
Name Modified Size InfoDownloads / Week
Parent folder
compiler.exe 2018-08-27 3.6 MB
Totals: 1 Item   3.6 MB 0

Go Text Template Compiler

這是一個將 Golang 的模板編譯的編譯器。

使用說明

假使你的資料夾如下

│  compiler.exe
├─bin
└─templates
       main.css
       header.tmpl
       index.tmpl

編譯器會將你 templates 的內容轉為 index.html 放置於 bin 資料夾之中

範例

以上面為例,假設各檔案內容如下:

main.css:

body{
    color: #333;
    font-family: arial, sans-serif;
}

header.tmpl:

<h1>My Page</h1>

index.tmpl

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Sample Document</title>
    <style>{{template "main.css"}}</style>
</head>
<body>
    <header>{{template "header.tmpl"}}</header>
    <p>This is a sample</p>
</body>
</html>

則執行 compiler 後會生成 bin/index.html

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Sample Document</title>
    <style>body{
    color: #333;
    font-family: arial, sans-serif;
}</style>
</head>
<body>
    <header><h1>My Page</h1></header>
    <p>This is a sample</p>
</body>
</html>
Source: README.md, updated 2018-04-18