]> granicus.if.org Git - graphviz/commitdiff
Merge mktypes.py into mkattrs.html
authorMark Hansen <mark@markhansen.co.nz>
Mon, 1 Jun 2020 11:31:21 +0000 (21:31 +1000)
committerMark Hansen <mark@markhansen.co.nz>
Mon, 1 Jun 2020 11:31:21 +0000 (21:31 +1000)
Ultimately only one HTML page is generated.

This ensures the entire page is present in one template.

Verified there are no diffs in the output.

doc/infosrc/Makefile
doc/infosrc/mkattrs.py
doc/infosrc/mktypes.py [deleted file]
doc/infosrc/templates/attrs.html.j2
doc/infosrc/templates/types.html.j2 [deleted file]

index de0ebf3cf80d55a8e305c446897396ed04e16ac5..4625154bf69bf61e578da8cffc600b97be37f500 100644 (file)
@@ -11,7 +11,7 @@
 #  python is used to run:
 #  - jconvert.py, which converts the json schema graphviz_json_schema.json to html.
 #    This also relies on the python package json2html.
-#  - mkoutput.py, which converts templates/output.html to output.html
+#  - mkoutput.py, which converts templates/output.html.j2 to output.html
 #    This requires the jinja2 python package.
 #
 # The main product are 7 web pages:
@@ -119,9 +119,8 @@ sdlshapes.ps : sdlshapes.dot
 sdlshapes.png : sdlshapes.ps
        ./ps_to_png.sh sdlshapes.ps sdlshapes.png
 
-attrs.html : attrs types mkattrs.py mktypes.py templates/attrs.html.j2
-       ./mkattrs.py < attrs > $@
-       ./mktypes.py < types >> $@
+attrs.html : attrs types mkattrs.py templates/attrs.html.j2
+       ./mkattrs.py attrs types > $@
 
 colors.html : colors.1 colors.n ../../lib/common/color_names ../../lib/common/svgcolor_names ../../lib/common/brewer_colors mkcolors.awk brewer.awk svg.awk
        mkdir -p colortmp
@@ -216,7 +215,7 @@ distclean : clean
        (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 \
-             mktypes.py mkarrowtbl.sh mkoutput.py mkshhtml.sh \
+             mkarrowtbl.sh mkoutput.py mkshhtml.sh \
                   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 \
index 3d5b545ff1cbc6082469bb7c41e87350c482bc30..69801c8a3984506a7de6677be08ef9103515cb2a 100755 (executable)
@@ -1,9 +1,9 @@
 #!/usr/bin/env python3
-# Filter taking a list of attribute descriptions as stdin
-# and producing a summary table, followed by a list of
-# attribute descriptions.
-# Uses `templates/attrs.html.j2`
-# See `attrs` file for format documentation.
+# Generator taking a list of attribute descriptions as argv[1] and attribute
+# type descriptions as argv[2] and producing a summary table, followed by a
+# list of attribute descriptions and attribute types. Uses
+# `templates/attrs.html.j2`.
+# See `attrs` and `types` files for format documentation.
 
 from dataclasses import dataclass
 import jinja2
@@ -12,14 +12,20 @@ import re
 import sys
 from typing import List, Dict
 
+##
+# Parse `attrs` file
+##
+
+
 @dataclass
 class Term:
-  """ One <dt> item. """
-  name: str
-  # Anchor (<a name="#">) for definition
-  d_anchor: str = ""
-  # Anchor (<a name="#">) for table at the top
-  a_anchor: str = ""
+    """ One <dt> item. """
+    name: str
+    # Anchor (<a name="#">) for definition
+    d_anchor: str = ""
+    # Anchor (<a name="#">) for table at the top
+    a_anchor: str = ""
+
 
 @dataclass
 class Attribute:
@@ -32,65 +38,108 @@ class Attribute:
     defaults: List[str]
     minimums: List[str]
 
-attrs : List[Attribute] = []
-
-for line in sys.stdin:
-    # Skip comment lines.
-    if line.startswith('#'):
-        continue
-
-    if line.startswith(':'):
-        # This is a header line. Grab out the values.
-        #    :name:uses:kind[:dflt[:minv]];  [notes]
-        headers, _, flags = line.rpartition(';')
-        parts = headers.split(':')
-
-        attr = Attribute(
-            terms=[Term(name=name) for name in parts[1].split('/')],
-            uses=parts[2],
-            kinds=parts[3].split('/'),
-            flags=[flag for flag in flags.strip().split(',') if flag],
-            # Set an empty string html description, ready to append to.
-            html_description='',
-            # Remaining fields are optional.
-            # First, check for default value: this has format :dflt1[/dflt2]*
-            defaults=parts[4].split('/') if len(parts) >= 5 else [],
-            # Check for minimum value: this has format /min1[/min2]*
-            minimums=parts[5].split('/') if len(parts) >= 6 else [],
-        )
-        attrs.append(attr)
-
-    else:
-        # This is an HTML line, possibly a continuation of a previous HTML line.
-        attr.html_description += '  ' + line
+
+attrs: List[Attribute] = []
+
+with open(sys.argv[1]) as attrs_in:
+    for line in attrs_in:
+        # Skip comment lines.
+        if line.startswith('#'):
+            continue
+
+        if line.startswith(':'):
+            # This is a header line. Grab out the values.
+            #    :name:uses:kind[:dflt[:minv]];  [notes]
+            headers, _, flags = line.rpartition(';')
+            parts = headers.split(':')
+
+            attr = Attribute(
+                terms=[Term(name=name) for name in parts[1].split('/')],
+                uses=parts[2],
+                kinds=parts[3].split('/'),
+                flags=[flag for flag in flags.strip().split(',') if flag],
+                # Set an empty string html description, ready to append to.
+                html_description='',
+                # Remaining fields are optional.
+                # First, check for default value: this has format :dflt1[/dflt2]*
+                defaults=parts[4].split('/') if len(parts) >= 5 else [],
+                # Check for minimum value: this has format /min1[/min2]*
+                minimums=parts[5].split('/') if len(parts) >= 6 else [],
+            )
+            attrs.append(attr)
+
+        else:
+            # This is an HTML line, possibly a continuation of a previous HTML line.
+            attr.html_description += '  ' + line
 
 
 attrs.sort(key=lambda attr: ''.join(term.name for term in attr.terms))
 
 for attr in attrs:
-  attr.html_description = markupsafe.Markup(attr.html_description)
+    attr.html_description = markupsafe.Markup(attr.html_description)
 
 # The specification allows items with the same attribute name.
 # This creates unique anchor keys, which are n copies of 'a' and 'd'.
 a_anchors_used = set()
 d_anchors_used = set()
 for attr in attrs:
-  for term in attr.terms:
-    a_key = 'a'
-    d_key = 'd'
-    a_anchor = a_key + ':' + term.name
-    d_anchor = d_key + ':' + term.name
-    while a_anchor in a_anchors_used:
-      a_key += 'a'
-      a_anchor = a_key + ':' + term.name
-    while d_anchor in d_anchors_used:
-      d_key += 'd'
-      d_anchor = d_key + ':' + term.name
-    a_anchors_used.add(a_anchor)
-    d_anchors_used.add(d_anchor)
-    term.a_anchor = a_anchor
-    term.d_anchor = d_anchor
+    for term in attr.terms:
+        a_key = 'a'
+        d_key = 'd'
+        a_anchor = a_key + ':' + term.name
+        d_anchor = d_key + ':' + term.name
+        while a_anchor in a_anchors_used:
+            a_key += 'a'
+            a_anchor = a_key + ':' + term.name
+        while d_anchor in d_anchors_used:
+            d_key += 'd'
+            d_anchor = d_key + ':' + term.name
+        a_anchors_used.add(a_anchor)
+        d_anchors_used.add(d_anchor)
+        term.a_anchor = a_anchor
+        term.d_anchor = d_anchor
+
+##
+# Parse `types` file
+##
+
+
+@dataclass
+class Type:
+    name: str
+    html_description: str
+
+
+types: List[Type] = []
+
+with open(sys.argv[2]) as types_in:
+    for line in types_in:
+        # Skip comment lines.
+        if line.startswith('#'):
+            continue
+        if line.startswith(':'):
+            # This is a header line. Grab out the values.
+            types.append(Type(
+                name=line[1:].rstrip(),
+                html_description=''
+            ))
+        else:
+            # This is an HTML line, possibly a continuation of a previous HTML line.
+            t = types[-1]
+            # This is purely so the diffs look the same porting from ksh, could
+            # delete this later.
+            if t.html_description != '':
+                t.html_description += '  '
+            t.html_description += line
+
+types.sort(key=lambda t: t.name)
+
+for t in types:
+    t.html_description = markupsafe.Markup(t.html_description)
 
+##
+# Output HTML
+##
 
 env = jinja2.Environment(
     # Load template files from ./templates/
@@ -104,4 +153,4 @@ env = jinja2.Environment(
     undefined=jinja2.StrictUndefined,
 )
 template = env.get_template('attrs.html.j2')
-print(template.render(attrs=attrs))
+print(template.render(attrs=attrs, types=types))
diff --git a/doc/infosrc/mktypes.py b/doc/infosrc/mktypes.py
deleted file mode 100755 (executable)
index dac5651..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-#!/usr/bin/env python3
-from dataclasses import dataclass
-import jinja2
-import markupsafe
-import sys
-from typing import List
-
-
-@dataclass
-class Type:
-    name: str
-    html_description: str
-
-
-types: List[Type] = []
-
-for line in sys.stdin:
-    # Skip comment lines.
-    if line.startswith('#'):
-        continue
-    if line.startswith(':'):
-        # This is a header line. Grab out the values.
-        types.append(Type(
-            name=line[1:].rstrip(),
-            html_description=''
-        ))
-    else:
-        # This is an HTML line, possibly a continuation of a previous HTML line.
-        t = types[-1]
-        # This is purely so the diffs look the same porting from ksh, could
-        # delete this later.
-        if t.html_description != '':
-            t.html_description += '  '
-        t.html_description += line
-
-types.sort(key=lambda t: t.name)
-
-for t in types:
-    t.html_description = markupsafe.Markup(t.html_description)
-
-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('types.html.j2')
-print(template.render(
-    types=types,
-))
index 9135d24e65aed8b4dfcce26247e9fa3b2653c86d..ca4d20fe13483c9ecab5a874abd1781bde452ab8 100644 (file)
@@ -150,3 +150,19 @@ of the layout programs.
 {% endfor %}
 </DL>
 <HR>
+<H1>Attribute Type Descriptions</H1>
+The following list gives the legal strings corresponding to values of
+the given types.
+The syntax for describing legal type strings is a mixture of literal strings,
+stdio encodings (e.g., <TT>%f</TT> for a double), and regular expressions.
+For regular expressions, <TT>(...)*</TT> indicates 0 or more copies of the expression
+enclosed in the parentheses,  <TT>(...)+</TT> indicates 1 or more, and
+<TT>(...)?</TT> denotes 0 or 1 copy.
+<DL>
+{% for t in types %}
+<DT><A NAME=k:{{t.name}}><STRONG>{{t.name}}</STRONG></A>
+<DD>{{t.html_description}}
+{% endfor %}
+</DL>
+</BODY>
+</HTML>
diff --git a/doc/infosrc/templates/types.html.j2 b/doc/infosrc/templates/types.html.j2
deleted file mode 100644 (file)
index bb06f0b..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<H1>Attribute Type Descriptions</H1>
-The following list gives the legal strings corresponding to values of
-the given types.
-The syntax for describing legal type strings is a mixture of literal strings,
-stdio encodings (e.g., <TT>%f</TT> for a double), and regular expressions.
-For regular expressions, <TT>(...)*</TT> indicates 0 or more copies of the expression
-enclosed in the parentheses,  <TT>(...)+</TT> indicates 1 or more, and
-<TT>(...)?</TT> denotes 0 or 1 copy.
-<DL>
-{% for t in types %}
-<DT><A NAME=k:{{t.name}}><STRONG>{{t.name}}</STRONG></A>
-<DD>{{t.html_description}}
-{% endfor %}
-</DL>
-</BODY>
-</HTML>