Hi!

Template languages are my favorite topic in programming.

If you implement html library yourself, it is much better to define tags 
not as functions but as classes with base Tag class which has properties 
for tag name, attributes and the nested list of tags. Such way you will 
re-implement DOM, although it is already available in lxml library.

So maybe it's a better idea to figure out whether lxml can be used as 
template engine for Django, because it can load source html into nested 
structures via binary optimized code. It should be cleaner and faster than 
manual composition of html in Python code.

In such case bindings could be performed via data-bind attribute like in 
Knockout,js or via Vue-like v-bind attribute:

http://knockoutjs.com/documentation/observables.html
https://vuejs.org/v2/guide/syntax.html#Attributes

Binding server-side data via html5 data attributes is the most 
non-obtrusive approach, and it does not create syntax clashes with 
server-side templates like DTL or Jinja which use double braces, 
semantically alien to XML / HTML (however Jinja is much more than html 
templating, it's an arbitrary text templating engine and an almost complete 
language itself).

But the most interesting thing in such approach are custom tags, including 
nested custom tags - so-called "components".

It was implemented ages ago in XSLT, where one may define small template 
with xml tags which then are transformed into larger, more verbose html:
https://www.w3schools.com/xml/xsl_transformation.asp

It is also supported in lxml:
http://lxml.de/xpathxslt.html

But XSL / XSLT did not gain wide adaption because the language syntax is 
made via XML tags and attributes thus became very verbose and difficult to 
read.

Maybe you could create template language like XSLT but with Python syntax? 
How's about such idea?

For example, Python XSLT-like well-readable transformation code could be 
dynamically converted to XSL style sheet then the XSL style sheet applied 
to source template to produce the final html.
https://www.w3schools.com/xml/xsl_transformation.asp

    <xsl:for-each select="catalog/cd">
    <tr>
      <td><xsl:value-of select="title"/></td>
      <td><xsl:value-of select="artist"/></td>
    </tr>

Instead xsl:for-each there will be Python's for, shorter and cleaner 
version, translated to xsl:for-each via AST parser.

Dmitriy
On Saturday, March 17, 2018 at 1:35:49 AM UTC+3, Manasvi Saxena wrote:
>
> Hello Sir,
>
> Okay, so the idea is to render HTML by generally defining it in Python. I 
>> could've sworn that I'd seen something like this years ago, but I'm failing 
>> to find it. That stated, I think this is basically a generating version of 
>> BeautifulSoup (https://www.crummy.com/software/BeautifulSoup/bs4/doc/) 
>> as opposed to a parsing version. 
>>
>> It's roughly like the Storm ORM (https://storm.canonical.com/) but for 
>> HTML instead of database queries.
>>
>> It's interesting, but I'll ask if one can get 90% of the functionality 
>> from xml.etree, which is in the standard Python Library.
>>
>> import xml.etree.ElementTree as ET
>>
>> a = ET.Element('p', style='{color: red;}')
>> a.text = "hello world"
>> ET.dump(a) # will match yours
>>
>> Note that this gets even weirder with something like "<p>hello <i>ignore 
>> this</i> world</p>".
>>
>> b = ET.Element('p')
>> b.text = "hello "
>> c = ET.Element('i')
>> c.text = "ignore this"
>> c.tail = " world"
>> b.append(c)
>> ET.dump(b) # will match above
>>
>
>
> I'm sure xml.etree has its drawbacks which I will improve in my library.
> The whole idea here is to bring python closer in the picture of generating 
> HTML content.
> Its applications are vast and not only limited to this. If time permits I 
> intend to write a complete framework like Bootstrap for python where things 
> like cards, navbars etc will be inbuilt and purely written on the basis of 
> my library.
> And that is the new feather I intend to add to Django's hat.
> Just like we have some inbuilt  'forms' in Django we'll have a lot of 
> other front-end related objects written in python and easily manipulative.
> And thus I intend to extend Django's reign in the front-end domain as 
> well. And make it a full-stack framework.
> Surely designing is something that changes very frequently in today's 
> world but if this is successfully implemented we can bring developers from 
> front-end world to contribute to it too. 
> Logic + Design.
>
> Regards,
> Manasvi Saxena
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/67d7a24c-d508-41cd-ab52-c3415cbb5131%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to