Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Example of what the course would look like with the new renderer #1216

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

sakex
Copy link
Collaborator

@sakex sakex commented Sep 18, 2023

No description provided.

@sakex sakex changed the title [DRAFT] Example [DRAFT] Example of what the course would look like with the new renderer Sep 18, 2023
src/index.md Outdated Show resolved Hide resolved
book.toml Outdated Show resolved Hide resolved
book.toml Outdated Show resolved Hide resolved
@@ -0,0 +1,39 @@
{% import "Macros" as macros %}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Macros work (import the name defined in the book.toml and not the file name. You could name it with the file name too)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see! This is the difference in thinking: I was expecting the user to declare an include directory and then rely solely on the mechanisms in the template engine (import a file by it's relative path, for example).

I believe you've instead built more infrastructure to make it easier to use — but the problem with that is that the user now has to understand the custom logic here (and you and I have to document and maintain this).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to support both options, but to do use a macro like this in index.hbs, you will need to write sometimes 4 { in a row {{{{ attribute | get(key="style") }}}}, I find that very clunky, when using HTML syntax is pretty easy to understand for people already writing HTML.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might even have to write 6 in a row when I think about it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to support both options

Please don't: avoid building up your own vocabulary here since nobody but you will know about it 🙂 I would like us to have as little code to maintain as possible here.

<button id="language-toggle{{ counter }}" class="icon-button" type="button"
title="Change language" aria-label="Change language"
aria-haspopup="true" aria-expanded="false"
aria-controls="language-list{{ counter }}" style="{{ attributes | get(key="style", default="") }}">
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading attributes passed in HTML

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go away in a MVP — I would like to keep this super simple at first.

{% for identifier, language_name in get_context(key="output.i18n.languages") %}
<li role="none">
<a id="{{ identifier }}"
href="{{ macros::get_rendered_path(identifier=identifier) }}"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling the macro

href="{{ macros::get_rendered_path(identifier=identifier) }}"
style="color: inherit;">
<button role="menuitem" class="theme {% if identifier == language %} theme-selected {% endif %}">
{% include "Included" %} {{ language_name }}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include directive

@@ -0,0 +1,3 @@
{% macro get_rendered_path(identifier) %}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defining macro

theme/index.hbs Outdated
}
</script>

<LanguagePicker style="color: red;">
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<LanguagePicker /> syntax is not supported

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now tera syntax is not supported in index.hbs but I will add it later, it is going to look a bit ugly though.

<script>
let langToggle = document.getElementById("language-toggle{{ counter }}");
let langList = document.getElementById("language-list{{ counter }}");
{% raw %}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a raw block for the Javascript block

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but then I think the {{ below has a { too many?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's a mistake actually (from copy pasting the HBS one), but still valid JS

book.toml Outdated Show resolved Hide resolved
theme/head.hbs Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants