Skip to content

Commit

Permalink
Correct .template-part behavior and expand on README.me.anne.template…
Browse files Browse the repository at this point in the history
…-part

These formatting rules were originally contributed in whatwg/fetch#1036 by yutakahirano and should be preserved (and spread!).

Additionally, ensure we don't keep reading the same .template-part file over and over as that gives funny results.

And finally make it so that --single doesn't checkout the main branch and pulls, as that is almost never what you want when selectively deploying changes.
  • Loading branch information
annevk committed Sep 27, 2023
1 parent a0aa919 commit 4a5bcc7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
27 changes: 27 additions & 0 deletions README.md.anne.template-part
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,30 @@ is not indented, but
is.

End tags may be included (if done consistently) and attributes may be quoted (using double quotes), though the prevalent theme is to omit end tags and not quote attributes (unless they contain a space).

Place one newline between paragraphs (including list elements). Place three newlines before `<h2>`, and two newlines before other headings. This does not apply when a nested heading follows the parent heading.
```html
<ul>
<li><p>Do not place a newline above.

<li><p>Place a newline above.
</ul>

<p>Place a newline above.


<h3>Place two newlines above.</h3>

<h4>Placing one newline is OK here.</h4>


<h4>Place two newlines above.</h4>
```
Use camel-case for variable names and "spaced" names for definitions, algorithms, etc.
```html
<p>A <a for=/>request</a> has an associated
<dfn export for=request id=concept-request-redirect-mode>redirect mode</dfn>,...
```
```html
<p>Let <var>redirectMode</var> be <var>request</var>'s <a for=request>redirect mode</a>.
```
28 changes: 16 additions & 12 deletions factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

OBSOLETE_FILES = [".travis.yml", "deploy_key.enc"]
TEMPLATES = {}
TEMPLATE_PARTS = {}
DB = json.loads(requests.get("https://github.com/whatwg/sg/raw/main/db.json").text)
FACTORY_DB = {}

Expand Down Expand Up @@ -31,11 +32,11 @@ def find_files_with_extension(extension, recurse=True):
return paths


def gather_templates():
templates = {}
for path in find_files_with_extension(".template"):
templates[path] = read_file(path)
return templates
def gather_files(extension):
files = {}
for path in find_files_with_extension(extension):
files[path] = read_file(path)
return files


def fill_templates(templates, variables):
Expand All @@ -44,7 +45,7 @@ def fill_templates(templates, variables):
output_name = template[:-len(".template")]
if output_name == "README.md":
if variables["readme"]:
templates[template] += "\n" + read_file("../spec-factory/{}".format(variables["readme"]))
templates[template] += "\n" + TEMPLATE_PARTS[variables["readme"]]
if os.path.isfile("READMEEND.md"):
templates[template] += "\n" + read_file("READMEEND.md")
output[output_name] = fill_template(templates[template], variables)
Expand Down Expand Up @@ -80,7 +81,7 @@ def fill_template(contents, variables):
return contents


def update_files(shortname, name):
def update_files(shortname, name, in_main=False):
os.chdir("../{}".format(shortname))

variables = {
Expand Down Expand Up @@ -108,8 +109,10 @@ def update_files(shortname, name):

files = fill_templates(TEMPLATES, variables)

subprocess.run(["git", "checkout", "main"], capture_output=True)
subprocess.run(["git", "pull"], capture_output=True)
if in_main:
subprocess.run(["git", "checkout", "main"], capture_output=True)
subprocess.run(["git", "pull"], capture_output=True)

for file in files:
if variables["only_these_templates"] and file not in variables["only_these_templates"]:
continue
Expand Down Expand Up @@ -142,17 +145,18 @@ def update_all_standards(create_prs = False):
for standard in workstream["standards"]:
shortname = href_to_shortname(standard["href"])

update_files(shortname, standard["name"])
update_files(shortname, standard["name"], True)

if create_prs:
create_pr(shortname)


def main():
global TEMPLATES, FACTORY_DB
global TEMPLATES, FACTORY_DB, TEMPLATE_PARTS

TEMPLATES = gather_templates()
TEMPLATES = gather_files(".template")
FACTORY_DB = json.loads(read_file("factory.json"))
TEMPLATE_PARTS = gather_files(".template-part")

parser = argparse.ArgumentParser()
parser.add_argument("--single", nargs=2, type=str, metavar=("<shortname>", "<h1>"), help="generate a single standard, e.g., --single xhr XMLHttpRequest")
Expand Down

0 comments on commit 4a5bcc7

Please sign in to comment.