templ README

项目的 README,来自 github.com/a-h/templ。合并为一个 markdown 文件: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

Tasks

version-set

Set the version of templ to the current version.

version set

build

Build a local version.

version set
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
# 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
go run ./cmd/templ generate -include-version=false
go test ./...

test-short

Run Go tests.

version set
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

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

test-fuzz

Run each fuzz test for FUZZTIME (default 120s).

./parser/v2/fuzz.sh
./parser/v2/goexpression/fuzz.sh
./runtime/fuzzing/fuzz.sh
./internal/jstokenizer/fuzzing/fuzz.sh

test-fuzz-corpus

Run the runtime and JavaScript tokenizer fuzz tests against their seed and committed corpora, without fuzzing. These fuzz tests are in separate modules, so that their JavaScript engine and parser dependencies are not dependencies of templ, and go test ./... in the root module doesn't run them. The parser fuzz tests are in the root module, so test and test-cover run their corpora.

(cd runtime/fuzzing && go test ./...) &&
	(cd internal/jstokenizer/fuzzing && go test ./...)

benchmark

Run benchmarks.

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

benchmark-fmt

Run the templ fmt benchmarks, which include the time taken by prettier.

go test ./internal/format -run '^$' -bench BenchmarkTempl -benchtime 3x

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

vulncheck

Check for known vulnerabilities in dependencies that templ calls.

govulncheck ./...

bump-deps

Update Go dependencies in the root module and the fuzzing modules, then update the vendor hash in flake.nix. The fuzzing modules replace templ with the root module, so they must be tidied whenever the root module's dependencies change.

go get -u ./...
go mod tidy
(cd runtime/fuzzing && go get -u ./... && go mod tidy)
(cd internal/jstokenizer/fuzzing && go get -u ./... && go mod tidy)
nix-update --flake --version=skip templ

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 --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)

正在搜索数据库…

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 的发布流程。
作者
a-h
大小
21.8 MB
星标
10.6K
时长
5年
提交 · 90 天