# Contributor: Matt Smith <mcs@darkregion.net>
# Maintainer: Matt Smith <mcs@darkregion.net>
pkgname=py-jinja2
_pkgname=Jinja2
pkgver=2.10
pkgrel=3
pkgdesc="A small but fast and easy to use stand-alone python3 template engine"
url="http://jinja.pocoo.org/"
arch="noarch"
license="BSD"
depends="py-markupsafe"
checkdepends="pytest"
makedepends="python2-dev python3-dev py-setuptools pytest"
subpackages="py2-${pkgname#py-}:_py2 py3-${pkgname#py-}:_py3
	$pkgname-doc $pkgname-vim"
source="https://files.pythonhosted.org/packages/source/${_pkgname:0:1}/$_pkgname/$_pkgname-$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"
option="!check"

build() {
	cd "$builddir"
	python2 setup.py build
	python3 setup.py build
}

package() {
	mkdir -p "$pkgdir"
}

_py2() {
	depends="${depends//py-/py2-}"
	replaces="$pkgname"
	_py python2
}

_py3() {
	depends="${depends//py-/py3-}"
	_py python3
}

_py() {
	local python="$1"
	pkgdesc="$pkgdesc (for $python)"
	depends="$depends $python"
	install_if="$pkgname=$pkgver-r$pkgrel $python"

	cd "$builddir"
	$python3 setup.py install --prefix=/usr --root="$subpkgdir"
}

doc() {
	default_doc
	local docdir="$subpkgdir/usr/share/doc/$pkgname"

	cd "$builddir"

	# Note: The documentation in the docs directory needs to be generated
	# by py-sphinx, however, this package (py-jinja2) is a dependency of
	# Sphinx itself!
	mkdir -p "$docdir"
	cp -R docs examples "$docdir"/

	install -m 644 -D LICENSE "$subpkgdir"/usr/share/licenses/$pkgname/LICENSE
}

vim() {
	pkgdesc="Vim syntax for Jinja2"
	depends="vim"
	install_if="$pkgname=$pkgver-r$pkgrel vim"

	install -m 644 -D "$builddir"/ext/Vim/jinja.vim \
		"$subpkgdir"/usr/share/vim/vimfiles/syntax/jinja.vim
}

sha512sums="0ea7371be67ffcf19e46dfd06523a45a0806e678a407d54f5f2f3e573982f0959cf82ec5d07b203670309928a62ef71109701ab16547a9bba2ebcdc178cb67f2  Jinja2-2.10.tar.gz"

