Skip to content

Commit

Permalink
Bumped needed version to 0.4.0. Updated install.cfg to newer version.…
Browse files Browse the repository at this point in the history
… Added raise macro support.
  • Loading branch information
WyvernIXTL committed Jun 23, 2024
1 parent 441f04f commit d3c4ad3
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 39 deletions.
82 changes: 46 additions & 36 deletions install.cfg
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
$schema: https://json-schema.org/draft/2020-12/schema
$id: https://github.com/instructions-d-installation/web-installation-instruction/install.cfg
title: Hello World
description: Hello World Example for Web Installation Instructions
type: object
$comment: by Adam McKellar
properties:
mynum:
type: number
title: My Number
description: A number to be echoed back.
default: 2024
mystr:
type: string
title: My String
description: A string to be echoed back.
default: "Hello World! We have "
mybool:
type: boolean
title: Show Extras
description: Check this if you want to see a helicopter.
default: true
mychoice:
title: Position
description: Where do you want the helicopter?
anyOf:
- title: Flying
const: flying
description: The helicopter will be flying.
- title: Landed
const: landed
description: The helicopter will be landed.
- title: Distant
const: distant
description: The helicopter is far away.
default: landed
schema:
$schema: https://json-schema.org/draft/2020-12/schema
$id: https://github.com/instructions-d-installation/web-installation-instruction/install.cfg
title: Hello World
description: Hello World Example for Web Installation Instructions
type: object
$comment: by Adam McKellar
properties:
mynum:
type: number
title: My Number
description: A number to be echoed back.
default: 2024
mystr:
type: string
title: My String
description: A string to be echoed back.
default: "Hello World! We have "
mybool:
type: boolean
title: Show Extras
description: Check this if you want to see a helicopter.
default: true
mychoice:
title: Position
description: Where do you want the helicopter?
enum:
- flying
- landed
- distant
- hidden
default: landed

pretty:
flying: Flying
landed: Landed
distant: Distant
hidden: Hidden

description:
flying: The helicopter will be flying.
landed: The helicopter will be landed.
distant: The helicopter is far away.
hidden: The helicopter is hidden.

------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -136,5 +144,7 @@ properties:
∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞√√√√√√√√√√√√√√√∞√√√√√√√√π√√π
∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞√∞∞√∞√√√∞∞√ππππ
{% endraw %}
{% else %}
{{ raise("Ups, this is an error message from within the template!") }}
{% endif %}
{% endif %}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ classifiers = [
dependencies = [
"jinja2",
"typer",
"installation-instruction == 0.3.0"
"installation-instruction >= 0.4.0"
]
[project.scripts]
ibi-build-html = "web_installation_instruction.__main__:run_cli"
19 changes: 17 additions & 2 deletions src/web_installation_instruction/template/index.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<Code id="output"></Code>
</pre>
</div>
<button class="secondary" onclick="copy_to_clipboard()" style="width: 100%;">Copy</button>
<button id="copybtn" class="secondary" onclick="copy_to_clipboard()" style="width: 100%;">Copy</button>

</main>
<footer class="container">
Expand All @@ -98,7 +98,13 @@
nunjucks.configure({ autoescape: true, trimBlocks: true, lstripBlocks: true });
nunjucks.installJinjaCompat()
let template = nunjucks.compile(`{{ __web_template__ }}`);
const raise_regex = /\[\[ERROR\]\](.*?)\[\[\/ERROR\]\]/g;
{% raw %}
const raise_macro = "{% macro raise(error) %} [[ERROR]]{{ error }}[[/ERROR]] {% endmacro %}";
{% endraw %}
let template = nunjucks.compile(raise_macro + `{{ __web_template__ }}`);
let default_input = structuredClone(input);
Expand All @@ -117,7 +123,16 @@
input.set(key, val);
}
output = template.render(Object.fromEntries(input.entries()));
let errmsg = raise_regex.exec(output)?.[1];
output = errmsg || output;
document.getElementById("output").innerHTML = output;
let copy_btn = document.getElementById("copybtn");
if (errmsg) {
copy_btn.setAttribute("disabled", "disabled");
} else {
copy_btn.removeAttribute("disabled");
}
}
function copy_to_clipboard() {
Expand Down

0 comments on commit d3c4ad3

Please sign in to comment.