Skip to content

Commit d6bbe74

Browse files
author
Niko Matsakis
committed
WIP: templates
1 parent b4498e5 commit d6bbe74

File tree

8 files changed

+1156
-132
lines changed

8 files changed

+1156
-132
lines changed

Cargo.lock

Lines changed: 305 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mdbook-goals/2024h2.md

Lines changed: 633 additions & 0 deletions
Large diffs are not rendered by default.

mdbook-goals/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ aws-config = "1.5.8"
2222
aws-sdk-bedrock = "1.57.0"
2323
aws-sdk-bedrockruntime = "1.55.0"
2424
tokio = { version = "1.41.0", features = ["full"] }
25-
handlebars = "6.1.0"
25+
handlebars = { version = "6.1.0", features = ["dir_source"] }
26+
comrak = "0.29.0"

mdbook-goals/src/json.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct TrackingIssue {
9292
state: ExistingIssueState,
9393
}
9494

95-
#[derive(Serialize)]
95+
#[derive(Serialize, Debug)]
9696
pub enum Progress {
9797
/// We could not find any checkboxes or other deatils on the tracking issue.
9898
/// So all we have is "open" or "closed".
@@ -120,23 +120,6 @@ struct TrackingIssueUpdate {
120120
pub url: String,
121121
}
122122

123-
impl Progress {
124-
/// Returns the number of completed and total items. Returns (0, 0) in the case of an error.
125-
pub fn completed_total(&self) -> (u32, u32) {
126-
match *self {
127-
Progress::Binary { is_closed } => {
128-
if is_closed {
129-
(1, 1)
130-
} else {
131-
(0, 1)
132-
}
133-
}
134-
Progress::Tracked { completed, total } => (completed, total),
135-
Progress::Error { .. } => (0, 0),
136-
}
137-
}
138-
}
139-
140123
/// Identify how many sub-items have been completed.
141124
/// These can be encoded in two different ways:
142125
///

mdbook-goals/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mod re;
1818
mod rfc;
1919
mod team;
2020
mod team_repo;
21+
mod templates;
2122
mod updates;
2223
mod util;
2324

mdbook-goals/src/templates.rs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
use std::path::{Path, PathBuf};
2+
3+
use handlebars::{DirectorySourceOptions, Handlebars};
4+
use serde::Serialize;
5+
6+
use crate::json::Progress;
7+
8+
pub struct Templates<'h> {
9+
reg: Handlebars<'h>,
10+
}
11+
12+
impl<'h> Templates<'h> {
13+
pub fn new() -> anyhow::Result<Self> {
14+
let templates = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../templates");
15+
Self::from_templates_dir(&templates)
16+
}
17+
18+
pub fn from_templates_dir(dir_path: impl AsRef<Path>) -> anyhow::Result<Self> {
19+
let dir_path = dir_path.as_ref();
20+
let mut reg = Handlebars::new();
21+
22+
reg.set_strict_mode(true);
23+
24+
reg.register_templates_directory(dir_path, DirectorySourceOptions::default())?;
25+
assert!(reg.get_template("updates").is_some());
26+
27+
reg.register_helper("markdown_to_html", Box::new(markdown_to_html));
28+
29+
Ok(Templates { reg })
30+
}
31+
}
32+
33+
handlebars::handlebars_helper!(markdown_to_html: |md: String| comrak::markdown_to_html(&md, &Default::default()));
34+
35+
/// The parameters expected by the `updates.md` template.
36+
#[derive(Serialize, Debug)]
37+
pub struct Updates {
38+
pub milestone: String,
39+
pub flagship_goals: Vec<UpdatesFlagshipGoal>,
40+
pub other_goals: Vec<UpdatesOtherGoal>,
41+
}
42+
43+
impl Updates {
44+
pub fn render(self) -> anyhow::Result<String> {
45+
let templates = Templates::new()?;
46+
Ok(templates.reg.render("updates", &self)?)
47+
}
48+
}
49+
50+
#[derive(Serialize, Debug)]
51+
pub struct UpdatesFlagshipGoal {
52+
/// Title of the tracking issue
53+
pub title: String,
54+
55+
/// Tracking issue number on the project goals repository
56+
pub issue_number: u64,
57+
58+
/// Comma-separated list of assignees
59+
pub issue_assignees: String,
60+
61+
/// URL of the tracking issue
62+
pub issue_url: String,
63+
64+
/// Progress towards the goal
65+
pub progress: Progress,
66+
67+
/// Updates provided towards the goal
68+
pub updates: Vec<UpdatesFlagshipGoalUpdate>,
69+
}
70+
71+
#[derive(Serialize, Debug)]
72+
pub struct UpdatesFlagshipGoalUpdate {
73+
/// Username of the person who wrote the update
74+
pub author: String,
75+
76+
/// Formatted like "Oct 26"
77+
pub date: String,
78+
79+
/// Text of the update
80+
pub update: String,
81+
82+
/// URL of the comment
83+
pub url: String,
84+
}
85+
86+
#[derive(Serialize, Debug)]
87+
pub struct UpdatesOtherGoal {
88+
/// Title of the tracking issue
89+
pub title: String,
90+
91+
/// Tracking issue number on the project goals repository
92+
pub issue_number: u64,
93+
94+
/// Comma-separated list of assignees
95+
pub issue_assignees: String,
96+
97+
/// URL of the tracking issue
98+
pub issue_url: String,
99+
100+
/// Markdown with update text (bullet list)
101+
pub updates_markdown: String,
102+
103+
/// Progress towards the goal
104+
pub progress: Progress,
105+
}

0 commit comments

Comments
 (0)