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

Introduce Pebble template engine as faster & more feature rich alternative #7

Open
pun-ky opened this issue Jan 10, 2019 · 2 comments

Comments

@pun-ky
Copy link

pun-ky commented Jan 10, 2019

In Handlebars java, easy things are not easy. There are missing many helpers like for removing whitespaces, logical operators etc. The limited functionality of handlebars is ok in case of concerns separation (model & view layers) but... in a real/dev world when we use Knot.x to just pass the JSON feed data from 3rd party service and render it we need advanced logic in template engine (for now, implement plenty of handlebars helpers) or be forced to manipulate 3rd party service response before passing it to template engine which could cause more poor performance in case of need to buffer response, map feed objects to pojos etc.

Without a need to transform 3rd party responses and into desired format, such little logic could be covered by more advanced template engine (with var assignments, macros, inheritance and much more built-in helpers) with even better performance like Pebble Template Engine.

image

https://github.com/mbosecke/template-benchmark

Rocker is alternative tpl engine with even better performance, but it does not offer such many features like Pebble.

To cover my case, I would like to have an option to write (with no extra pebble extensions needed to be impl):

[
{
all_swatch_ids: "PX1|PC2|PG1"
all_swatch_links: "http://my-website.com/products/1|http://my-website.com/products/2|http://my-website.com/products/3"
all_swatch_images: "http://my-images.com/swatch1.jpg|http://my-images.com/swatch2.jpg|http://my-images.com/swatch3.jpg"
all_swatch_names: "Product 1|Product 2|Product 3"
description: "Sample product description"
title: "My product"
},
/* ... and more items */
]

then

{% for(item in items) %}
<div class="product">
{% for (swatch in swatches) %}
    {% set links = split(item.all_swatch_links) %}
    {% set ids= split(item.all_swatch_ids) %}
    {% set images= split(item.all_swatch_images) %}
    <ul class="product-swatches">
       <li class="product-swatch {% if loop.first %}is-active{% endif %}"><a href=""></a></li>
    </ul>
</div>
{% endfor %}

reference:
https://pebbletemplates.io/wiki/tag/for/
https://pebbletemplates.io/wiki/tag/set/
https://pebbletemplates.io/wiki/filter/slice/

in handlebars it is not trivial to introduce new variable which values comes from custom helper to be able to use other helpers to consume a value

to sum up, more ways to cover edge cases in Knot.x templates make reduce costs of integrating 3rd party services and this is main motivation to introduce this issue.

current set of handlebars helpers is not good enough in my opinion. pebble just offers more built-in features and they are well tested. I'd like to avoid using untested helpers (be forced to implement my own for simple scenarios /yes it is ugly truth for now).

@pun-ky
Copy link
Author

pun-ky commented Jan 10, 2019

issue copied from Knotx/knotx#477 (comment)

@szymon-owczarzak
Copy link

Quite readable markup from my perspective - i like it.

@marcinus marcinus mentioned this issue Jan 24, 2020
6 tasks
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

No branches or pull requests

2 participants