Can't I do anything with a mustache?

I rate http://github.com/janl/mustache.js

and I’m thinking about how it will work in general over time over time. If I just create a giant object, is there a mustache enough to convert it to any form of HTML?

So my question. Is there anything a mustache can't do?

(I think this is just converting the tree from JSON to HTML, but I'm not sure how to test this or get enough confidence to bet against it)

further clarification

Suppose all that I had was a gigantic object, and then I gave a mustache pattern in one iteration; is there anything in HTML that cannot be expressed in mustache through its language.

+6
javascript mustache
source share
2 answers

Since Mustache is just a template language in JavaScript, you can do everything you can already do in JavaScript, and JavaScript is Turing. No, there is nothing that you cannot do in Mustache; in fact, you cannot do anything in Mustache that you cannot do yourself in JavaScript, it just makes some things more convenient.

When evaluating something like this, instead of determining what it can and cannot do, it’s more useful to ask “does it do what I need to do easily” and “does it make mistakes that I want to avoid? to do. "

For example, one way to evaluate it is to avoid cross-site scripting (XSS). According to the documentation, "mustache.js escapes all meanings using the standard double-whisker syntax", so it looks like it really helps to prevent these kinds of attacks.

In order to better evaluate it, you will need to provide more detailed information about your requirements. What are you trying to do? What do you need to integrate with?

change

Even after your clarification, it is still not entirely clear what you are looking for. Even limiting yourself to expanding a single Mustache template with a single representation as input, you can create any arbitrary string, and therefore any arbitrary HTML, by simply passing it that string as input.

If you ask if you can perform arbitrary calculations based on the template and presentation for rendering, then the answer is also yes, because Ussu allows you to call functions in your template, and these functions are written in Javascript, which completes Turing.

But both of these are trivial answers; you can produce any given output by specifying this as an input, or you can perform any calculation using a higher order section. As I said earlier, what can be done with it is less interesting than what is easy to do with it and what mistakes are difficult to cope with.

I believe that one weakness, which may be the type you are looking for, is that if you need more energy than the Mustache system itself, you need to pass these functions as part of the view. Thus, you need to configure the object that is displayed with the code that will be used to display it. And if you remove the ability to invoke Javascript from the views that are passed to the templates, then you severely limit what you can do. Given the fact that these objects are known as “views,” it seems that by design you mix representations with them in the logic; this is very different from templating systems in which you allow a template to retrieve values ​​directly from your model objects.

+8
source share

Yes, there are many things you cannot do in your mustache. Mustache is simpler than some other full-featured template systems (e.g. in Django). Mustache is a very minimal template system that encourages you (through this lack of functions) to implement templates without logic. This means that some processing that you can do on other template systems must be done in code that modifies the data that is sent to the template.

This is a good template system, it's just a minimal system that aims to be simple and fast.

So, I would say that the answer to this question is: "Yes, there are things that you cannot do in Mustache (compared to some other template systems)."

+3
source share

All Articles