Skip to content

Commit a2be3da

Browse files
committed
Add custom template to display minified code tabs
- Revert inject script to add minifiedCode/minifiedBundledCode as custom fields - Create custom document_body.html that extends embedded array display - Manually render code blocks for minified versions - Add buttons for minified tabs alongside default/bundled tabs - Include testcases display from code_and_testcases.html
1 parent a38969f commit a2be3da

File tree

2 files changed

+97
-17
lines changed

2 files changed

+97
-17
lines changed
Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,95 @@
11
{%- include dependencies.html data=include.data -%}
2-
{%- include code_and_testcases.html data=include.data -%}
2+
3+
<h2>Code</h2>
4+
5+
{%- comment -%}Build extended embedded array with minified versions{%- endcomment -%}
6+
{%- assign extended_embedded = include.data.embedded -%}
7+
8+
{%- if include.data.minifiedCode -%}
9+
{%- assign minified_obj = '{"name":"minified","code":"PLACEHOLDER"}' | parse_json -%}
10+
{%- assign extended_embedded = extended_embedded | push: minified_obj -%}
11+
{%- endif -%}
12+
13+
{%- if include.data.minifiedBundledCode -%}
14+
{%- assign minified_bundled_obj = '{"name":"minified + bundled","code":"PLACEHOLDER"}' | parse_json -%}
15+
{%- assign extended_embedded = extended_embedded | push: minified_bundled_obj -%}
16+
{%- endif -%}
17+
18+
{%- comment -%}Display code with tabs{%- endcomment -%}
19+
{%- if extended_embedded.size >= 1 -%}
20+
<div class="code">
21+
{%- for source in include.data.embedded -%}
22+
{%- assign codeBody = source.code -%}
23+
<pre class="hljs {% unless forloop.first %}disable{% endunless %}" id="code-body-{{forloop.index}}"><code class="language-{{include.data.pathExtension}}">{{ codeBody | xml_escape }}</code></pre>
24+
{%- endfor -%}
25+
26+
{%- if include.data.minifiedCode -%}
27+
{%- assign idx = include.data.embedded.size | plus: 1 -%}
28+
<pre class="hljs disable" id="code-body-{{idx}}"><code class="language-{{include.data.pathExtension}}">{{ include.data.minifiedCode | xml_escape }}</code></pre>
29+
{%- endif -%}
30+
31+
{%- if include.data.minifiedBundledCode -%}
32+
{%- assign idx = include.data.embedded.size -%}
33+
{%- if include.data.minifiedCode -%}{%- assign idx = idx | plus: 2 -%}{%- else -%}{%- assign idx = idx | plus: 1 -%}{%- endif -%}
34+
<pre class="hljs disable" id="code-body-{{idx}}"><code class="language-{{include.data.pathExtension}}">{{ include.data.minifiedBundledCode | xml_escape }}</code></pre>
35+
{%- endif -%}
36+
37+
<div class="btn-area">
38+
{%- assign total_tabs = include.data.embedded.size -%}
39+
{%- if include.data.minifiedCode -%}{%- assign total_tabs = total_tabs | plus: 1 -%}{%- endif -%}
40+
{%- if include.data.minifiedBundledCode -%}{%- assign total_tabs = total_tabs | plus: 1 -%}{%- endif -%}
41+
42+
{%- if total_tabs >= 2 -%}
43+
<div class="btn-group">
44+
{%- for source in include.data.embedded -%}
45+
<button type="button" class="code-btn code-toggle-btn {% if forloop.first %}selected{% endif %}" data-target="code-body-{{forloop.index}}">{{source.name}}</button>
46+
{%- endfor -%}
47+
48+
{%- if include.data.minifiedCode -%}
49+
{%- assign idx = include.data.embedded.size | plus: 1 -%}
50+
<button type="button" class="code-btn code-toggle-btn" data-target="code-body-{{idx}}">minified</button>
51+
{%- endif -%}
52+
53+
{%- if include.data.minifiedBundledCode -%}
54+
{%- assign idx = include.data.embedded.size -%}
55+
{%- if include.data.minifiedCode -%}{%- assign idx = idx | plus: 2 -%}{%- else -%}{%- assign idx = idx | plus: 1 -%}{%- endif -%}
56+
<button type="button" class="code-btn code-toggle-btn" data-target="code-body-{{idx}}">minified + bundled</button>
57+
{%- endif -%}
58+
</div>
59+
{%- endif -%}
60+
<div class="btn-group"><button type="button" class="code-btn code-copy-btn hint--top hint--always hint--disable" aria-label="Copied!">Copy</button></div>
61+
</div>
62+
</div>
63+
{%- else -%}
64+
<div style="height: 5em;">:x: <b>There is no code.</b></div>
65+
{%- endif -%}
66+
67+
{%- if include.data.testcases and include.data.testcases.size != 0 -%}
68+
<h2>Test cases</h2>
69+
<table class="testcases-table">
70+
<thead>
71+
<tr>
72+
<th class="col col1">Env</th>
73+
<th class="col col2">Name</th>
74+
<th class="col col3">Status</th>
75+
<th class="col col4">Elapsed</th>
76+
<th class="col col5">Memory</th>
77+
</tr>
78+
</thead>
79+
<tbody>
80+
{%- for case in include.data.testcases -%}
81+
<tr>
82+
<td class="col col1">{{ case.environment | xml_escape }}</td>
83+
<td class="col col2">{{ case.name | xml_escape }}</td>
84+
{%- if case.status == "AC" -%}
85+
<td class="col col3">{{ site.icons.TEST_ACCEPTED }}&nbsp;AC</td>
86+
{%- else -%}
87+
<td class="col col3">{{site.icons.TEST_WRONG_ANSWER}}&nbsp;{{ case.status | xml_escape }}</td>
88+
{%- endif -%}
89+
<td class="col col4">{{ case.elapsed | times: 1000 | round }} ms</td>
90+
<td class="col col5">{{ case.memory | round }} MB</td>
91+
</tr>
92+
{%- endfor -%}
93+
</tbody>
94+
</table>
95+
{%- endif -%}

.verify-helper/scripts/inject_minified_docs.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,13 @@ def inject_minified_to_markdown(markdown_file, minified_code=None, minified_bund
4747
if 'data' not in front_matter or not isinstance(front_matter['data'], dict):
4848
return False
4949

50-
# Ensure embedded array exists
51-
if 'embedded' not in front_matter['data']:
52-
return False
53-
54-
if not isinstance(front_matter['data']['embedded'], list):
55-
return False
56-
57-
# Add minified versions to the embedded array
50+
# Add minified code as custom fields (we'll display these in a custom template)
5851
if minified_code:
59-
front_matter['data']['embedded'].append({
60-
'name': 'minified',
61-
'code': minified_code
62-
})
52+
front_matter['data']['minifiedCode'] = minified_code
6353
updated = True
6454

6555
if minified_bundled_code:
66-
front_matter['data']['embedded'].append({
67-
'name': 'minified + bundled',
68-
'code': minified_bundled_code
69-
})
56+
front_matter['data']['minifiedBundledCode'] = minified_bundled_code
7057
updated = True
7158

7259
if not updated:

0 commit comments

Comments
 (0)