commit: b01082acb7bb01817247bd5947b9d59294a885fb
Author: Luca Barbato <lu_zero <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 29 15:16:48 2021 +0000
Commit: Georgy Yakovlev <gyakovlev <AT> gentoo <DOT> org>
CommitDate: Wed Aug 25 15:11:29 2021 +0000
URL: https://gitweb.gentoo.org/proj/cargo-ebuild.git/commit/?id=b01082ac
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 <AT> gentoo.org>
Signed-off-by: Georgy Yakovlev <gyakovlev <AT> gentoo.org>
src/base.tera | 33 +++++++++++++++++++++++++++++++++
src/ebuild.tera | 28 +---------------------------
src/lib.rs | 2 ++
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 {