aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Barbato <lu_zero@gentoo.org>2021-07-29 17:16:48 +0200
committerGeorgy Yakovlev <gyakovlev@gentoo.org>2021-08-25 08:11:29 -0700
commitb01082acb7bb01817247bd5947b9d59294a885fb (patch)
tree8778c55d0abde71c0b81a02b1d00f7bd0cf3078d
parentAdd an option to provide a custom tera template (diff)
downloadcargo-ebuild-b01082acb7bb01817247bd5947b9d59294a885fb.tar.gz
cargo-ebuild-b01082acb7bb01817247bd5947b9d59294a885fb.tar.bz2
cargo-ebuild-b01082acb7bb01817247bd5947b9d59294a885fb.zip
Move the bulk of the template to base.tera
Custom templates can just implement the blocks they care for Signed-off-by: Luca Barbato <lu_zero@gentoo.org> Signed-off-by: Georgy Yakovlev <gyakovlev@gentoo.org>
-rw-r--r--src/base.tera33
-rw-r--r--src/ebuild.tera28
-rw-r--r--src/lib.rs2
3 files changed, 36 insertions, 27 deletions
diff --git a/src/base.tera b/src/base.tera
new file mode 100644
index 0000000..e1f4571
--- /dev/null
+++ b/src/base.tera
@@ -0,0 +1,33 @@
+{%- block header -%}
+# Copyright 2017-{{ this_year }} Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# Auto-Generated by cargo-ebuild {{ cargo_ebuild_ver }}
+{% endblock %}
+EAPI={%- block eapi -%}7{%- endblock %}
+
+{% block crates -%}
+CRATES="
+{% for crate in crates -%}
+{{ crate }}
+{%- endfor -%}"
+{%- endblock %}
+
+inherit {% block inherit -%}cargo{%- endblock %}
+
+DESCRIPTION={%- block description -%}"{{ description | trim }}"{%- endblock %}
+# Double check the homepage as the cargo_metadata crate
+# does not provide this value so instead repository is used
+HOMEPAGE={%- block homepage -%}"{{ homepage }}"{%- endblock %}
+SRC_URI={%- block src_uri -%}{% raw -%}"$(cargo_crate_uris ${CRATES})"{%- endraw %}{%- endblock %}
+# License set may be more restrictive as OR is not respected
+# use cargo-license for a more accurate license picture
+LICENSE={%- block license -%}"{{ license }}"{%- endblock %}
+SLOT={%- block slot -%}"0"{%- endblock %}
+KEYWORDS={%- block keyword -%}"~amd64"{%- endblock %}
+{% block variables -%}
+RESTRICT="mirror"
+{%- endblock %}
+
+{%- block phases -%}
+{%- endblock -%}
diff --git a/src/ebuild.tera b/src/ebuild.tera
index b83675d..9ba9906 100644
--- a/src/ebuild.tera
+++ b/src/ebuild.tera
@@ -1,27 +1 @@
-# Copyright 2017-{{ this_year }} Gentoo Authors
-# Distributed under the terms of the GNU General Public License v2
-
-# Auto-Generated by cargo-ebuild {{ cargo_ebuild_ver }}
-
-EAPI=7
-
-CRATES="
-{% for crate in crates -%}
-{{ crate }}
-{%- endfor -%}"
-
-inherit cargo
-
-DESCRIPTION="{{ description | trim }}"
-# Double check the homepage as the cargo_metadata crate
-# does not provide this value so instead repository is used
-HOMEPAGE="{{ homepage }}"
-{% raw -%}
-SRC_URI="$(cargo_crate_uris ${CRATES})"
-{%- endraw %}
-# License set may be more restrictive as OR is not respected
-# use cargo-license for a more accurate license picture
-LICENSE="{{ license }}"
-SLOT="0"
-KEYWORDS="~amd64"
-RESTRICT="mirror"
+{%- extends "base.tera" -%}
diff --git a/src/lib.rs b/src/lib.rs
index 8f53e17..db9d54b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -141,6 +141,8 @@ pub fn write_ebuild(
let mut tera = tera::Tera::default();
let mut context = tera::Context::from_serialize(ebuild_data)?;
+
+ tera.add_raw_template("base.tera", include_str!("base.tera"))?;
if let Some(template) = template_path {
tera.add_template_file(template, Some("ebuild.tera"))?;
} else {