Added readme
This commit is contained in:
parent
44c21e670f
commit
3920478d6b
96
README.md
Normal file
96
README.md
Normal file
@ -0,0 +1,96 @@
|
||||
|
||||
# Template Engine
|
||||
|
||||
A shell script template engine for generating scripts that render HTML markup,
|
||||
or anything really.
|
||||
|
||||
## Examples
|
||||
|
||||
```html
|
||||
$ #!/bin/sh
|
||||
$ title='My Restaurant Randomizer';
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title><% $title %></title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to <% $title %></h1>
|
||||
<p>From the following restaurants:</p>
|
||||
<ul>
|
||||
$ while read restaurant; do
|
||||
<li><% $restaurant %></li>
|
||||
$ done <restaurants.txt
|
||||
</ul>
|
||||
<p>
|
||||
The fates have decided that you shall eat at:
|
||||
<strong><$% shuf -n 1 restaurants.txt %></strong>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
The above template will generate the following shell script:
|
||||
|
||||
```bash
|
||||
#!/bin/sh
|
||||
title='My Restaurant Randomizer';
|
||||
printf '%s\n' '<!doctype html>';
|
||||
printf '%s\n' '<html>';
|
||||
printf '%s\n' ' <head>';
|
||||
printf '%s' ' <title>';
|
||||
printf '%s' "$title" | jq -Rrj @html;
|
||||
printf '%s\n' '</title>';
|
||||
printf '%s\n' ' </head>';
|
||||
printf '%s\n' ' <body>';
|
||||
printf '%s' ' <h1>Welcome to ';
|
||||
printf '%s' "$title" | jq -Rrj @html;
|
||||
printf '%s\n' '</h1>';
|
||||
printf '%s\n' ' <p>From the following restaurants:</p>';
|
||||
printf '%s\n' ' <ul>';
|
||||
printf '%s' '';
|
||||
while read restaurant; do
|
||||
printf '%s' ' <li>';
|
||||
printf '%s' "$restaurant" | jq -Rrj @html;
|
||||
printf '%s\n' '</li>';
|
||||
printf '%s' '';
|
||||
done <restaurants.txt
|
||||
printf '%s\n' ' </ul>';
|
||||
printf '%s\n' ' <p>';
|
||||
printf '%s\n' ' The fates have decided that you shall eat at:';
|
||||
printf '%s' ' <strong>';
|
||||
printf '%s' "$(shuf -n 1 restaurants.txt)" | jq -Rrj @html;
|
||||
printf '%s\n' '</strong>';
|
||||
printf '%s\n' ' </p>';
|
||||
printf '%s\n' ' </body>';
|
||||
printf '%s\n' '</html>';
|
||||
printf '%s' '';
|
||||
```
|
||||
|
||||
Which when executed might products the following HTML:
|
||||
|
||||
```html
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>My Restaurant Randomizer</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to My Restaurant Randomizer</h1>
|
||||
<p>From the following restaurants:</p>
|
||||
<ul>
|
||||
<li>Luigi's</li>
|
||||
<li>Papa Johns</li>
|
||||
<li>SushiQ</li>
|
||||
</ul>
|
||||
<p>
|
||||
The fates have decided that you shall eat at:
|
||||
<strong>Papa Johns</strong>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
## License
|
||||
|
||||
[MIT](https://choosealicense.com/licenses/mit/)
|
||||
|
21
example_templates/readme_example.n0m
Normal file
21
example_templates/readme_example.n0m
Normal file
@ -0,0 +1,21 @@
|
||||
$ #!/bin/sh
|
||||
$ title='My Restaurant Randomizer';
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title><% $title %></title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to <% $title %></h1>
|
||||
<p>From the following restaurants:</p>
|
||||
<ul>
|
||||
$ while read restaurant; do
|
||||
<li><% $restaurant %></li>
|
||||
$ done <restaurants.txt
|
||||
</ul>
|
||||
<p>
|
||||
The fates have decided that you shall eat at:
|
||||
<strong><$% shuf -n 1 restaurants.txt %></strong>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
@ -8,6 +8,6 @@
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"license": "MIT",
|
||||
"type": "module"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user