Skip to content

Commit

Permalink
Warn people not to edit the generated README.md. Improve the placehol…
Browse files Browse the repository at this point in the history
…der handling.
  • Loading branch information
ssorj committed Feb 25, 2024
1 parent ad9ffe6 commit 67841cc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 32 deletions.
10 changes: 2 additions & 8 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- NOTE: This file is generated from skewer.yaml. Do not edit it directly. -->

# Skupper Hello World

[![main](https://github.com/skupperproject/skewer/actions/workflows/main.yaml/badge.svg)](https://github.com/skupperproject/skewer/actions/workflows/main.yaml)
Expand Down Expand Up @@ -32,12 +34,10 @@ across cloud providers, data centers, and edge sites.

An overview


## Prerequisites

Some prerequisites


## Step 1: Install the Skupper command-line tool

This example uses the Skupper command-line tool to deploy Skupper.
Expand Down Expand Up @@ -249,7 +249,6 @@ _**West:**_

~~~ shell
if [ -n "${SKEWER_FAIL}" ]; then expr 1 / 0; fi

~~~

## Step 7: Expose the backend
Expand Down Expand Up @@ -323,7 +322,6 @@ navigating to `http://<external-ip>:8080/` in your browser.
To remove Skupper and the other resources from this exercise, use
the following commands:


And more!

_**West:**_
Expand All @@ -343,18 +341,14 @@ kubectl delete deployment/backend

## Summary



More summary


## Next steps

Check out the other [examples][examples] on the Skupper website.

More steps


## About this example

This example was produced using [Skewer][skewer], a library for
Expand Down
46 changes: 22 additions & 24 deletions python/skewer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ def append_section(heading, text):
out.append(text)
out.append("")

out.append("<!-- NOTE: This file is generated from skewer.yaml. Do not edit it directly. -->")
out.append("")

out.append(f"# {model.title}")
out.append("")

Expand Down Expand Up @@ -427,23 +430,22 @@ def apply_standard_steps(model):
del step.data["standard"]

def apply_attribute(name, default=None):
value = standard_step_data.get(name, default)
standard_value = standard_step_data.get(name, default)
value = step.data.get(name, standard_value)

if is_string(value):
if standard_value is not None:
value = value.replace("@default@", str(nvl(standard_value, "")).strip())

if name in step.data:
if name in ("title", "preamble", "postamble"):
if value:
step.data[name] = step.data[name].replace("@default@", value)
else:
step.data[name] = step.data[name].replace("@default@", "")
else:
if value and name in ("title", "preamble", "postamble"):
for i, site in enumerate([x for _, x in model.sites]):
value = value.replace(f"@site{i}@", site.title)
for i, site in enumerate([x for _, x in model.sites]):
value = value.replace(f"@site{i}@", site.title)

if site.namespace:
value = value.replace(f"@namespace{i}@", site.namespace)
if site.namespace:
value = value.replace(f"@namespace{i}@", site.namespace)

step.data[name] = value
value = value.strip()

step.data[name] = value

apply_attribute("name")
apply_attribute("title")
Expand Down Expand Up @@ -521,13 +523,9 @@ def object_property(name, default=None):
def get(obj):
value = obj.data.get(name, default)

try:
if default is None:
value = value.replace("@default@", "")
else:
value = value.replace("@default@", default)
except AttributeError:
pass
if is_string(value):
value = value.replace("@default@", str(nvl(default, "")).strip())
value = value.strip()

return value

Expand All @@ -550,10 +548,10 @@ class Model:
subtitle = object_property("subtitle")
workflow = object_property("workflow", "main.yaml")
overview = object_property("overview")
prerequisites = object_property("prerequisites", standard_text["prerequisites"].strip())
prerequisites = object_property("prerequisites", standard_text["prerequisites"])
summary = object_property("summary")
next_steps = object_property("next_steps", standard_text["next_steps"].strip())
about_this_example = object_property("about_this_example", standard_text["about_this_example"].strip())
next_steps = object_property("next_steps", standard_text["next_steps"])
about_this_example = object_property("about_this_example", standard_text["about_this_example"])

def __init__(self, skewer_file, kubeconfigs=[]):
self.skewer_file = skewer_file
Expand Down

0 comments on commit 67841cc

Please sign in to comment.