commit 44c21e670f35997af7d554da7814925109cc15b8 Author: Ben Ashton Date: Sat Sep 3 00:31:55 2022 -0600 Initial commit diff --git a/cli.js b/cli.js new file mode 100644 index 0000000..721f6c2 --- /dev/null +++ b/cli.js @@ -0,0 +1,24 @@ +import { TemplateEngine } from './index.js'; +import { basename } from 'node:path'; + +// Check arguments +if (process.argv.length !== 3) { + console.error(`Usage: node ${basename(process.argv[1])} filename`); + process.exit(1); +} +const fileName = process.argv[2]; + +const tp = new TemplateEngine(); + +let result; + +try { + result = await tp.render(fileName); +} catch (e) { + console.error(e.message); + process.exit(1); +} + +if (result) { + process.stdout.write(result); +} diff --git a/example_templates/everything.n0m b/example_templates/everything.n0m new file mode 100644 index 0000000..25d5d56 --- /dev/null +++ b/example_templates/everything.n0m @@ -0,0 +1,14 @@ +$ #!/bin/sh +$ title='My Website'; +$ dangerous='Unescaped'; + + + # This is a comment + + <% $title %> + + +

Welcome: <% $2 %>

+

+ + diff --git a/example_templates/inline_tags.n0m b/example_templates/inline_tags.n0m new file mode 100644 index 0000000..84f6688 --- /dev/null +++ b/example_templates/inline_tags.n0m @@ -0,0 +1,5 @@ +$ VAR1="So many cats!"; +

<% $VAR1 %>

+

+

<$% echo $VAR1 | cut -f 2 -d ' ' %>

+

<$!% echo $VAR1 | cut -f 2 -d ' ' %>

\ No newline at end of file diff --git a/example_templates/restaurants.n0m b/example_templates/restaurants.n0m new file mode 100644 index 0000000..1bd278a --- /dev/null +++ b/example_templates/restaurants.n0m @@ -0,0 +1,12 @@ +$ #!/bin/sh + + + Restaurants + +