Uniform HTML templating language - html

It seems like every web framework has its own pet template language. Ruby has eRuby, Python's django uses the Django template language, Haskell has Heist and Hamlet, Java's got JSP, and then there's PHP...
My question is, has anyone tried creating One Templating Language to Rule Them All? Are there any such templating languages that at least have some widespread support amongst the varying web frameworks?

Mustache maybe.

XSLT might be a candidate as a "universal" template language.
It might also be the greatest evil that this land has ever seen, but that's up for debate.

NHAML/HAML is the closest you'll get to a standard.

Freemarker (and Velocity to some extent) seem to be supported by a growing number of frameworks (Spring, Tiles, Struts and more) and can be used to generate code in any framework, but I don't think there is "one template engine to rule them all". If there was though, I would choose Freemarker any day

uh... Trying to find something like that for WEB project which would be able to render html from same templates at both sides. Server and Client. Already mentioned Mustache seams to be most suitable choice so far...
Maybe this JSON based solution will sound interesting...
Also HAML looks promising.

Related

Understanding the Basics behind Handlebars, Express, and Node.js

I've been struggling to understand Handlebars ever since I was introduced to it in class. I've researched different resources and videos (e.g., YouTube, StackOverflow, etc.) to try and learn more about it, but I still feel like I'm not getting it.
Could somebody please either explain to me what Handlebars is in their own terms or send me resources they found helpful when learning it?
Thanks!
handlebars.js is a templating engine which allows dynamic data to be mixed in with your HTML code. Templating engines were created due to complex projects requiring a lot of dynamic HTML manipulation. Previously, software developers created new chunks of HTML code and dynamically inserted them into the DOM using Javascript. This eventually became unwieldy and difficult to maintain. Also, it lead to repetition of code. To solve this issue, templating engines allowed one to create predefined templates to be used in multiple locations without repeating the code. Templates are like “macros”; wherever they are used, the code in them is inserted at that place. They also help to keep your html away from your javascript files, thereby increasing the readability and re-usability of your code. For a more comprehensive explanation see this blog post
The best resource to learn handlebars.js is their documentation
There is a course on Udemy that uses handlebarsjs and Node and Express and goes from pretty basic I think. This is it.

Can anyone point me to a modular static HTML authoring/preprocessing framework, a la SASS? Or more accurately, HAML with includes?

I find myself doing a lot of work here and there (both for myself and on contract) to develop small, static websites where the use of dynamic tools like PHP frameworks or Rails would be totally useless and heavy-handed and a waste of resources.
I'm looking for a way to author static HTML sites that introduces a level of modularity and syntax simplification; to clarify, something like SASS for HTML with a fast syntax and that allows common patterns to be extruded out in to separate files.
I'm aware of HAML. I would love for HAML to be my solution. But in all of my reading, HAML doesn't seem to have an equivalent to a SASS-style include directive used for in-lining the content of external files. In addition, HAML seems to bill itself as more of a templating engine than an authoring tool the way SASS bills itself; it seems to have a desire to be a replacement for ERB and to be used in Rails projects, rather than being used as a modular HTML preprocessor.
I know I could roll my own solution by bolting a small amount of Ruby and in-line evaluation on to HAML, but it feels a little cheap and dirty since this isn't really what HAML "wants" to do. It's not a solution I'm averse to, but if there is a no-configuration, light-weight option out there that basically behaves like SASS but for HTML then I'd prefer to go that route.
We build static sites with middleman. There are a lot of features, but mainly it's just a very handy static site generator (for development and production). As a plus middleman is a quite popular thing.
And another known option is a Serve. It may be useful for rails prototypes or for those people, who already familiar with rails.
But I still prefer middleman because it's more popular (Serve just more younger, not worse).
As about your question: in both tools you can split HAML views into partials, layouts, etc.
Also, take a look at this category.
It sounds like Stasis would fit your needs very well. I've used it to build a number of small static sites now.
Another option is Jekyll. It offers an easy setup, easy syntax, plugins and extras.

How to prettify programming language

I have code written in any programming language. How can I "prettify" it (bold if, else etc.) to display on a website? Are there any good APIs to do that?
There is Google's prettify which is widely used for such tasks (e.g. SO itself uses it for highlighting of code).
Google Code Prettify JavaScript library supports all C-like (Java,
PHP, C#, etc), Bash-like, and XML-like languages without need to
specify the language and has customizable styles via CSS.
Moreover, as i know, there is a lot of third-party styles for those languages that not supported officially.
If you're using PHP, I recommend GeSHi
If you're talking about an auto-formatter, I've used PEAR's PHP Beautifer before.
Although you shouldn't really need a script to format your code for you...
This is the most common plugin used on the web I think.
I think it works for most programming languages.
I see it everywhere. I am actually thinking of adding it to my website as well.

multi language html page

The website I'm currently working on is supposed to be in multiple languages (4 in this case).
What's the "best" way to achieve this?
It seems like most people use a php table for it. Is this the "best" way right now?
Alas I only know some HTML and CSS, so my idea was to simply copy the whole website tree and make a seperate html tree for each language starting with index.html as the default language and three other trees starting with index_lang2.html, index_lang3.html, index_4.html.
On the index site you could switch the language and go down each seperate html tree.
Is this solution acceptable? I seems quite easy to generate but hard to maintain.
it depends on how much pages you have! There is no reason in making a language system if you only have 10 plain html pages and have no clue about php. And such systems are "only for" UI Elements and not for the real content if you plan to post information there...
If that are static pages, then using no such system is a nice solution!
But if you have more, then there are several solutions:
Take an existing Framework with language support
Write your own language class with vars on the different places
... there are for sure more possibilities, but nothing which comes in my mind :)
As already stated, I think as long as your site only has limited static HTML webpages then it's not worth trying to implement a fancy PHP solution (especially if you have to learn PHP to do so!)

Does Django have HTML helpers?

Does Django have any template tags to generate common HTML markup? For example, I know that I can get a url using
{% url mapper.views.foo %}
But that only gives me the URL and not the HTML code to create the link. Does Django have anything similar to Rails' link_to helper? I found django-helpers but since this is a common thing I thought Django would have something built-in.
No it doesn't.
James Bennett answered a similar question a while back, regarding Rails' built-in JavaScript helpers.
It's really unlikely that Django will ever have 'helper' functionality built-in. The reason, if I understand correctly, has to do with Django's core philosophy of keeping things loosely coupled. Having that kind of helper functionality built-in leads to coupling Django with a specific JavaScript library or (in your case) html document type.
EG. What happens if/when HTML 5 is finally implemented and Django is generating HTML 4 or XHTML markup?
Having said that, Django's template framework is really flexible, and it wouldn't be terribly difficult to write your own tags/filters that did what you wanted. I'm mostly a designer myself, and I've been able to put together a couple custom tags that worked like a charm.
The purpose of helpers is not, as others here imply, to help developers who don't know how to write HTML. The purpose is to encapsulate common functionality -- so you don't need to write the same thing a thousand times -- and to provide a single place to edit common HTML used throughout your app.
It's the same reason templates and SSI are useful -- not because people don't know how to write the HTML in their headers and footers, but sometimes you want to write it just once.
EG. What happens if/when HTML 5 is
finally implemented and Django is
generating HTML 4 or XHTML markup?
Same thing that happens when HTML 5 is implemented and all your templates are written in repetitive HTML, except a lot easier.
The other posts have already answered the question, linking to the docs on custom template tags; you can use tags and filters to build your own, but no, there aren't any built in.
it doesnt look like they're built in but here's a couple snippets. it looks like it'd be pretty easy to create these helpers:
http://www.djangosnippets.org/snippets/441/
Here is a list of all template tags and filters built into Django. Django core doesn't have as much HTML helpers as Rails, because Django contributors assumed that web developer knows HTML very well. As stated by saturdaypalace, it's very unlikely for AJAX helpers to be added to Django, because it would lead to coupling Django with a specific JavaScript library.
It's very easy to write your own template tags in Django (often you need just to define one function, similiar to Rails). You could reimplement most of Rails helpers in Django during a day or two.
I bet if there would be any consent of what is common html, there would be helpers module too, just for completeness (or because others have it). ;)
Other than that, Django template system is made mostly for HTML people, who already know how to write p, img and a tags and do not need any helpers for that. On the other side there are Python developers, who write code and do not care if the variable they put in context is enclosed by div or by span (perfect example of separation of concerns paradigm). If you need to have these two worlds to be joined, you have do to it by yourself (or look for other's code).
This won't answer directly to the question, but why not using foo in template then?