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 — это язык шаблонов для создания HTML-интерфейсов на Go, где главная фишка — удобные инструменты для разработчика.
templ — это библиотека, которую я импортирую, или отдельная утилита, которую я запускаю?И то и другое: вы пишете компоненты в файлах .templ внутри своего Go-проекта, а утилита командной строки компилирует их в обычный Go-код, который ваше приложение рендерит на сервере.
Как начать с ним работать?Установите templ CLI, напишите первые компоненты в файлах .templ и выполните 'templ generate', чтобы скомпилировать их в Go-код. В README есть ссылка на документацию с полным описанием всех шагов.
Мне нужно быть Go-разработчиком, чтобы этим пользоваться?Да — templ живёт внутри экосистемы Go: шаблоны компилируются в Go-код и форматируются вместе с ним, поэтому нужны инструментарий Go и уверенное знание этого языка.
После правки шаблонов нужно что-то перегенерировать?Да — после изменения файлов .templ нужно запустить templ generate, чтобы сгенерированный Go-код оставался актуальным; такие сгенерированные файлы принято коммитить в git.
Он работает на Windows и macOS или только на Linux?Он распространяется как бинарник командной строки на Go, поэтому работает везде, где работает Go, — на Windows, macOS и Linux, — без какого-либо специального железа или сервисов.
Он работает с htmx?Да — htmx входит в число основных тем проекта, а поскольку templ выдаёт обычный HTML, отрендеренный на сервере, он отлично сочетается с фронтендами на htmx.
Насколько хороша поддержка файлов .templ в редакторах?Хорошая по замыслу: проект заявляет отличный инструментарий для разработчика и поставляет language server (LSP), так что IDE могут давать автодополнение и подсказки об ошибках для файлов templ.
Это устоявшийся проект или новый эксперимент?Устоявшийся: templ развивается с апреля 2021 года, набрал более 10 500 звёзд на GitHub, а релизы собираются автоматически через CI и goreleaser.
Какие есть похожие проекты?dioxus, pug, gin-vue-admin, datapages, mitosis, htn_planner, open-saas, graphql-code-generator
Автор
a-h
Размер
21.8 MB
Звёзды
10.6K
Возраст
5 г
Коммиты · 90 дней