templ README

The project's README from github.com/a-h/templ. As one markdown file: README.md.

templ

An HTML templating language for Go that has great developer tooling.

templ

Documentation

See user documentation at https://templ.guide

Go Reference xc compatible Go Coverage Go Report Card

Tasks

version-set

Set the version of templ to the current version.

version set --template="0.3.%d"

build

Build a local version.

version set --template="0.3.%d"
cd cmd/templ
go build

install-snapshot

Build and install current version.

# Remove templ from the non-standard ~/bin/templ path
# that this command previously used.
rm -f ~/bin/templ
# Clear LSP logs.
rm -f cmd/templ/lspcmd/*.txt
# Update version.
version set --template="0.3.%d"
# Install to $GOPATH/bin or $HOME/go/bin
cd cmd/templ && go install

build-snapshot

Use goreleaser to build the command line binary using goreleaser.

goreleaser build --snapshot --clean

generate

Run templ generate using local version.

go run ./cmd/templ generate -include-version=false

test

Run Go tests.

version set --template="0.3.%d"
go run ./cmd/templ generate -include-version=false
go test ./...

test-short

Run Go tests.

version set --template="0.3.%d"
go run ./cmd/templ generate -include-version=false
go test ./... -short

test-cover

Run Go tests.

# Create test profile directories.
mkdir -p coverage/fmt
mkdir -p coverage/generate
mkdir -p coverage/version
mkdir -p coverage/unit
# Build the test binary.
go build -cover -o ./coverage/templ-cover ./cmd/templ
# Run the covered generate command.
GOCOVERDIR=coverage/fmt ./coverage/templ-cover fmt .
GOCOVERDIR=coverage/generate ./coverage/templ-cover generate -include-version=false
GOCOVERDIR=coverage/version ./coverage/templ-cover version
# Run the unit tests.
go test -cover ./... -coverpkg ./... -args -test.gocoverdir="$PWD/coverage/unit"
# Display the combined percentage.
go tool covdata percent -i=./coverage/fmt,./coverage/generate,./coverage/version,./coverage/unit
# Generate a text coverage profile for tooling to use.
go tool covdata textfmt -i=./coverage/fmt,./coverage/generate,./coverage/version,./coverage/unit -o coverage.out
# Print total
go tool cover -func coverage.out | grep total

test-cover-watch

interactive: true

gotestsum --watch -- -coverprofile=coverage.out

test-fuzz

./parser/v2/fuzz.sh
./parser/v2/goexpression/fuzz.sh

benchmark

Run benchmarks.

go run ./cmd/templ generate -include-version=false && go test ./... -bench=. -benchmem

fmt

Format all Go and templ code.

gofmt -s -w .
go run ./cmd/templ fmt .

lint

Run the lint operations that are run as part of the CI.

golangci-lint run --verbose

ensure-generated

Ensure that templ files have been generated with the local version of templ, and that those files have been added to git.

Requires: generate

git diff --exit-code

push-release-tag

Push a semantic version number to GitHub to trigger the release process.

version push --template="0.3.%d" --prefix="v"

docs-run

Run the development server.

Directory: docs

npm run start

docs-build

Build production docs site.

Directory: docs

npm run build

templ (a-h/templ)

Searching Database…

10.6K ·GitHub
这是什么?templ 是一种模板语言,用来在 Go 中编写 HTML 用户界面,强大的开发工具支持是它的一大卖点。
templ 是我导入的库,还是单独运行的工具?两者都是:你在 Go 项目里用 .templ 文件编写组件,然后由一个命令行工具把它们编译成普通的 Go 代码,由你的应用在服务端渲染。
怎么上手使用它?先安装 templ CLI,然后在 .templ 文件里写出你的第一批组件,再运行 'templ generate' 把它们编译成 Go 代码。README 中链接了用户文档,里面有完整的上手教程。
我必须是 Go 开发者才能用它吗?是的——templ 属于 Go 生态:模板会编译成 Go 代码并随之格式化,所以你需要 Go 工具链,并且要具备一定的 Go 基础。
修改模板之后需要重新生成什么吗?需要——改动 .templ 文件后必须运行 templ generate,让生成的 Go 代码保持同步,而且生成的文件通常要提交到 git。
它能在 Windows 和 macOS 上运行,还是只支持 Linux?它是一个 Go 命令行二进制程序,所以 Go 能运行的地方它都能运行——Windows、macOS 和 Linux,不需要特殊的硬件或服务。
它能和 htmx 配合使用吗?可以——htmx 是这个项目的核心主题之一,而且 templ 输出的是普通的服务端渲染 HTML,天然适合搭配 htmx 驱动的前端。
.templ 文件的编辑器支持怎么样?设计上就很好:项目主打出色的开发工具,并自带一个语言服务器(LSP),所以 IDE 可以为 templ 文件提供自动补全和错误提示。
这是一个成熟项目还是新实验?成熟项目:templ 从 2021 年 4 月开始开发,GitHub 星标超过 10500,并使用自动化 CI 以及基于 goreleaser 的发布流程。
Creator
a-h
Size
9.8 MB
Stars
10.6K
Age
5y
Commits · 90 Days