Skip to content

Generator

Paramtamtam edited this page Jan 28, 2022 · 1 revision

Create a config file (error-pages.yml) with the following content:

templates:
  - path: ./foo.html # Template name "foo" (same as file name),
                     # content located in the file "foo.html"
  - name: bar # Template name "bar", its content is described below:
    content: "Error {{ code }}: {{ message }} ({{ description }})"

pages:
  400:
    message: Bad Request
    description: The server did not understand the request

  401:
    message: Unauthorized
    description: The requested page needs a username and a password

Template file foo.html:

<html>
<title>{{ code }}</title>
<body>
    <h1>{{ message }}: {{ description }}</h1>
</body>
</html>

And run the generator:

$ docker run --rm \
    -v "$(pwd):/opt:rw" \
    -u "$(id -u):$(id -g)" \
    tarampampam/error-pages build --config-file ./error-pages.yml ./out

$ tree
.
β”œβ”€β”€ error-pages.yml
β”œβ”€β”€ foo.html
└── out
    β”œβ”€β”€ bar
    β”‚   β”œβ”€β”€ 400.html
    β”‚   └── 401.html
    └── foo
        β”œβ”€β”€ 400.html
        └── 401.html

3 directories, 6 files

$ cat ./out/foo/400.html
<html>
<title>400</title>
<body>
    <h1>Bad Request: The server did not understand the request</h1>
</body>
</html>

$ cat ./out/bar/400.html
Error 400: Bad Request (The server did not understand the request)

To see the usage help run the following command:

$ docker run --rm tarampampam/error-pages build --help