Skip to content

Commit e4eee9f

Browse files
authored
Rework file naming for csv-report (#134)
1 parent 46a04f6 commit e4eee9f

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

src/csv/csv_report.html.tera

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<script src="../data/index{{ current_page }}.js"></script>
2020
<script src="../js/csv_report.js"></script>
2121
{% for title in titles %}
22-
<script src="../plots/{{ title }}.js"></script>
22+
<script src="../plots/plot_{{ loop.index0 }}.js"></script>
2323
{% endfor %}
2424
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
2525
<a class="navbar-brand" href="#">rbt report</a>
@@ -64,7 +64,7 @@
6464
<tr>
6565
{% for title in titles %}
6666
<th style="white-space: nowrap;">{{ title }}
67-
<a class="sym" data-toggle="modal" data-target="#{{ title }}" onclick="vegaEmbed('#{{ title }}_plot', {{ title }}_plot)">
67+
<a class="sym" data-toggle="modal" data-target="#{{ title }}" onclick="vegaEmbed('#plot_{{ loop.index0 }}', plot_{{ loop.index0 }})">
6868
<svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-bar-chart-fill" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
6969
<rect width="4" height="5" x="1" y="10" rx="1"/>
7070
<rect width="4" height="9" x="6" y="6" rx="1"/>
@@ -125,7 +125,7 @@
125125
</button>
126126
</div>
127127
<div class="modal-body">
128-
<div id="{{ title }}_plot" style="width: 100%; height: 300px; border:none;">
128+
<div id="plot_{{ loop.index0 }}" style="width: 100%; height: 300px; border:none;">
129129
</div>
130130
</div>
131131
<div class="modal-footer">
@@ -144,7 +144,7 @@
144144
</button>
145145
</div>
146146
<div class="modal-body">
147-
<iframe src="../prefixes/{{ title }}.html" frameBorder="0" style="width: 100%; height: min(530px, 50vh)"></iframe>
147+
<iframe src="../prefixes/col_{{ loop.index0 }}.html" frameBorder="0" style="width: 100%; height: min(530px, 50vh)"></iframe>
148148
</div>
149149
<div class="modal-footer">
150150
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>

src/csv/lookup_table.html.tera

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</tbody>
3232
</table>
3333
</div>
34-
<div class="col-3 ml-auto" style="padding-top: 10px"><a role="button" href="../{{ title }}.html" class="btn btn-primary">Back</a></div>
34+
<div class="col-3 ml-auto" style="padding-top: 10px"><a role="button" href="../col_{{ index }}.html" class="btn btn-primary">Back</a></div>
3535
</div>
3636
</div>
3737
</body>

src/csv/plot.js.tera

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let {{ title }}_plot = {
1+
let plot_{{ index }} = {
22
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
33
"data": {"values": {{ table }}},
44
"width": "container",
@@ -19,4 +19,4 @@ let {{ title }}_plot = {
1919
{% endif %}
2020
"y": {"field": "value", "type": "quantitative", "title": null}
2121
}
22-
}
22+
}

src/csv/prefix_table.html.tera

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<tbody>
2424
{% for prefix, v in table %}
2525
<tr>
26-
<td><a href="{{ title }}/{{ prefix }}.html" style="display: table-cell">{{ prefix }}</a></td>
26+
<td><a href="col_{{ index }}/{{ prefix }}.html" style="display: table-cell">{{ prefix }}</a></td>
2727
</tr>
2828
{% endfor %}
2929
</tbody>

src/csv/report.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub(crate) fn csv_report(
154154
dir_path: plot_path.to_owned(),
155155
})?;
156156

157-
for title in &titles {
157+
for (n, title) in titles.iter().enumerate() {
158158
let mut templates = Tera::default();
159159
templates.add_raw_template("plot.js.tera", include_str!("plot.js.tera"))?;
160160
let mut context = Context::new();
@@ -173,9 +173,10 @@ pub(crate) fn csv_report(
173173
_ => unreachable!(),
174174
}
175175
context.insert("title", &title);
176+
context.insert("index", &n.to_string());
176177
let js = templates.render("plot.js.tera", &context)?;
177178

178-
let file_path = plot_path.to_owned() + title + ".js";
179+
let file_path = plot_path.to_owned() + "plot_" + &n.to_string() + ".js";
179180
let mut file = fs::File::create(file_path)?;
180181
file.write_all(js.as_bytes())?;
181182
}
@@ -255,7 +256,7 @@ pub(crate) fn csv_report(
255256
dir_path: prefix_path.to_owned(),
256257
})?;
257258

258-
for title in &titles {
259+
for (n, title) in titles.iter().enumerate() {
259260
if let Some(prefix_table) = prefixes.get(title.to_owned()) {
260261
let mut templates = Tera::default();
261262
templates.add_raw_template(
@@ -264,15 +265,16 @@ pub(crate) fn csv_report(
264265
)?;
265266
let mut context = Context::new();
266267
context.insert("title", title);
268+
context.insert("index", &n.to_string());
267269
context.insert("table", prefix_table);
268270
context.insert("numeric", is_numeric.get(title).unwrap());
269271
let html = templates.render("prefix_table.html.tera", &context)?;
270272

271-
let file_path = output_path.to_owned() + "/prefixes/" + title + ".html";
273+
let file_path = output_path.to_owned() + "/prefixes/col_" + &n.to_string() + ".html";
272274
let mut file = fs::File::create(file_path)?;
273275
file.write_all(html.as_bytes())?;
274276

275-
let title_path = prefix_path.to_owned() + "/" + title + "/";
277+
let title_path = prefix_path.to_owned() + "/col_" + &n.to_string() + "/";
276278
fs::create_dir(Path::new(&title_path)).context(WriteErr::CantCreateDir {
277279
dir_path: title_path.to_owned(),
278280
})?;
@@ -286,6 +288,7 @@ pub(crate) fn csv_report(
286288
let mut context = Context::new();
287289
context.insert("title", title);
288290
context.insert("values", values);
291+
context.insert("index", &n.to_string());
289292
let html = templates.render("lookup_table.html.tera", &context)?;
290293

291294
let file_path = title_path.to_owned() + prefix + ".html";

0 commit comments

Comments
 (0)