Re: include_block template tag

2021-04-22 Thread Pierre Vanliefland
Thanks Jure! In the meantime, I have started testing my code extensively 
and spotted a few problems, mostly linked to the usage of block nodes 
within {% embed %}.

I have decide to use a new tag, {% slot %}, with a much simpler 
implementation and it seems to work just fine. I have updated the gist 
 
accordingly. I also have ditched the idea of reusing existing Django code 
(it was messy and confusing) but I have commented the code sections that 
are 100% identical to existing Django code, they could one day be 
refactored into helper methods / abstract classes.

I plan to test this and release it in a production project over the next 
few weeks, I'll share my findings here after that.

Kind regards,

Pierre

On Monday, April 19, 2021 at 11:16:08 AM UTC+2 jure.er...@gmail.com wrote:

> Hi Pierre,
>
> I like your solution very much: implements what needs to be implemented, 
> rationalises it very well and also adds all the other bits'n'pieces 
> required for a proper PR.
>
> I really hope this gets accepted, it was a huge thorn in our butts until 
> we implemented it. Now we're (ab)using it everywhere.
>
> LP,
> Jure
> On 17. 04. 21 10:23, Pierre Vanliefland wrote:
>
> Hi Carlton, 
>
> Thanks for replying so quickly. It's definitely been an itch for me, as 
> check the docs and Stack Overflow every year to check if this has been 
> implemented!
>
> I've completed the Gist with an "include/extends" example, but I haven't 
> done the same for inclusion tags: as far as I know, an inclusion tag has a 
> single, fixed template, which would require you to create one inclusion tag 
> by component in your "design system", which would be even more cumbersome. 
> And it would not allow you to override multiple block contents with 
> arbitrary HTML, which is the goal here.
>
> I plan to use my own implementation more extensively in the coming weeks 
> to check its robustness, but I would be super happy to propose a PR if you 
> find it interesting.
>
> At the moment, it's not a big pain point for me, as I can use my custom 
> tag, but I agree with the feeling of Carl above: while useful, it's a small 
> feature and I'm afraid users won't be attracted by a third-party plugin for 
> 50 lines of code...
>
> I was wondering why I was feeling like this is a missing piece, and I 
> remembered this morning: I used this feature a lot when I was using Twig (
> https://twig.symfony.com/doc/3.x/tags/embed.html).
>
> It was super useful, especially when working on a web application (vs 
> website), where you have a lot of similar sections and widgets, and I've 
> been missing it a lot over the years.
>
> Have a nice day!
>
> Pierre
>
> On Saturday, April 17, 2021 at 5:44:05 AM UTC+2 carlton...@gmail.com 
> wrote:
>
>> Hi Pierre,  
>>
>> No problem at all! There’s some itch that folks have here so all for the 
>> good discussing it. 
>>
>> Thanks for your work on the gist it looks good. I just glanced at it now, 
>> and need to sit down longer but, can I ask you to add a “What’s wrong with 
>> the current tools” section to text? i.e. How would it look using include or 
>> a custom inclusion tag, and so why would a new tag be better? I think that 
>> would be helpful. (Make sense?)
>>
>> Kind Regards,
>>
>> Carlton
>>
>>
>> On 16 Apr 2021, at 23:03, Pierre Vanliefland  
>> wrote:
>>
>> Hello! First, sorry if it is not appropriate to bring back this thread 
>> from the grave, but I spent some time on finding a solution for this and 
>> came up with an implementation that: 
>>
>>1. Needs very little code 
>>2. Re-uses the existing code for the extends and include tags
>>
>> I have written a Gist that contain the full code (including text) and a 
>> bit of context: 
>> https://gist.github.com/pvanliefland/bb676a906b900c7e29e46b474038a6ca
>>
>> Do you think this is worth discussing here?
>>
>> *Usage:*
>>
>> 
>>   {% embed "section.html" %}
>> {% block title %}Stats{% endblock %}
>> {% block content %}
>>
>>   A stat
>>   ...
>>
>> {% endblock %}
>>   {% endembed %}
>>   {% embed "section.html" %}
>> {% block title %}Activity{% endblock %}
>> {% block content %}
>>Yesterday
>>All my troubles seem so far away
>> {% endblock %}
>>   {% endembed %}
>> 
>>
>> On Wednesday, December 2, 2020 at 9:51:03 AM UTC+1 jure.er...@gmail.com 
>> wrote:
>>
>>> Final comment for this:
>>>
>>> we implemented the tag in our dynamicforms library (commit with initial 
>>> implementation 
>>> 
>>> ).
>>>
>>> The initial implementation straight-out replaces the django include tag, 
>>> giving it an additional option to also declare a block tag with nested 
>>> blocks. That didn't work on Django 2.2. though, so the final implementation 
>>> now splits the tag in block and non-block variants.
>>>
>>> Anyway, I wanted t

Re: include_block template tag

2021-04-22 Thread Carlton Gibson
Hi Pierre.

If you were to bundle it in a package and put in on PyPI, that would allow
others to easily experiment and feedback too.

Kind regards, Carlton

On Thu, 22 Apr 2021 at 21:33, Pierre Vanliefland <
pierre.vanliefl...@gmail.com> wrote:

> Thanks Jure! In the meantime, I have started testing my code extensively
> and spotted a few problems, mostly linked to the usage of block nodes
> within {% embed %}.
>
> I have decide to use a new tag, {% slot %}, with a much simpler
> implementation and it seems to work just fine. I have updated the gist
> 
> accordingly. I also have ditched the idea of reusing existing Django code
> (it was messy and confusing) but I have commented the code sections that
> are 100% identical to existing Django code, they could one day be
> refactored into helper methods / abstract classes.
>
> I plan to test this and release it in a production project over the next
> few weeks, I'll share my findings here after that.
>
> Kind regards,
>
> Pierre
>
> On Monday, April 19, 2021 at 11:16:08 AM UTC+2 jure.er...@gmail.com wrote:
>
>> Hi Pierre,
>>
>> I like your solution very much: implements what needs to be implemented,
>> rationalises it very well and also adds all the other bits'n'pieces
>> required for a proper PR.
>>
>> I really hope this gets accepted, it was a huge thorn in our butts until
>> we implemented it. Now we're (ab)using it everywhere.
>>
>> LP,
>> Jure
>> On 17. 04. 21 10:23, Pierre Vanliefland wrote:
>>
> Hi Carlton,
>>
>> Thanks for replying so quickly. It's definitely been an itch for me, as
>> check the docs and Stack Overflow every year to check if this has been
>> implemented!
>>
>> I've completed the Gist with an "include/extends" example, but I haven't
>> done the same for inclusion tags: as far as I know, an inclusion tag has a
>> single, fixed template, which would require you to create one inclusion tag
>> by component in your "design system", which would be even more cumbersome.
>> And it would not allow you to override multiple block contents with
>> arbitrary HTML, which is the goal here.
>>
>> I plan to use my own implementation more extensively in the coming weeks
>> to check its robustness, but I would be super happy to propose a PR if you
>> find it interesting.
>>
>> At the moment, it's not a big pain point for me, as I can use my custom
>> tag, but I agree with the feeling of Carl above: while useful, it's a small
>> feature and I'm afraid users won't be attracted by a third-party plugin for
>> 50 lines of code...
>>
>> I was wondering why I was feeling like this is a missing piece, and I
>> remembered this morning: I used this feature a lot when I was using Twig (
>> https://twig.symfony.com/doc/3.x/tags/embed.html).
>>
>> It was super useful, especially when working on a web application (vs
>> website), where you have a lot of similar sections and widgets, and I've
>> been missing it a lot over the years.
>>
>> Have a nice day!
>>
>> Pierre
>>
>> On Saturday, April 17, 2021 at 5:44:05 AM UTC+2 carlton...@gmail.com
>> wrote:
>>
>>> Hi Pierre,
>>>
>>> No problem at all! There’s some itch that folks have here so all for the
>>> good discussing it.
>>>
>>> Thanks for your work on the gist it looks good. I just glanced at it
>>> now, and need to sit down longer but, can I ask you to add a “What’s wrong
>>> with the current tools” section to text? i.e. How would it look using
>>> include or a custom inclusion tag, and so why would a new tag be better? I
>>> think that would be helpful. (Make sense?)
>>>
>>> Kind Regards,
>>>
>>> Carlton
>>>
>>>
>>> On 16 Apr 2021, at 23:03, Pierre Vanliefland 
>>> wrote:
>>>
>>> Hello! First, sorry if it is not appropriate to bring back this thread
>>> from the grave, but I spent some time on finding a solution for this and
>>> came up with an implementation that:
>>>
>>>1. Needs very little code
>>>2. Re-uses the existing code for the extends and include tags
>>>
>>> I have written a Gist that contain the full code (including text) and a
>>> bit of context:
>>> https://gist.github.com/pvanliefland/bb676a906b900c7e29e46b474038a6ca
>>>
>>> Do you think this is worth discussing here?
>>>
>>> *Usage:*
>>>
>>> 
>>>   {% embed "section.html" %}
>>> {% block title %}Stats{% endblock %}
>>> {% block content %}
>>>
>>>   A stat
>>>   ...
>>>   
>>> {% endblock %}
>>>   {% endembed %}
>>>   {% embed "section.html" %}
>>> {% block title %}Activity{% endblock %}
>>> {% block content %}
>>>Yesterday
>>>All my troubles seem so far away
>>> {% endblock %}
>>>   {% endembed %}
>>> 
>>>
>>> On Wednesday, December 2, 2020 at 9:51:03 AM UTC+1 jure.er...@gmail.com
>>> wrote:
>>>
 Final comment for this:

 we implemented the tag in our dynamicforms library (commit with
 initial implementation