Nunjucks – A rich and powerful templating language for JavaScript by Mozilla
mozilla.github.io
mozilla.github.io
There are so many awesome things that React's model enables (like live editing with react-hot-loader). It would be awesome if the next generation of templating languages could inherit them for effectively free.
In any event, I must say I like this kind of comments: a bit opinionated but putting forth some rationale, and hence inviting a healthy exchange of opinions.
There is no "inviting a healthy exchange of opinions",he is basically just trashing the project.There is nothing interesting in what he is saying,though he's free to say whatever he wants.Proof is the answers to his comment.
But yeah, I'm not really a huge fan of the template system either and the whole jsx thing is not really convenient.
The duplicate effort: porting some custom Jinja2 filters and plugins from Python to JS. That was a few hours of work on a project that has seen thousands of hours of total work, so down in the noise really. If Python on the server side has big benefits in your problem space, don't let this deter you.
The other thing to be aware of if you want isomorphic templating across JS and Python: Nunjucks is a subset of Jinja2. When I did the Jinja2 -> Nunjucks port, probably 95% of things just worked. The other 5% was either language-idiosyncratic stuff (for example {% set foo = 'bar' %} is scoped to the current block in Nunjucks, but leaks out of block scope in Jinja2) or places where I was being unnecessarily fancy in templates. The port forced me to keep my templates simple and not use the more exotic features of Jinja2, which has turned out to be a good thing.
The closest I've seen to what I want is DRYML: http://hobocentral.net/manual/dryml-guide
The big advantage of DRYML over systems like React & builders is that it has a really nice story for customization. Rather than customizing just through XML attributes, it also has a system for passing in snippets through XML children. But not just snippets for the top component, but but snippets for children of the components you're instantiating.
This has huge advantages for reusability. There are millions of jQuery widgets out there. How come you never use any of them? They never fit the style, behaviour nor requirements of your app. Yet on the server side, you pull in tens of gems, npms, etc from random authors.
DRYML allows customization in both the small and the large. It works well for both defining and customizing <a> tags as well as huge custom components. That huge custom component will use your customized <a> etc, so it automatically picks up your theme and behavior.
DRYML has some major disadvantages though: it's really nice to use, but defining new components looks like line noise. It's also tied to a heavyweight, lightly used framework for Ruby on Rails called Hobo.
One of my many projects abandoned due to lack of time is a port of DRYML's "standard library" Rapid to React. React isn't quite as nice as DRYML for re-use and customization, but it has a large number of advantages in popularity, speed and readability. If anybody else is interested in the project, give me a shout.
See e.g. https://en.wikipedia.org/wiki/Template_Attribute_Language
On the flexibility front, the same template language (and especially ones with good whitespace control, e.g. Jinja2) can be used for any text-like format. If browser or device quirks force you to emit invalid XML to trigger some desired behavior, you don't end up in a fight with your perfectionist templating system (and probably resorting to regexes over its output) to achieve the desired result.
I'd say (and probably, a younger version of myself turns in his grave as I say it) that in this case, worse turns out to be much better.
On the other hand, there are other similar attribute based xml templating languages that are much much better, because they didn't try to reinvent the wheel out of tapioca and rusty iron filings, but instead they simply acted as a thin veneer over Python, so everything you knew about and could do in Python applied without any distortion or unnecessarily creative reinterpretation.
Specifically, TurboGears used the "Kid" templating language, the next generation of which was re-implemented as "Genshi". I have used both extensively, and although they do have some problems and limitations (many of which Genshi addressed), I really like them a lot, and they are easy to use and think about, and not so full of surprises and disappointments as the horrible stuff from ZOPE that they (distantly) descended from. I've used Kid and then Genshi in large template-heavy projects over many years, and I still use Genshi and like it. It is actually quite elegant and minimalistic, and super easy to learn.
Genshi operates on pure clean XML internally, has real Python loops, conditionals, variables, functions, parameter passing and extensibility, and has plug-in serializers for various formats like XML, XHTML and HTML5, that know about all the formatting rules and conventions and browser quirks and superstitions like <BR />, and never produce incorrectly quoted or formatted content. You can also use it to product plain text as well as markup.
And rarely is speed the most important attribute of a template language. If it was, we'd be writing all of our server code in C.
At least for DRYML, it only requires valid XML on input, it can emit any string on output.
But in essence, you're right. String templating languages have been more successful than TAL or DRYML. But my belief is that's because we just haven't done it properly yet. TAL suffers XML disease, and DRYML has other problems.
I think Genshi does something similar to this but I'm not 100% sure.
Templating with Enlive takes regular old HTML, which could even be mockups of your ui, and a list of (selector, transform) pairs to apply to it. The selectors mostly mimic CSS, while the transforms come with a library to manipulate node attributes, contents, etc. Taking a non-functional form and setting its method and action might look like this:
[:form#my-form] (enlive/set-attr :action "." :method "POST")
My favorite part of using enlive is that it removes almost all responsibility from any frontend developers to know about the templating. They can just produce straight HTML mockups with enough CSS hooks for you to get in and change what needs changing. I even use it on projects that I don't envision anyone else working on -- it's nice not to have to context-switch between design and development all the time.To bind an object to a chunk of DOM (it leverages jQuery) you simple do something like $(selector).bindomatic(object) and you're done. (If you need additional logic, you pass it on the side in an options object.)
http://www.w3.org/TR/2013/WD-components-intro-20130606/#inse...
A webpage is a giant string.HTTP is a giant string over tcp. And you dont need all your complicated stuff if you dont like "giant strings".
There is already something called XSL that can transform structured data into anything else.You just choosed to ignore it in your rant.
why is it easier to manage?
[0] http://twig.sensiolabs.org
[1] https://github.com/mitsuhiko/twig
[2] http://fabien.potencier.org/article/34/templating-engines-in...
By the example of async which initiates value lookups... it can only be slower and promotes the bad habbit of putting too much logic into views.
I'd like to see a sane templating language that is based on a spec and it could be supported under different programming languages.
No,because your spec wouldnt suit everybody and you'll end up with 20 other specs. That's why there is not just 1 programming languages.Because silver bullets dont exist.
I didn't mean spec as in a universal standard.
I meant a language that defines its syntax and functionality as a spec so it can be implemented in the same way in many languages so you can pick your favourite flavour and use it in as many languages as you want without surprises.
So given the template 'T' and template context 'C', you could always produce the exact same output regardless of whether you used javascript or python (assuming the libraries implemented the language based on the spec).
The spec doesn't mean it has to be a silver bullet, it will be a single bullet and there will be many bullets, but whatever bullet you pick, you can use it in more places.
> Rich Powerful language with block inheritance, autoescaping, macros, asynchronous control, and more. Heavily inspired by jinja2
And Jinja is an extended reimplementation of Django's template language.