1
0
Fork 0
forked from acute/readme

Compare commits

..

No commits in common. "master" and "master" have entirely different histories.

7 changed files with 99 additions and 1169 deletions

2
.gitignore vendored
View file

@ -1,2 +0,0 @@
target
.idea

1057
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -7,10 +7,10 @@ href = "https://guardianproject.dev/jasima/lipu-pali"
name = "Example Project" name = "Example Project"
summary = "An example project for example use" summary = "An example project for example use"
description = """ description = """
This is an extended description of the example project. This is an extended description of the example project.
Look how much longer it is than the summary. Look how much longer it is than the summary.
The summary is just one line, but the description is many. The summary is just one line, but the description is many.
""" """
language = "Rust" language = "Rust"
licence = "BSD-2-Clause" licence = "BSD-2-Clause"
lifecycle = "experimental" lifecycle = "experimental"

View file

@ -1,25 +1,24 @@
[BSD-2-Clause] [BSD-2-Clause]
name = "BSD 2-Clause"
class = "permissive" class = "permissive"
grant = """ grant = """
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, 1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, 2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
""" """

View file

@ -1,17 +1,14 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap; use std::collections::HashMap;
use std::fs; use std::fs;
use std::fs::File; use tera::Tera;
use std::io::Write; use serde::Deserialize;
use tera::{to_value, try_get_value, Result, Tera, Value}; #[derive(Deserialize, serde::Serialize)]
#[derive(Deserialize, Serialize)]
struct ReadmeConfig { struct ReadmeConfig {
header: Image, header: Image,
project: Project, project: Project
} }
#[derive(Deserialize, Serialize)] #[derive(Deserialize, serde::Serialize)]
struct Project { struct Project {
name: String, name: String,
summary: String, summary: String,
@ -22,69 +19,39 @@ struct Project {
badges: Vec<Image>, badges: Vec<Image>,
} }
#[derive(Deserialize, Serialize)] #[derive(Deserialize, serde::Serialize)]
struct Image { struct Image {
alt: String, alt: String,
href: String, href: String,
src: String, src: String,
} }
#[derive(Deserialize, Serialize)] #[derive(Deserialize)]
struct Language { struct Language {
color: String, color: String
} }
#[derive(Deserialize, Serialize)]
struct Licence {
name: String,
class: String,
grant: String,
}
fn licence_badge(name: &Value, _: &HashMap<String, Value>) -> Result<Value> {
let mut s = try_get_value!("licence_badge", "value", String, name);
s = s.to_lowercase().replace("-", "--").replace(" ", "%20");
Ok(to_value(s.as_str())?)
}
fn licence_colour(name: &Value, _: &HashMap<String, Value>) -> Result<Value> {
let s = try_get_value!("licence_colour", "value", String, name);
let result = match s.as_str() {
"publicdomain" => "7cd958",
"permissive" => "green",
"copyleft" => "orange",
"proprietary" => "red",
_ => "grey",
};
Ok(to_value(result)?)
}
fn main() { fn main() {
let template = include_str!("template.md"); let mut readme_template = Tera::new("templates/**/*").unwrap();
let mut tera = Tera::default(); readme_template.add_template_file("templates/readme_templ.j2", Option::from("readme")).unwrap();
tera.add_raw_template("template.md", template) let mut context = tera::Context::new();
.expect("failed to add template");
tera.register_filter("licence_badge", licence_badge);
tera.register_filter("licence_colour", licence_colour);
let languages_toml = include_str!("languages.toml"); let language_colours = include_str!("languages.toml");
let languages: HashMap<String, Language> = toml::from_str(languages_toml).unwrap(); let language_colours_config: HashMap<String, Language> = toml::from_str(language_colours).unwrap();
// println!("{:?}", colours_config);
let licences_toml = include_str!("licences.toml");
let licences: HashMap<String, Licence> = toml::from_str(licences_toml).unwrap();
let toml_filename = "README.toml"; let toml_filename = "README.toml";
let contents: String = fs::read_to_string(toml_filename).unwrap(); let contents: String = fs::read_to_string(toml_filename).unwrap();
let readme_config: ReadmeConfig = let readme_config: ReadmeConfig = toml::from_str(&contents).expect("Failed to parse readme.toml");
toml::from_str(&contents).expect("Failed to parse readme.toml");
let mut context = tera::Context::new(); let project_language = &readme_config.project.language;
let project_language_colour = language_colours_config.get(project_language).unwrap();
context.insert("config", &readme_config); context.insert("config", &readme_config);
context.insert("language", &languages.get(&readme_config.project.language));
context.insert("licence", &licences.get(&readme_config.project.licence)); let rendered = readme_template.render("readme", &context).unwrap();
//println!("{}", rendered);
let rendered = tera.render("template.md", &context).unwrap();
let mut file = File::create("README.md").expect("could not create README.md");
file.write_all(rendered.as_bytes())
.expect("failed to write to README.md");
} }

View file

@ -1,30 +0,0 @@
<h1 align="center">
<br>
<a href="{{ config.header.href }}"> <img src="{{ config.header.src }}" alt="{{ config.header.alt }}"> </a>
<br>
</h1>
<p align="center">
{% if licence.name -%}
<img src="https://img.shields.io/badge/license-{{ licence.name | licence_badge }}-{{ licence.class | licence_colour }}?style=flat-square">
{% endif -%}
{% for badge in config.project.badges -%}
{% if badge.href -%}
<a href="{{ badge.href }}"><img alt="{{ badge.alt }}" src="{{ badge.src }}"></a>
{% else -%}
<img alt="{{badge.alt}}" src="{{badge.src}}">
{% endif -%}
{% endfor -%}
</p>
## {{ config.project.name }}
*{{ config.project.summary }}*
{{ config.project.description }}
### Licence
Copyright © 2022-2025 irl.
{{ licence.grant }}

53
templates/readme_templ.j2 Normal file
View file

@ -0,0 +1,53 @@
<h1 align="center">
<br>
<a href="{{ config.header.href }}"> <img src="{{ config.header.src }}" alt="{{ config.header.alt }}"> </a>
<br>
</h1>
<p align="center">
{% for badge in config.project.badges %}
{% if badge.href %}
<a href="{{ badge.href }}"><img alt="{{ badge.alt }}" src="{{ badge.src }}"></a>
{% else %}
<img alt="{{badge.alt}}" src="{{badge.src}}">
{% endif %}
{% endfor %}
</p>
## {{ config.project.name }}
{{ config.project.summary }}
{{ config.project.description }}
### Usage
Use these as examples, but I would strongly recommend you do not include these directly in your IaC.
If something here fits your needs really well, maybe [get in touch](https://irl.xyz/contact/) with me and check if I'm
planning to maintain that role or playbook.
Sometimes a bit of external motivation is the push I need to get something finished, otherwise you can always
[hire me to do it](https://www.sr2.uk/).
### Licence
Copyright © 2022-2025 irl.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following
disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.