From fa7eaefd958146ec32f8ccc10507eca97c7a4b69 Mon Sep 17 00:00:00 2001 From: Dominic Date: Tue, 19 Sep 2023 10:56:09 +0200 Subject: [PATCH] Fix default template when details are missing --- src/README.j2 | 12 ++++++------ tests/pass/default-template-no-details/Cargo.lock | 7 +++++++ tests/pass/default-template-no-details/Cargo.toml | 8 ++++++++ tests/pass/default-template-no-details/README.md | 4 ++++ tests/pass/default-template-no-details/lib.rs | 2 ++ 5 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 tests/pass/default-template-no-details/Cargo.lock create mode 100644 tests/pass/default-template-no-details/Cargo.toml create mode 100644 tests/pass/default-template-no-details/README.md create mode 100644 tests/pass/default-template-no-details/lib.rs diff --git a/src/README.j2 b/src/README.j2 index daefea6..b410d1e 100644 --- a/src/README.j2 +++ b/src/README.j2 @@ -1,20 +1,20 @@ {# this is the default template used when the user does not specify one #} -{%- if crate is defined -%} +{%- if crate -%} # {{ crate }} - {%- if license is defined %} ![License: {{ license }}](https://img.shields.io/badge/license-{{ license | replace("-", "--") | urlencode }}-blue) + {%- if license %} ![License: {{ license }}](https://img.shields.io/badge/license-{{ license | replace("-", "--") | urlencode }}-blue) {%- else %} ![License](https://img.shields.io/crates/l/{{ crate | urlencode }}) {%- endif %} - {%- if crate is defined %} [![{{ crate }} on crates.io](https://img.shields.io/crates/v/{{ crate | urlencode }})](https://crates.io/crates/{{ crate | urlencode }}) + {%- if crate %} [![{{ crate }} on crates.io](https://img.shields.io/crates/v/{{ crate | urlencode }})](https://crates.io/crates/{{ crate | urlencode }}) {%- if target == "lib" %} [![{{ crate }} on docs.rs](https://docs.rs/{{ crate | urlencode }}/badge.svg)](https://docs.rs/{{ crate | urlencode }}) {%- endif %} {%- endif %} - {%- if repository is defined %} + {%- if repository %} {%- if repository_host == "github.com" %} [![Source Code Repository](https://img.shields.io/badge/Code-On%20GitHub-blue?logo=GitHub)]({{ repository }}) - {%- elif repository_host is defined %} [![Source Code Repository](https://img.shields.io/badge/Code-On%20{{ repository_host | replace("-", "--") | urlencode }}-blue)]({{ repository }}) + {%- elif repository_host %} [![Source Code Repository](https://img.shields.io/badge/Code-On%20{{ repository_host | replace("-", "--") | urlencode }}-blue)]({{ repository }}) {%- endif %} {%- endif %} - {%- if rust_version is defined %} ![Rust Version: {{rust_version}}](https://img.shields.io/badge/rustc-{{ rust_version | urlencode }}-orange.svg) + {%- if rust_version %} ![Rust Version: {{rust_version}}](https://img.shields.io/badge/rustc-{{ rust_version | urlencode }}-orange.svg) {%- endif %} {%- endif %} diff --git a/tests/pass/default-template-no-details/Cargo.lock b/tests/pass/default-template-no-details/Cargo.lock new file mode 100644 index 0000000..357c60a --- /dev/null +++ b/tests/pass/default-template-no-details/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "default_template_no_details" +version = "0.0.0" diff --git a/tests/pass/default-template-no-details/Cargo.toml b/tests/pass/default-template-no-details/Cargo.toml new file mode 100644 index 0000000..bd0edd5 --- /dev/null +++ b/tests/pass/default-template-no-details/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "default_template_no_details" +version = "0.0.0" +publish = false +edition = "2021" + +[lib] +path = "lib.rs" diff --git a/tests/pass/default-template-no-details/README.md b/tests/pass/default-template-no-details/README.md new file mode 100644 index 0000000..76d01f3 --- /dev/null +++ b/tests/pass/default-template-no-details/README.md @@ -0,0 +1,4 @@ +# default_template_no_details ![License](https://img.shields.io/crates/l/default_template_no_details) [![default_template_no_details on crates.io](https://img.shields.io/crates/v/default_template_no_details)](https://crates.io/crates/default_template_no_details) [![default_template_no_details on docs.rs](https://docs.rs/default_template_no_details/badge.svg)](https://docs.rs/default_template_no_details) + +This test ensures that the default template behaves well when there are no details (like description, license, rust-version etc) defined in the `Cargo.toml` file. + diff --git a/tests/pass/default-template-no-details/lib.rs b/tests/pass/default-template-no-details/lib.rs new file mode 100644 index 0000000..d4fd8e3 --- /dev/null +++ b/tests/pass/default-template-no-details/lib.rs @@ -0,0 +1,2 @@ +//! This test ensures that the default template behaves well when there are no details +//! (like description, license, rust-version etc) defined in the `Cargo.toml` file.