Ameba Ownd

アプリで簡単、無料ホームページ作成

centzudotsmac1976's Ownd

Why mustache template

2022.01.07 19:25




















It might be installed as a global tool on your computer to render a mustache template of some kind. The command line tool is basically a wrapper around Mustache. If your templates use partials you should pass paths to partials using -p flag:. These may be built using Rake and one of the following commands:. In order to run the tests you'll need to install Node. You also need to install the sub module containing Mustache specifications in the project root.


The test suite consists of both unit and integration tests. If a template isn't rendering correctly for you, you can make a test for it by doing the following:.


Browser tests are not included in npm test as they run for too long, although they are ran automatically on Travis when merged into master. Run browser tests locally in any browser:. An updated list of mustache. Add yourself or your company if you use mustache. You can help out a high-profile project that is used in a lot of places on the web.


No big commitment required, if all you do is review a single Pull Request , you are a maintainer. And a hero. Skip to content. Star 15k. MIT License. Branches Tags. Could not load branches. Could not load tags. Latest commit. Git stats commits. Failed to load latest commit information. View code. Contributing Your First Contribution Thanks.


Where to use mustache. And this will be your templates after you use Mustache: Install You can get Mustache via npm. No repos :. That said, after some frustration and after trying other template engines we ended up creating our own NET Razor templates. It is parsed and compiled on the server and generats a simple, self-contained JS function actually as RequireJS module which can be invoked to "execute" the template, returning a string as the result.


The sample given by brad would look like this when using our engine which I personally find far superior in readabily compared to both Mustache and Underscore :. Another logic-free limitation hit us when calling into partials with Mustache. While partials are supported by Mustache, there is no possibility to customize the data to be passed in first.


So instead of being able to create a modular template and reuse small blocks I'll end up doing templates with repeated code in them. We solved that by implementing a query language inspired by XPath, which we called JPath.


The language is side-effect-free which is a must for templating but allows "massaging" data as needed by creating new literal objects. Let's say we want to render a "data grid" table with cusomizable headers and links to actions on the rows, and later dynamically add rows using jQuery. The rows therefore need to be in a partial if I don't want to duplicate the code. And that's where the trouble begins if some additional information such as what columns shall be rendered are part of the viewmodel, and just the same for those actions on each row.


Here's some actual working code using our template and query engine:. It does not have any business logic in it, yet it is reusable and configurable, and it also is side-effect free. Here are 3 ways of rendering a list, with character counts. All but the first and shortest one are in logic-less templating languages.. The promise of logic-less templates was, I suppose, that people with broader skillsets would be able to manage logic-less templates without shooting themselves in the foot.


However, what you see in the above examples is that when you add a minimal-logic language to string-based markup, the result is more complex, not less. Also, you look like you're doing old-school PHP. Clearly I don't object to keeping "business logic" extensive computation out of templates.


But I think that by giving them a pseudo-language for display logic instead of a first class language, the price is paid. Not just more to type, but a heinous mix of context-switching somebody needs to read it. In conclusion, I fail to see the logic of logic-less templates, so I'd say their advantage is nil to me, but I respect that many in the community see it differently :. I agree with Brad: the underscore style is easier to understand. But I must admit the syntactic sugar may not please to everybody.


It is always nice if you can fallback to standard constructs such as for or if. Template engine is great when you can achieve nested templates easily underscore style :. Basically you pass your inner tmpl as a property of your context. And call it accordingly. Sweet :. By the way, if the only stuff you are interested in is the template engine, use the standalone template implementation.


It is only characters when minified 4 long lines :. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?


Collectives on Stack Overflow. Learn more. What's the advantage of Logic-less template such as mustache? Ask Question. Asked 11 years, 1 month ago. Active 4 years, 1 month ago. Viewed 40k times. Improve this question. Morgan Cheng Morgan Cheng Add a comment. Active Oldest Votes. Improve this answer. Miguel Ping Miguel Ping So, why is it a good thing that controller code HAS to massage data in exactly the form that is needed to present the data in a particular way?


Why is it a good thing that changing the presentation often requires changing controller code? This seems like a bad thing to me. I thought one goal of a template language was to separate controller logic from presentation logic. A dumb template that can't make any decisions whatsoever forces presentation logic back into the controller code.


In organizations where a different person works on presentation, they can't do their job by themself. You should not prepare data for the view in your controller. Controller is for controlling application flow.


Instead what you should do is create a presenter class that transforms your model into a view model which is then consumed by the view. A view model is a model for the UI which is separate from the model which is part of the business logic. It forces some presentation logic into the controller, but this helps mutliple various presentation layers. Emile Bergeron I'm surprised you feel that the underscore template is simpler..


Just an opinion :- — Ben Clayton. However, its the complexity that I'm driving at when I say "simple". Sometimes using a ternary statement is appropriate in the template no matter what logic you have. Or what if I want to output the number of items in an array? I don't know how I could use mustache, it appears to lack things like that. PaulShapiro You would generate the number of items in the array outside the template, and store it in a separate variable.


Show 5 more comments. Mustache is logic-less? So, while it's possible to use Mustache with or without logic, it's up to you. After all, it's just a tool. You're looking at this the wrong way. Just because you can do a few things in a language that are not exactly of its general paradigm does not mean that the language is not of that paradigm. You can do write imperative code in Java or Haskell, yet you wouldn't say that makes Java not an OO language nor Haskell not a functional language.


Look at what the language lets you do easily and what it leads you towards to see what kind of language it is. Sampson your analogy would make sense if Java sold itself as "functional-less" or if Haskell sold itself as "object-oriented-less". This answer is demonstrating that "logic-less" is at best a misnomer. I think you agree with me that when we call a language "functional" we mean, "tending toward functional.


From the mustache manual : We call it "logic-less" because there are no if statements, else clauses, or for loops. Jeremy Jeremy If you'd like, you can do this ahead of time using mustache. It might be installed as a global tool on your computer to render a mustache template of some kind.


The command line tool is basically a wrapper around Mustache. These may be built using Rake and one of the following commands:. In order to run the tests you'll need to install Node. You also need to install the sub module containing Mustache specifications in the project root.


The test suite consists of both unit and integration tests. If a template isn't rendering correctly for you, you can make a test for it by doing the following:. Browser tests are not included in npm test as they run for too long, although they are ran automatically on Travis when merged into master.


Run browser tests locally in any browser:. An updated list of mustache. Add yourself or your company if you use mustache. You can help out a high-profile project that is used in a lot of places on the web.


No big commitment required, if all you do is review a single Pull Request , you are a maintainer. And a hero. Git github. Where to use mustache. And this will be your templates after you use Mustache: Install You can get Mustache via npm.


Keywords mustache template templates ejs. Install npm i mustache Repository Git github. Homepage github. Downloads Weekly Downloads 2,, Version 4.


License MIT. Unpacked Size kB. Total Files