-
-
Notifications
You must be signed in to change notification settings - Fork 400
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
NutritionScore Calculation Details HTML Template #3503
Conversation
Note for reviewers: @areeshatariq is working on using a template engine for the HTML code generated by Product Opener. Copying here Areeesha's message in #productopener on Slack: "I've opened a Pull request on HTML Template of Nutrition Score Calculation Details. Started with Nutrition Score as it was a more independent module. We used Template::Toolkit for this. What do you think of the approach and how the template looks?" |
lib/ProductOpener/Display.pm
Outdated
push @{$template_data_ref->{points_groups}}, $points_group_ref; | ||
} | ||
# Nutrition Score Calculation Template | ||
my $config = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my $config = { | |
my $config = { |
Also, aren't these config we can use for every template? Can't we put them outside of the sub?
That's a VERY good start, thank you @areeshatariq! The Template::Toolkit is not as usable as I would like, but it's a good enhancement. PROs:
CONs:
Questions:
shouldn't we compute a |
Yes we can insert comments that won't be rendered in the HTML
Yes, we did try to avoid as many conditions as we can to make the template easier to understand. I'll add this If Else to the back-end. Thank you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the minor issues highlighted, very good job!
That's a very good question @CharlesNepote . @areeshatariq changed it to: [% beverage_view %] It does make the template simpler, but we lost the connection to the string id in the .po file. That's another interesting question: should we try to put the calls to lang () to internationalize the strings in the template, or should we try to do all the calls to lang() in the Perl code. The next statement is interesting too: [% IF is_fat %] [% lang('nutriscore_proteins_is_added_fat') %] [% END %] We need the if statement because we don't want the to be generated in the Perl code. We could to the call to lang() in Perl though, and pass the translated message directly, in the "is_fat" variable (instead of just passing 0 or 1). [% IF is_fat %] [% is_fat %] [% END %] |
@CharlesNepote , @areeshatariq : there is a simple solution to that: rename the .tt file in .html :) (it's in the /templates/ directory so it's obvious it's a template). I just tried it, we have HTML highlighting in github: https://github.com/openfoodfacts/openfoodfacts-server/blob/areesha-stephane-wip/templates/nutrition_score.html and also in the text / code editors: |
I added github syntax highlighting as HTML for the templates (per suggestion from @stephanegigandet). If there's a better option than HTML, see here how to configure it. |
Thanks @Ban3 . We probably will have templates for dynamically generated JS code as well (and possibly CSS). So I think the simplest thing is just to rename the template so that they have extension of what we are generating. /templates/nutriscore.html (instead of .tt) |
AFAIK, it is usually recommended to not create JS/CSS on-the-fly, but to use techniques like unobtrusive JS and to use selectors efficiently. 🙂
The templates are not valid HTML/CSS/JS, so that working syntax highlighting basically depends on how forgiving the parser is. 🤷♂️ |
Description:
HTML Template has been created for Nutrition Score Calculation Details using Template::Toolkit
The template file is used for the presentation purpose only, while all the logic has been kept in /lib/ProductOpener/Display.pm
Related issues and discussion: #2416