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

Find widgets by introspection #44

Merged
merged 8 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,26 @@ And finally we can use this blocks with :
```

# Exemple for automatic widget inclusion
Let's assume we have 3 macros widgets : `navbar()` in `widgets/menu.html`, `header()` and `footer()` in `widgets/page.html`.

First you can verify that all widgets are found with the `listwidget` command.\
Then the `makewidget` command will create a file `content/templates/<engine>/allwidgets.html`, that groups all the widgets found, and is automatically imported as `widgets` in all pages.\
First you can verify that all widgets are found with the `list-widget` command :
```shell
$ ./manage.py list-widgets
0 django widget found

The line `{% import 'allwidgets.html' as widgets %}` is added at the beginning of each `Body` section of pages.

For instance, if we have 3 widgets : `navbar.html`, `header.html` and `footer.html` we can use them in pages :
content/templates/jinja2/widgets/menu.html
navbar()
content/templates/jinja2/widgets/page.html
footer()
header()
2 jinja2 widget files found (3 macros)
```
All the listed widgets are automatically imported in all pages and can be accessed by : `<filename>.<macroname>()`\
The lines `{% import '<widget-file-path>' as <widget-file-name> %}` are added at the beginning of each `Body` section of pages.

We can use our widgets in pages with :
```jinja
{{ widgets.navbar(...) }}
{{ widgets.header(...) }}
{{ widgets.footer(...) }}
{{ menu.navbar(...) }}
{{ page.header(...) }}
{{ page.footer(...) }}
```
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ For each command, the option `-h` give u some help.

`./manage.py distill-local` to make the static website, see [Prod](#prod) for usage

`./manage.py list-widgets` to list all widgets found in content directories

`./manage.py make-widgets` to make a file that groups all jinja2 widgets macros for easier includes. It is automatically called by `runserver` and `distill-local` commands. \
See an example in `EXAMPLE.md`
`./manage.py list-widgets` to list all widgets found in content directories. See an example in `EXAMPLES.md`.

`./manage.py format-html <action>` to minify or beautify the html content (`<action>` being `minify` or `beautify`)

Expand Down
202 changes: 202 additions & 0 deletions common-content/templates/jinja2/widgets/generic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
{% macro navbar(
CTA_LABEL="",
CTA_TARGET="",
CTA_URL="",
CHANGE_LANG_URL="",
CHANGE_LANG_FLAG_URL="",
CHANGE_LANG_ALT=""
)
%}

<!-- Navigation-->
<nav class="navbar navbar-light bg-light static-top">
<div class="container">
<a class="navbar-brand" href="#">
<img class="navbar__logo__image" src="{{ static('assets/logo-galae.svg')}}"
alt="galae"/>
<div class="navbar__logo__label">le service e-mail qui vous veut du bien</div>
</a>
<div class="navbar__container__right">
<a class="btn btn-sm btn-primary" href="{{ CTA_URL }}"
target="{{ CTA_TARGET }}">{{ CTA_LABEL }}</a>
<a href="{{ url_for_slug_path(CHANGE_LANG_URL) }}">
<img class="languageFlag" src="{{ static(CHANGE_LANG_FLAG_URL)}}" alt="{{ CHANGE_LANG_ALT }}"/>
</a>
</div>
</div>
</nav>

{% endmacro %}




{% macro page_header(
PRIMARY_TITLE="",
SECONDARY_TITLE="",
THIRD_TITLE=""
)
%}

<!-- Masthead-->
<header class="masthead">
<div class="container position-relative">
<div class="row justify-content-center">
<div class="col-xl-9">
<div class="text-center text-white">
<!-- Page heading-->
<h1 class="mb-5">
{{ PRIMARY_TITLE|safe }}
</h1>
{% if SECONDARY_TITLE %}
<h2>{{ SECONDARY_TITLE|safe }}</h2>
{% endif %}
{% if THIRD_TITLE %}
<h3 class="navbar__logo__label"><i>{{ THIRD_TITLE|safe }}</i></h3>
{% endif %}
</div>
</div>
</div>
</div>
</header>

{% endmacro %}




{% macro page_section_main_cta(
HTMLID = "",
TITLE = "",
SUBTITLE = "",
SECONDARY_TITLE = ""
)
%}

<!-- Call to Action-->
<section class="call-to-action text-white text-center" id="{{ HTMLID }}">
<div class="container position-relative">
<div class="row justify-content-center">
<div class="col-xl-6">
<h2 class="mb-4">
{{ TITLE|safe }}
</h2>
{{ SUBTITLE|safe }}
</div>
</div>
<div class="row justify-content-center">
<div class="col-xl-6">
<h3 class="mb-4">
{{ SECONDARY_TITLE|safe }}
</h3>
</div>
</div>
</div>
</section>

{% endmacro %}




{% macro page_section_reference_logos(
REFERENCES = []
)
%}

<!-- Icons Grid -->
<section class="features-icons text-bg-light light text-center ">
<div class="container-fluid">
<div class="row mb-5">
<div class="col-12">
<h3>Plus de 200 clients nous font déjà confiance, pourquoi pas vous ?</h3>
</div>
</div>

<div class="row" title="ils nous font confiance">
<div class="col-lg-12">
{% for reference in REFERENCES %}
<img class="img-client-reference" src="{{ static(reference.logo_url) }}" alt="ils utilisent le service email galae: {{ reference.name }}"/>
{% endfor %}
</div>
</div>
</div>
</section>

{% endmacro %}




{% macro testimonials_quotes(
PERSONS = []
)
%}

<!-- Testimonials-->
<section class="testimonials text-center bg-light">
<div class="container">
<h2 class="mb-5">Ce qu'en disent nos clients ...</h2>
<div class="row">
{% for reference in PERSONS %}
<div class="col-lg-4">
<div class="testimonial-item mx-auto mb-5 mb-lg-0">
<img class="img-fluid rounded-circle mb-3" src="{{ static(reference.img_url)}}" alt="" />
<h5>{{reference.name}}</h5>
<h6>{{reference.job}}</h6>
<p class="font-weight-light mb-0">
«&nbsp;{{reference.testimonial|safe}}&nbsp;»
</p>
</div>
</div>
{% endfor %}
</div>
</div>
</section>

{% endmacro %}




{% macro testimonials(
PERSONS = []
)
%}

<!-- Testimonials-->
<section class="testimonials text-center bg-dark">
<div class="container">

<div class="row text-left">
{% for reference in PERSONS %}
<div class="col-md-12 col-sm-12 col-12 col-lg-6 col-xl-4 mb-4">
<div class="card testimonial-card">
<div class="card-body">
<img class="img-fluid rounded-circle mb-3" style="max-width: 8em; float:right;" src="{{ static(reference.img_url)}}" alt="" />
<h5 class="card-title">{{ reference.name }}</h5>
<h6 class="card-subtitle mb-2">{{ reference.job }}</h6>
{% for text in reference.testimonial %}
<p class="card-text lead">
{{ text|safe }}
</p>
{% endfor %}
</div>
</div>
</div>
{% endfor %}
</div>

<div class="row text-center">
<p class="col-12 mt-4">
<a href="https://pay.galae.net/" target="_blank" class="btn btn-primary btn-lg">
Je suis convaincu, je veux souscrire maintenant&nbsp;!
<i class="bi-rocket"></i>
</a>
</p>
</div>

</div>
</section>

{% endmacro %}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading