Эх сурвалжийг харах

Make render respect template's pre and post text of the line where interpolation happens

Santiago Pastorino 5 жил өмнө
parent
commit
ba01b22962

+ 23 - 9
src/meeting.rs

@@ -32,7 +32,7 @@ pub struct QueryMap<'a> {
 }
 
 pub trait Template: Send {
-    fn render(&self) -> String;
+    fn render(&self, pre: &str, post: &str) -> String;
 }
 
 pub struct FileTemplate<'a> {
@@ -103,7 +103,7 @@ impl<'a> Action for Step<'a> {
         }
 
         let template = FileTemplate::new(self.name, map);
-        template.render()
+        template.render("", "")
     }
 }
 
@@ -114,7 +114,7 @@ impl<'a> FileTemplate<'a> {
 }
 
 impl<'a> Template for FileTemplate<'a> {
-    fn render(&self) -> String {
+    fn render(&self, _pre: &str, _post: &str) -> String {
         let relative_path = format!("templates/{}.tt", self.name);
         let path = env::current_dir().unwrap().join(relative_path);
         let path = path.as_path();
@@ -122,9 +122,23 @@ impl<'a> Template for FileTemplate<'a> {
         let mut contents = String::new();
         file.read_to_string(&mut contents).unwrap();
 
+        let mut replacements = Vec::new();
+
         for (var, template) in &self.map {
             let var = format!("{{{}}}", var);
-            contents = contents.replace(&var, &template.render());
+            for line in contents.lines() {
+                if line.contains(&var) {
+                    if let Some(var_idx) = line.find(&var) {
+                        let pre = &line[..var_idx];
+                        let post = &line[var_idx + var.len()..];
+                        replacements.push((line.to_string(), template.render(pre, post)));
+                    }
+                }
+            }
+        }
+
+        for (line, content) in replacements {
+            contents = contents.replace(&line, &content);
         }
 
         contents
@@ -138,14 +152,14 @@ impl IssuesTemplate {
 }
 
 impl Template for IssuesTemplate {
-    fn render(&self) -> String {
+    fn render(&self, pre: &str, post: &str) -> String {
         let mut out = String::new();
 
         if !self.issues.is_empty() {
             for issue in &self.issues {
                 out.push_str(&format!(
-                    "\"{}\" [#{}]({})\n",
-                    issue.title, issue.number, issue.html_url,
+                    "{}\"{}\" [#{}]({}){}\n",
+                    pre, issue.title, issue.number, issue.html_url, post,
                 ));
             }
         } else {
@@ -163,7 +177,7 @@ impl IssueCountTemplate {
 }
 
 impl Template for IssueCountTemplate {
-    fn render(&self) -> String {
-        format!("\"{}\"", self.count)
+    fn render(&self, pre: &str, post: &str) -> String {
+        format!("{}{}{}", pre, self.count, post)
     }
 }

+ 3 - 3
templates/agenda.tt

@@ -10,11 +10,11 @@ tags: prioritization, rustc
 
 - Major Changes Proposals:
   - Seconded proposals (in FCP)
-{mcp.seconded}
+    - {mcp.seconded}
   - New proposals (not seconded)
-{mcp.new_not_seconded}
+    - {mcp.new_not_seconded}
   - Old proposals (not seconded)
-{mcp.old_not_seconded}
+    - {mcp.old_not_seconded}
 
 ## Beta-nominations
 

+ 4 - 4
templates/nominations.tt

@@ -16,7 +16,7 @@
 
 ### Issues
 
-{nominations.beta_nominated}
+- {nominations.beta_nominated}
 
 ## I-nominated
 
@@ -26,7 +26,7 @@
 
 ### Issues
 
-{nominations.i_nominated}
+- {nominations.i_nominated}
 
 2. [I-nominated T-compiler](https://github.com/rust-lang/rust/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3AI-nominated+label%3AT-compiler)
     - Remove leftovers from last meeting.
@@ -34,7 +34,7 @@
 
 ### Issues
 
-{nominations.i_nominated_t_compiler}
+- {nominations.i_nominated_t_compiler}
 
 3. [I-nominated libs-impl](https://github.com/rust-lang/rust/issues?utf8=%E2%9C%93&q=is%3Aopen+label%3AI-nominated+label%3Alibs-impl)
     - Remove leftovers from last meeting.
@@ -42,4 +42,4 @@
 
 ### Issues
 
-{nominations.i_nominated_libs_impl}
+- {nominations.i_nominated_libs_impl}

+ 3 - 3
templates/prs_waiting_on_team.tt

@@ -6,18 +6,18 @@
 
 ### Issues
 
-{prs_waiting_on_team.all}
+- {prs_waiting_on_team.all}
 
 2. [PR's waiting on T-compiler](https://github.com/rust-lang/rust/pulls?q=is%3Aopen+is%3Apr+label%3AS-waiting-on-team+label%3AT-compiler)
     - Explicitly nominate any that you think may be able to be resolved *quickly* in triage meeting.
 
 ### Issues
 
-{prs_waiting_on_team.t_compiler}
+- {prs_waiting_on_team.t_compiler}
 
 3. [PR's waiting on libs-impl](https://github.com/rust-lang/rust/pulls?q=is%3Aopen+is%3Apr+label%3AS-waiting-on-team+label%3Alibs-impl)
     - Explicitly nominate any that you think may be able to be resolved *quickly* in triage meeting.
 
 ### Issues
 
-{prs_waiting_on_team.libs_impl}
+- {prs_waiting_on_team.libs_impl}

+ 3 - 3
templates/regressions.tt

@@ -7,7 +7,7 @@
 
 ### Issues
 
-{regressions.stable_to_beta}
+- {regressions.stable_to_beta}
 
 2. [Nightly regressions without P-label](https://github.com/rust-lang/rust/issues?q=is%3Aopen+label%3Aregression-from-stable-to-nightly+-label%3AP-critical+-label%3AP-high+-label%3AP-medium+-label%3AP-low+-label%3AT-infra+-label%3AT-release)
     - Prioritize.
@@ -16,7 +16,7 @@
 
 ### Issues
 
-{regressions.stable_to_nightly}
+- {regressions.stable_to_nightly}
 
 3. [Stable regressions without P-label](https://github.com/rust-lang/rust/issues?q=is%3Aopen+label%3Aregression-from-stable-to-stable+-label%3AP-critical+-label%3AP-high+-label%3AP-medium+-label%3AP-low+-label%3AT-infra+-label%3AT-release)
     - Prioritize (once we have this under control).
@@ -25,4 +25,4 @@
 
 ### Issues
 
-{regressions.stable_to_stable}
+- {regressions.stable_to_stable}

+ 3 - 3
templates/unpri_i_prioritize.tt

@@ -6,7 +6,7 @@
 
 ### Issues
 
-{unpri_i_prioritize.all}
+- {unpri_i_prioritize.all}
 
 2. [T-compiler](https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AT-compiler+-label%3AP-critical+-label%3AP-high+-label%3AP-medium+-label%3AP-low+label%3AI-prioritize)
     - Prioritize issues and remove nomination of the ones not worth discussing.
@@ -15,7 +15,7 @@
 
 ### Issues
 
-{unpri_i_prioritize.t_compiler}
+- {unpri_i_prioritize.t_compiler}
 
 3. [libs-impl](https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3Alibs-impl+-label%3AP-critical+-label%3AP-high+-label%3AP-medium+-label%3AP-low+label%3AI-prioritize)
     - Prioritize issues and remove nomination of the ones not worth discussing.
@@ -24,4 +24,4 @@
 
 ### Issues
 
-{unpri_i_prioritize.libs_impl}
+- {unpri_i_prioritize.libs_impl}