maintainer="Hoang Nguyen <folliekazetani@protonmail.com>"
pkgname=templ
pkgver=0.2.778
pkgrel=0
pkgdesc="Language for writing HTML user interface in Go"
url="https://templ.guide/"
arch="all"
license="MIT"
makedepends="go"
checkdepends="gopls"
source="$pkgname-$pkgver.tar.gz::https://github.com/a-h/templ/archive/refs/tags/v$pkgver.tar.gz"
options="net" # download Go modules

# /cmd/templ/lspcmd: hangs on s390x, fails on riscv64, ppc64le and loongarch64
# /cmd/templ/generatecmd/testwatch: panics on 32-bit platforms (unaligned 64-bit atomic operation)
case "$CARCH" in
	armhf|armv7|loongarch64|ppc64le|riscv64|s390x|x86) options="$options !check";;
esac

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	go build -v ./cmd/templ
}

check() {
	echo "$pkgver" > .version
	go run ./cmd/templ generate -include-version=false

	# Removing -trimpath is needed for tests inside cmd/templ/generatecmd/testwatch and cmd/templ/lspcmd.
	# The tests create template files relative to the current directory and try to watch those files.
	GOFLAGS="${GOFLAGS/-trimpath/}" go test ./...
}

package() {
	install -Dm755 $pkgname -t "$pkgdir"/usr/bin/
}

sha512sums="
cc5a795510208e5cacdd9412518b02956fa48d057bf93472eb2b6c4c69ea734007f6f7ce0d0b95ad8ea3edcce846ac6b99e370f48502bb7ed23589bc777382e1  templ-0.2.778.tar.gz
"
