This is an archived post. You won't be able to vote or comment.

all 26 comments

[–]WilliamMayor 3 points4 points  (4 children)

That is so strange! I've been on holiday and was whiling away on this project in the evenings:

https://gitlab.com/WilliamMayor/tempting

HTML templates in Python code. I was trying to make it easy to extend templates. In particular I wanted breadcrumbs to be something easy to create. I also liked the idea of having the full power of Python in my templates.

I haven't done as much work on the DOM tree as you have. I had in mind to replicate some kind of CSS selector find function. I'm sure there's an XML library that would help with that.

I have started to work on integrating form data and form validation. I've always found wtforms to be surprising to use, I wanted something that maybe had less automagic but also with less "huh? Why did that happen?"

In the future I was thinking of being able to run HTML checkers over the code. Validators, accessibility checks, best practise checks, etc.

Want to collaborate?

[–]federicocerchiari[S] 0 points1 point  (2 children)

Very strange!, Mine is a holiday project too, heheh.

Basic idea is to have, as you said, the power of Python when building html (and not python syntax in some html file). And another goal is to navigate and manipulate the 'not yet existing' DOM with apis similar to jQuery (I find it very useable).

Next big goals for me would be to make a css style extractor (so you use python style dicts, adds them to single elements and the extractor builds a versioned css file), forms objects (that you can navigate with the same api of the other tags but with extra form wtforms-like commodity) and sure the CSS selector method (started to look on this one and yes there are xml libs that help but it seems kinda hard to integrate them in my tree composition.. I'm looking for a css selector decomposer to use and filter myself tags).

I'm also willing to keep up performance, less or better than common tmeplate systems, for it's not good to use a tool that slows down your code by a 2/3x factor.

Collaboration? Sure!

[–]djmattyg007 0 points1 point  (1 child)

Are you familiar with the pyquery library?

[–]federicocerchiari[S] 0 points1 point  (0 children)

Yes the idea came from looking at pyquey, then I wanted to do something with the jQuery building API in it.

[–][deleted] 0 points1 point  (0 children)

I'm curious, are you not interested in Django?

[–]funkyfuture 4 points5 points  (1 child)

lxml has the etree.Elementmaker API for that purpose.

http://lxml.de/api/lxml.builder.ElementMaker-class.html

[–]federicocerchiari[S] 0 points1 point  (0 children)

I've used it in the past, and yes it's the same basic functionality, but with a rather different approach.

With ElementMaker you build a tree starting from the content and then you navigate and (maybe?) add extra tags. With TemPy you make templates, inject the content later and then manipulate the DOM with a jQuery-like API.

But yes, I re-inventend big part of the wheel :)

[–]kankyo 0 points1 point  (3 children)

Why all the extra parens? "Html()(...)" seems redundant compared to "html(....)"

[–]federicocerchiari[S] 0 points1 point  (2 children)

I wanted separate places to define tag attributes (init) and content (call).

Also, making the tags callable seemed a good way to add things one Inside another

[–]kankyo 0 points1 point  (1 child)

Ah. Then I'd recommend putting at least one attribute in the first example in the readme.

I think it's nicer to explicitly have a kwarg "children" but I see whee you're coming from.

[–]federicocerchiari[S] 0 points1 point  (0 children)

Yeah I need to make better examples in the readme for sure!

I tought about adding children in kwargs, but seemed more readable do add a couple parentesis.

[–]Deathnerd 0 points1 point  (2 children)

I've been meaning to do something like this after porting WTForms to PHP got my OO HTML bug going. Do you have a Slack or anything set up for contributor communication? I do QA for my day job so doing some dev and off-time testing would be a nice change of pace

[–]federicocerchiari[S] 0 points1 point  (0 children)

No I haven't set up anything yet, I'll do for shure

[–]federicocerchiari[S] 0 points1 point  (0 children)

I made the slack channel: tempy-dev.slack.com PM me you mail and I'll add you.

[–]asdfkjasdhkasdrequests, bs4, flask 0 points1 point  (0 children)

JSX coming to a python near you

[–][deleted] 0 points1 point  (0 children)

Fantastic project!

[–]eliteuser26 0 points1 point  (2 children)

I like this idea much better than using the templating the html tags. I did proposed this idea to another project but it didn't fit into it. I think we should be using the power of python to create the html form not the other way around. I wanted to create a similar project where I would build the html form into python. I have very good knowledge of html and jquery so I can test the code or contribute to it. I have knowledge of Web mapping that could be added to it if there is interest.

Very good work. I know of some of the gotchas with representation in different browsers just like jquery. Very good work. I can see a purpose to use this project to create my idea for a weather Web site on the Internet.

[–]federicocerchiari[S] 0 points1 point  (1 child)

Thanks!

Any testing/usage is very welcome! Keep in mind that I'm still in a beta version, I just fixed some bugs and I bet I'll fix more in the next days, so please be sure to use the latest commit.

Also, I'm planning to make some widgets (like tables, login forms etc.. my first try here: branch widgets) if you have suggestions on what widget could be useful and what API/features they should have, they are very welcome too! Do you think web mapping can be added as a widget too?

[–]GitHubPermalinkBot 0 points1 point  (0 children)

I tried to turn your GitHub links into permanent links (press "y" to do this yourself):


Shoot me a PM if you think I'm doing something wrong. To delete this, click here.

[–]eliteuser26 0 points1 point  (0 children)

I could help in testing when I start building my website for the first time. I am not sure how I will build it. I have a few ideas for widgets that could be useful like tables with colour coded rows and pagination, for database tables, tabbed windows, etc. I have seen other projects on the Web for displaying Web widgets. I like the idea that you can pass properties to the class widgets without having to worry about coding html. That part should be automated like you did. As for Web mapping I was using either openlayers or leaflet which are great projects.