./mkshapes.sh
touch shapes
-shapes.html : shapes shapes.1 mkshhtml.sh shapes.2 html.html shapes.3 record.gif record2.gif sdlshapes.png
+shapes.html : shapes shapes.1 mkshhtml.py shapes.2 html.html shapes.3 record.gif record2.gif sdlshapes.png templates/shapes.html.j2
cat shapes.1 > shapes.html
- ./mkshhtml.sh >> shapes.html
+ ./mkshhtml.py < shapelist >> shapes.html
cat shapes.2 >> shapes.html
cat html.html >> shapes.html
cat shapes.3 >> shapes.html
(for s in $$(cat shapelist); do rm -f $$s.gif; done)
EXTRA_DIST = $(XGIF) mklang.y mkarrows.sh mkattrs.py mkshapes.sh mkstyles.sh mktapers.sh \
- mkarrowtbl.sh mkoutput.py mkshhtml.sh \
+ mkarrowtbl.sh mkoutput.py mkshhtml.py \
ps_to_png.sh arrow_grammar grammar html_grammar \
shapelist attrs.1 colors.1 colors.n \
output.1 output.2 html.1 html.2 html1.dot html.3 \
--- /dev/null
+#!/usr/bin/env python3
+
+from dataclasses import dataclass
+import jinja2
+import markupsafe
+import re
+import sys
+from typing import List, Dict
+
+N_PER_ROW=4
+
+shapes = []
+for line in sys.stdin:
+ shape = line.strip()
+ shapes.append(shape)
+
+# From https://stackoverflow.com/a/312464/171898
+def chunks(lst, n):
+ """Yield successive n-sized chunks from lst."""
+ for i in range(0, len(lst), n):
+ yield lst[i:i + n]
+
+# Use the shapes name in shape list to create the
+# contents of an HTML array.
+
+env = jinja2.Environment(
+ # Load template files from ./templates/
+ loader=jinja2.FileSystemLoader('templates'),
+ # Auto-HTML-escape any html or xml files.
+ autoescape=jinja2.select_autoescape(['html', 'xml', 'html.j2', 'xml.j2']),
+ # Whitespace control
+ trim_blocks=True,
+ lstrip_blocks=True,
+ # Raise exception on any attempt to access undefined variables.
+ undefined=jinja2.StrictUndefined,
+)
+template = env.get_template('shapes.html.j2')
+print(template.render(rows=chunks(shapes, N_PER_ROW)))
+++ /dev/null
-#! /bin/ksh
-typeset -i N_PER_ROW=4
-typeset -i cnt=0
-list=
-
-function doLine {
- echo " <TR ALIGN=CENTER>"
- for s in $@
- do
- echo " <TD><IMG SRC=$s.gif>"
- done
- echo " </TR>"
-
- echo " <TR ALIGN=CENTER>"
- for s in $@
- do
- echo " <TD><A NAME=d:$s>$s</A>"
- done
- echo " </TR>"
-}
-
-# Use the shapes name in shape list to create the
-# contents of an HTML array.
-
-for s in $(cat shapelist)
-do
- list=$list" $s"
- cnt=$(( $cnt + 1 ))
- if [[ $cnt = $N_PER_ROW ]]
- then
- doLine $list
- list=
- cnt=0
- fi
-done
-
-if [[ -n "$list" ]]
-then
- doLine $list
-fi
-
-exit 0
--- /dev/null
+{% for row in rows %}
+ <TR ALIGN=CENTER>
+ {% for shape in row %}
+ <TD><IMG SRC={{shape}}.gif>
+ {% endfor %}
+ </TR>
+ <TR ALIGN=CENTER>
+ {% for shape in row %}
+ <TD><A NAME=d:{{shape}}>{{shape}}</A>
+ {% endfor %}
+ </TR>
+{% endfor %}