diff --git a/EXAMPLES.md b/EXAMPLES.md index c58c400..d844c08 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -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//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 `listwidget` 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 : `.()`\ +The lines `{% import '' as %}` is 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(...) }} ``` \ No newline at end of file diff --git a/README.md b/README.md index 7f76fc1..cfe330a 100644 --- a/README.md +++ b/README.md @@ -125,9 +125,6 @@ For each command, the option `-h` give u some help. `./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` - ## Others JFM-Engine is a friendly fork of [JSSG](https://github.com/jtremesay/jssg/) made in agreement with the JSSG developer because of different goals. \ diff --git a/content/templates/jinja2/allwidgets.html b/content/templates/jinja2/allwidgets.html deleted file mode 100644 index 2757498..0000000 --- a/content/templates/jinja2/allwidgets.html +++ /dev/null @@ -1,301 +0,0 @@ -{% macro navbar( - CTA_LABEL="", - CTA_TARGET="", - CTA_URL="", - CHANGE_LANG_URL="", - CHANGE_LANG_FLAG_URL="", - CHANGE_LANG_ALT="" -) -%} - - - - -{% endmacro %} - - -{% macro page_block_h2_with_ul_content_and_image_left( - IMAGE_URL = '', - TITLE = '', - CONTENT_ITEMS = [], - CTA_URL = '', - CTA_LABEL = '' -) -%} - -
-
-
-
-
-
-

{{ TITLE|safe }}

-

-

    {% for ITEM in CONTENT_ITEMS %} -
  • {{ ITEM | safe }}
  • {% endfor %}
-

-

{{ CTA_LABEL }}

-
-
- -{% endmacro %} -{% macro page_block_h2_with_content_and_primary_secondary_cta( - HTMLID="", - TITLE="", - CONTENT="", - MAIN_IMG_URL="", - MAIN_IMG_ALT="", - SECONDARY_CTA_URL="", - SECONDARY_CTA_TARGET="", - SECONDARY_CTA_LABEL="", - PRIMARY_CTA_URL="", - PRIMARY_CTA_TARGET="", - PRIMARY_CTA_LABEL="", - PRIMARY_CTA_ICON="" - ) -%} - -
-
-

{{ TITLE|safe }}

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

- {{ PRIMARY_TITLE|safe }} -

- {% if SECONDARY_TITLE %} -

{{ SECONDARY_TITLE|safe }}

- {% endif %} - {% if THIRD_TITLE %} - - {% endif %} -
-
-
-
-
- -{% endmacro %} -{% macro page_section_reference_logos( - REFERENCES = [] - ) -%} - - -
-
-
-
-

Plus de 200 clients nous font déjà confiance, pourquoi pas vous ?

-
-
- -
-
- {% for reference in REFERENCES %} - ils utilisent le service email galae: {{ reference.name }} - {% endfor %} -
-
-
-
- -{% endmacro %} -{% macro page_block_h2_with_ul_content_and_image_right( - IMAGE_URL = '', - TITLE = '', - CONTENT_ITEMS = [], - CTA_URL = '', - CTA_LABEL = '' -) -%} - -
-
-
-
-
-
-

{{ TITLE|safe }}

-

-

    {% for ITEM in CONTENT_ITEMS %} -
  • {{ ITEM | safe }}
  • {% endfor %}
-

-

{{ CTA_LABEL }}

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

Ce qu'en disent nos clients ...

-
- {% for reference in PERSONS %} -
-
- -
{{reference.name}}
-
{{reference.job}}
-

- « {{reference.testimonial|safe}} » -

-
-
- {% endfor %} -
-
-
- -{% endmacro %} -{% macro testimonials( - PERSONS = [] - ) -%} - - -
-
- -
- {% for reference in PERSONS %} -
-
-
- -
{{ reference.name }}
-
{{ reference.job }}
- {% for text in reference.testimonial %} -

- {{ text|safe }} -

- {% endfor %} -
-
-
- {% endfor %} -
- - - -
-
- -{% endmacro %} -{% macro page_block_h2_with_content_dark_background_no_cta( - HTMLID = "", - TITLE = "", - CONTENT = "" -) -%} - -
-
-

{{ TITLE|safe }}

-
-
- {{ CONTENT|safe }} -
-
-
-
- -{% endmacro %} -{% macro page_section_main_cta( - HTMLID = "", - TITLE = "", - SUBTITLE = "", - SECONDARY_TITLE = "" -) -%} - - -
-
-
-
-

- {{ TITLE|safe }} -

- {{ SUBTITLE|safe }} -
-
-
-
-

- {{ SECONDARY_TITLE|safe }} -

-
-
-
-
- -{% endmacro %} diff --git a/galae-content/pages/fr-index.md b/galae-content/pages/fr-index.md index 32d738c..7f58129 100644 --- a/galae-content/pages/fr-index.md +++ b/galae-content/pages/fr-index.md @@ -26,7 +26,7 @@ og:locale fr --- BODY (last / third) --- -{{ widgets.page_section_reference_logos( +{{ page_section_reference_logos.page_section_reference_logos( REFERENCES = [ {'name': 'oslandia', 'logo_url': 'assets/img/references/oslandia.webp'}, @@ -70,7 +70,7 @@ og:locale fr
-{{ widgets.page_block_h2_with_ul_content_and_image_right( +{{ page_block_h2_with_ul_content_and_image_right.page_block_h2_with_ul_content_and_image_right( TITLE = " Des e-mails délivrés, @@ -89,7 +89,7 @@ og:locale fr ) }} -{{ widgets.page_block_h2_with_ul_content_and_image_left( +{{ page_block_h2_with_ul_content_and_image_left.page_block_h2_with_ul_content_and_image_left( TITLE = "Vos données en sécurité", IMAGE_URL = "assets/img/undraw_relaxation_re_ohkx.svg", CONTENT_ITEMS = @@ -104,7 +104,7 @@ og:locale fr ) }} -{{ widgets.page_block_h2_with_ul_content_and_image_right( +{{ page_block_h2_with_ul_content_and_image_right.page_block_h2_with_ul_content_and_image_right( TITLE = "Vous êtes autonomes, accompagnés et souverains.", IMAGE_URL = "assets/img/undraw_experts_re_i40h.svg", CONTENT_ITEMS = @@ -124,7 +124,7 @@ og:locale fr -{{ widgets.page_block_h2_with_content_and_primary_secondary_cta( +{{ page_block_h2_with_content_and_primary_secondary_cta.page_block_h2_with_content_and_primary_secondary_cta( HTMLID = "pricing", TITLE = "Offres et tarifs", CONTENT = "L'offre galae repose sur les 4 offres suivantes :", @@ -141,7 +141,7 @@ og:locale fr -{{ widgets.testimonials_quotes( +{{ testimonials_quotes.testimonials_quotes( PERSONS = [ { "name": "Dominique Hébert", "job": "Directeur du développement Educ'AT", "testimonial": "Je peux créer autant d'adresses email et d'alias que je veux.", "img_url": "assets/img/testimonials/educ-at--dominique-hebert.webp" }, @@ -153,7 +153,7 @@ og:locale fr -{{ widgets.page_block_h2_with_content_dark_background_no_cta( +{{ page_block_h2_with_content_dark_background_no_cta.page_block_h2_with_content_dark_background_no_cta( TITLE = "Pourquoi j'ai décidé de créer le service galae ?", CONTENT = " @@ -206,7 +206,7 @@ og:locale fr -{{ widgets.page_section_main_cta( +{{ page_section_main_cta.page_section_main_cta( HTMLID = "signup", TITLE = "Convaincus que vous avez besoin d'un email éthique facturé à l'usage ?", SUBTITLE = diff --git a/jssg/management/commands/distill-local.py b/jssg/management/commands/distill-local.py deleted file mode 100644 index e53be23..0000000 --- a/jssg/management/commands/distill-local.py +++ /dev/null @@ -1,9 +0,0 @@ -import importlib -DistilllocalCommand = importlib.import_module("django_distill.management.commands.distill-local").Command -from django.core.management import call_command - -#Override the default distill-local command to call the make-widget before it execute -class Command(DistilllocalCommand): - def handle(self, *args, **options): - call_command('make-widgets') - super(Command, self).handle(*args, **options) \ No newline at end of file diff --git a/jssg/management/commands/make-widgets.py b/jssg/management/commands/make-widgets.py deleted file mode 100644 index 2ada800..0000000 --- a/jssg/management/commands/make-widgets.py +++ /dev/null @@ -1,40 +0,0 @@ -from django.core.management.base import BaseCommand -from django.conf import settings -from jinja2 import Environment -from jinja2.nodes import Macro - -class Command(BaseCommand): - help = "Make a file which contains all widgets macros for easier import in templates and pages." - - def handle(self, *args, **options): - - path = settings.BASE_DIR / "content" / "templates" / "jinja2" / "allwidgets.html" - buf = "" - n = 0 - for template_dir in settings.JFME_TEMPLATES_DIRS : - for widget in (template_dir / "jinja2" / "widgets").rglob("*") : - if widget.is_file() : - with open(widget, "r") as w : - file_content = w.read() - for macro in Environment().parse(file_content).find_all(Macro) : - n += 1 - buf += file_content + "\n" - - if n == 0 : - self.stdout.write( - "0 widget macro written" - ) - else : - path.parent.mkdir(exist_ok=True, parents=True) - with open(path, "w+") as f : - f.write(buf) - if n == 1 : - self.stdout.write( - "1 widget macro written in %s" % - (path.relative_to(settings.BASE_DIR)) - ) - else : - self.stdout.write( - "%d widget macros written in %s" % - (n, path.relative_to(settings.BASE_DIR)) - ) \ No newline at end of file diff --git a/jssg/management/commands/runserver.py b/jssg/management/commands/runserver.py deleted file mode 100644 index 5113617..0000000 --- a/jssg/management/commands/runserver.py +++ /dev/null @@ -1,8 +0,0 @@ -from django.core.management.commands.runserver import Command as RunserverCommand -from django.core.management import call_command - -#Override the default runserver command to call the make-widget before it execute -class Command(RunserverCommand): - def inner_run(self, *args, **options): - call_command('make-widgets') - super(Command, self).inner_run(*args, **options) \ No newline at end of file diff --git a/jssg/models.py b/jssg/models.py index e8e5b15..e1a1aab 100644 --- a/jssg/models.py +++ b/jssg/models.py @@ -44,7 +44,7 @@ def __init__(self, content: str, **metadata: Mapping[str, str]) -> None: :param content: The content (body) of the document :param metadata: Associated metadata """ - self.body = "{% import 'allwidgets.html' as widgets %}\n" + content + self.body = self.make_imports() + content self.metadata = dict(metadata) self.path = metadata["path"] self.data = {} @@ -218,6 +218,15 @@ def load_glob( files += (p / dir).glob(glob) # print(files) return map(cls.load, files) + + @classmethod + def make_imports(cls) : + import_str = "" + for template_dir in settings.JFME_TEMPLATES_DIRS : + for widget in (template_dir / "jinja2" / "widgets").rglob("*") : + if widget.is_file() : + import_str += "{% " + "import '{}' as {}".format(widget.relative_to(template_dir / "jinja2"), widget.stem) + " %}\n" + return import_str class Page(Document):