dust.js

Dust.js load template from filesystem in Node.js

女生的网名这么多〃 提交于 2019-12-13 05:56:27
问题 I'm trying to load template from file system using node.js and can't find the way. So far I have: exports.index = function(req, res){ var compiled = dust.compile("Hello {name}!", "intro"); dust.loadSource(compiled); dust.render("intro", {name: "Fred"}, function(err, out) { res.write(out); res.close(); }); }; Is there is a way to replace: "Hello {name}!" with file name? Should it be HTML or JS file? Also if that's not really great way on rendering templates let me know, I'm new to Node.js

Dustjs Display Unique Values Only?

假装没事ソ 提交于 2019-12-12 20:35:10
问题 Lets say i have the following JSON { names: ["John", "Peter", "Ron", "John", "James", "John"] } I need DustJS to render the following names John Peter Ron James Notice that these are unique values in an array. Any ideas? Thank you so much! 回答1: This can be done using a common algorithm to 'unique' an array: Array.prototype.getUnique = function(){ var u = {}, a = []; for(var i = 0, l = this.length; i < l; ++i){ if(u.hasOwnProperty(this[i])) { continue; } a.push(this[i]); u[this[i]] = 1; }

Indirection in dust.js

孤街浪徒 提交于 2019-12-12 00:23:02
问题 Is it possible to achieve variable indirection in dust.js - and therefore to be able to use map-like functionality? Imagine I have the following context to pass to Dust: { "keys": [ "Foo", "Bar", "Baz" ], "data": [{ "date": "20130101", "values": { "Foo": 1, "Bar": 2, "Baz": 3 } }, { "date": "20130102", "values": { "Foo": 4, "Bar": 5, "Baz": 6 } }] } And I want to achieve the following output (it would actually be a table, but I've skipped the <tr><td> tags for brevity and replaced them with

How to append html into section in dust.js?

╄→尐↘猪︶ㄣ 提交于 2019-12-11 20:09:28
问题 How do you append html into a section in dust.js? It seems that there isn't a built-in way to do this. Maybe some kind of streaming block could be used to achieve this? Another solution might be a dustjs-helper which would find a section and append into it. I need this functionality to add scripts and styles in the head of the html document, when including other templates into the parent template. Any ideas how to approach this problem? I'll also accept solutions which use bodies or blocks

dustjs rendering client-side not working

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 10:29:41
问题 Using dustjs for templating engine within Expressjs 4. Want to render the template client-side when user fills out a form and clicks a search button using xhr. Everything seems to go fine so far as getting the json from xhr call but dust.render does not render the result. Here is the dust template on the page: &ltscript id="result-template"> // extra table tags removed for brevity {#search_results} {fname} {lname} {accountId} {email} {status} {/search_results} </script> <div id="output">

How to stylize recursive directory with css?

三世轮回 提交于 2019-12-11 07:32:05
问题 I'm trying to make a recursive directory display in html using json data from a node.js server and using it as the rendering context for a dustjs-linkedin template. The data contains a structure like the following: { "isDirectory": true, "path": "", "name": "", "files": [ { "name": "Light House.jpg", "filename": "Light%20House.jpg", "path": "/Light%20House.jpg", "bytes": 561276, "date": "2012-07-25T16:30:45.094Z", "prettyDate": "Jul 25 2012 11:30:45", "type": "image/jpeg", "size": "548.1 kB",

How to update context in dust helper for chunk.render

我只是一个虾纸丫 提交于 2019-12-11 03:56:51
问题 I am using linkedin's version of dustjs. I want to create a custom helper that updates the context to be more specific for rendering the body of the context. How can I do that? Say the context is currently: { title: "News", items: [], nav: { logo: 'logo.png', items: [] }, body: { items: [] } } If I just use chunk.render(bodies.block,context) in my helper, it would be at context level. But I'd like it to render with a scope at the lower 'nav' level: { logo: 'logo.png', items: [] } Somewhat

dustjs-linkedin with express 3

人盡茶涼 提交于 2019-12-08 13:37:06
问题 I am trying to get dustjs-linkedin working with an express 3 project, however I can't seem to get past this error: Error: Template name parameter cannot be undefined when calling dust.compile at Object.compiler.compile (/home/user/project/node_modules/dustjs-linkedin/lib/compiler.js:21:16) at Object.dust.compileFn (/home/user/project/node_modules/dustjs-linkedin/lib/dust.js:109:37) at Function.exports.dust.render (/home/user/project/node_modules/consolidate/lib/consolidate.js:226:56) at /home

node.js + express.js + dust.js issues

*爱你&永不变心* 提交于 2019-12-07 09:05:52
问题 The quick question: why won't express.js run with dust.js? I know it's not officially supported, but dust.js even has issues with my node.js version. Node won't even start due to require.path issues. server:testapp treejanitor$ node --version v0.6.12 I get issues when setting the app engine to dust. ( app.js in express) var dust = require('dust'); ... app.set('view engine', 'dust'); I'm showing the console here to give you my simple list of modules. Also someone searching for the same problem

Why should we wrap our templates inside script blocks?

痞子三分冷 提交于 2019-12-07 01:26:16
问题 Background All the JS template engines recommend putting your template text inside script blocks like so: <script id="peopleTemplate" type="text/template"> {#people} <div class="person">Name: {firstName} {lastName}</div> {/people} </script> but many developers (understandably) dislike this because they lose HTML syntax highlighting in their code editor inside the script block. I've seen the workarounds like this: Keep correct HTML syntax highlighting in <script> "text/html" templates . This