Code Monkey home page Code Monkey logo

dot's People

Contributors

blakmatrix avatar davsket avatar designfrontier avatar edwardbetts avatar epoberezkin avatar kevnk avatar olado avatar pdehaan avatar rdev5 avatar rdworth avatar theel0ja avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dot's Issues

Mixed defines in shared include.

I am attempting to use doT for a multi-processor messaging application that is sending emails. Most emails include the same header partial, with only the title being variable. I just noticed, while sending three different emails, that the titles are getting mixed up.

Following the advanced snippet, this is how I wired up the top part of my template:

{{##def.sTitle:
Welcome!

}}

{{#def.loadfile('/message/email/partials/header.dot')}}

The 'Welcome!' is not consistently being displayed in the welcome email if other templates are simultaneously being processed. How can I set a variable in a limited scope so that my header always prints out the right thing?

Switch encoded and unencoded interpolation

First of all thanks for your great work. Nice and fast lib. This is actually not a bug, its just ment as a hint.

IMHO it would be better to switch the "operators" for encoded and unencoded interpolation like this:

{{=foo}} --> encoded
{{! foo}} --> unencoded

for the following reasons:

  • "Encoded" should be the normal case for security reasons. = feels more like the normal case. ! indicates "heads up" something special goes on here.
  • Other templating libraries, force you to do something special, if you want to have unencoded string output. In Handlebars its {{{foo}}}, in Jade != is used.
  • As a tech lead of larger projects with many developers and even javascript or webapp noobs who might not aware of the security risks, it would make me sleep better.

But as i said, this is just a matter of personal taste.

{{=value.class}} parse error

"{{=value.class}}" produces an parse error on ipad with safari 5.0.2
I am aware that "class" is "preserved" in javascript. BUT the rest of the browsers seem to accept it.
So the question is: Is this a bug in doT?

Example:
{{it.data :value:index}}
{{=value.class}}
{{
}}

Quick fix:
Dont use "{{=value.class}}" but rename it to "{{=value.somethingelse}}"

In "evaluation" blocks, the last character of code cannot be "}"

I guess it's obvious why the last character of an evaluation block can't be "}", but I'm confused by the fact that even when
separated by a newline, the parser gets confused.

That is,

{{ if (a) { b = c }
}}

won't work unless there's at least one space after the "}" after the "if" block. The line break isn't treated as whitespace.

This is easy to work around, of course, but it might be nice to fix if a simple solution can be found (and I'll try to find one).

dotjs comments

add comment syntax

{{// comments }}

  • it will not get removed in the brower
  • can use third party tool to remove that when generating

Mixed defines in shared include.

I am attempting to use doT for a multi-processor messaging application that is sending emails. Most emails include the same header partial, with only the title being variable. I just noticed, while sending three different emails, that the titles are getting mixed up.

Following the advanced snippet, this is how I wired up the top part of my template:

{{##def.sTitle:
Welcome!

}}

{{#def.loadfile('/message/email/partials/header.dot')}}

The 'Welcome!' is not consistently being displayed in the welcome email if other templates are simultaneously being processed. How can I set a variable in a limited scope so that my header always prints out the right thing?

Broken in Opera 11.64

Just tested with a simple HTML file:

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript" src="https://raw.github.com/olado/doT/master/doT.js"></script>
  </head>
</html>

Got:

Uncaught exception: TypeError: Cannot convert 'global' to object

Error thrown at line 36, column 2 in <anonymous function>() in https://raw.github.com/olado/doT/master/doT.js:
    global.doT = doT;
called from line 7, column 0 in https://raw.github.com/olado/doT/master/doT.js:
    (function() {

Browser: Windows Opera 11.64 (latest version)
Related link: http://stackoverflow.com/q/10564463
But the minified version worked.

is dOT what they call "logic-less" ?

In otherwords, is it possible to embed raw javascript in a doT template? I'm hoping the answer is no. This post on templating engines doesn't put dOT in the logicless category

http://engineering.linkedin.com/frontend/client-side-templating-throwdown-mustache-handlebars-dustjs-and-more

My understanding of the term logic-less is that it means you cannot embed javascript in the template, ie, the template engine doesn't understand javascript which is exactly what I want.

Support pre-compilation?

Or does it not make sense because it is mostly string concatenation? Even if a small portion of the job can be done at the server side, it will be huge boost to performance.

If pre-compilation is not supported, please consider supporting it.

If it is already supported, please update the docs to say so.

else is not supported

else directive is not supported within a template, e.g.:

{{ if (typeOf(it.entity) == "null") { }}
<li class="deleted">
    <div class="name"></div>
    <div class="icon remove"></div>
    <div class="separator"></div>
</li>
{{ } }}
{{ else { }}
<li>
    <div class="name">{{= entity.name }}</div>
    <div class="icon remove"></div>
    <div class="separator"></div>
</li>
{{ } }}

Could not create a template function: var out=' '; if (typeOf(it.entity) == "null") { out+='

  • '; } out+=' '; else { out+='
  • '+( entity.name )+'
  • '; }; out+=' ';return out;
    doT.js:83Uncaught SyntaxError: Unexpected token else

    Using templates with Require.js and r.js

    Is possible to use doT template with requirejs?? I mean, put the templates in a folder and dynamically pull this templates.. When build process run (r.js), precompile this templates?

    whitespace removal problem

    Can line 92 be changed to:

    str = ("var out='" + (c.strip ? str.replace(/(^|\r|\n)\t* +| +\t*(\r|\n|$)/g,'')

    Changing the replacement value to empty string.
    In most cases is is unnecessary, but with li tags, space between them on new lines is always present when using new lines to create horizontal lists.

    It would be nice if the whitespace stripping could fix this issue as a bonus to compression.

    500 TypeError: Object #<Object> has no method 'compile'

    500 TypeError: Object # has no method 'compile'

    at Function.compile (D:\nodejs\node_modules\express\lib\view.js:65:33)
    at ServerResponse._render (D:\nodejs\node_modules\express\lib\view.js:414:18)
    at ServerResponse.render (D:\nodejs\node_modules\express\lib\view.js:315:17)
    at D:\nodejs\ex_project\dot\app.js:35:9
    at callbacks (D:\nodejs\node_modules\express\lib\router\index.js:272:11)
    at param (D:\nodejs\node_modules\express\lib\router\index.js:246:11)
    at pass (D:\nodejs\node_modules\express\lib\router\index.js:253:5)
    at Router._dispatch (D:\nodejs\node_modules\express\lib\router\index.js:280:4)
    at Object.handle (D:\nodejs\node_modules\express\lib\router\index.js:45:10)
    at next (D:\nodejs\node_modules\express\node_modules\connect\lib\http.js:203:15)
    

    index.js:

    exports.index = function(req, res){
    res.render('index', { f1: 1, f2: 2, f3: 3})
    };

    index.html

    Just static text

    Here is a simple case {{=it.f1+it.f3}}

    Next we will use a JavaScript block:
    {{ for(var i=0; i < it.f2; i++) { }}
    {{=it.f3}}
    {{ }; }}

    app.js

    var express = require('express')
    , routes = require('./routes')

    var app = module.exports = express.createServer();
    var dot_express = require('dot');
    console.log(dot_express);

    // Configuration

    app.configure(function(){
    app.set('views', __dirname + '/views');
    app.set("view engine", "html");
    app.register(".html", dot_express);
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(app.router);
    app.use(express.static(__dirname + '/public'));
    });

    app.configure('development', function(){
    app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
    });

    app.configure('production', function(){
    app.use(express.errorHandler());
    });

    // Routes
    app.get('/', function(req, res, next) {
    res.render('index', {world: 'world'});
    });

    app.listen(3001);
    console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);

    Isn't doT compatible with IE8?

    I used doT in my website. It can work fine in Chrome, IE9. But when I test it in IE8, the content that I use array iteration of doT can not display. Isn't doT compatible with IE8?

    Streaming?

    The readme says "streaming friendly," but I can't seem to see how in the code that would be possible. I'm pretty new to node and js so I'm sure I could just be overlooking something...

    causes error from Chrome extension

    Hi, thank you for awesome work! I like doT very much and I think it's the best js template library.

    In a project I use doT.js from inside a Google Chrome extension I get the following error in the console:

    Uncaught Error: Code generation from strings disallowed for this context

    Is there any way to get past this error?

    PS: this error causes after I change the manifest_version from 1 to 2, and then doT doesn't work because Content Security Policy

    When I call <a href={{=it.Path}}> the URI encoding gets stripped

    Its appears that even though I properly encode it.Path in the javascript, when i call <a href={{=it.Path}}> in the html, all my URI encoding is stripped and turned into normal text, how can I easily remedy this? Please refer to image to clearly understand the nature of the issue.
    BUG

    Few capability related questions

    Hello,

    1. How difficult is it to implement inclusion of code from external files. Lets say we have a menu system that we want to keep separately and include it in each page and set the menu corresponding to the page as selected.
    2. Can we use the defined data in the evaluation framework as well?
    3. Is it possible to cache the runs so that the pages are not processed on each request?
    4. I believe Ecma5's "use strict"; forbids the use of 'with' . Some people consider 'eval' as evil. Is it possible to refactor the doT without these two constructs?

    Thanks

    Feature request: Context delimeter for prefix free output

    Hi,
    It would be nice if there was a context delimeter. Instead of needing to add "it" as a prefix for every data reference.

    <div>Hi {{=it.name}}!</div>
    <div>{{=it.age || ''}}</div>

    becomes

    {{$ it}}
    <div>Hi {{=name}}!</div>
    <div>{{=age || ''}}</div>
    {{$}}

    Or in a more complex scenario with nesting

    var data = {
      "name": "Jake",
      "age":31,
      "mother":"Kate",
      "father":"John",
      "interests": ["basketball","hockey","photography"],
      "contact": {
        "email":"[email protected]",
        "phone":"999999999"
      }
    }

    Could be used like this:

    {{$ it}}
      <div>I'm {{=name}} and I love..</div>
      <ul>
        {{~interests :value}}
          <li>{{=value}}!</li>
        {{~}}
      </ul>
      <div>Please contact me</div>
      {{$ contact}}
        Phone: {{=phone}}
        Email: {{=email}}
      {{$}}
    {{$}}

    I roughly tried something along these lines in my fork some time back but never really tested or used it. This give a few big advantages. 1) Easier to read the templates without "it" everywhere. 2) If the data structure ever changes- (i.e. something gets nested inside another object when previously it had not) fixing the template is simply a matter of adding a new context delimiter.

    Thoughts?
    Thanks!

    advanced templating #def. bug

    {{##def.snippet:param:
    test {{param.t}}====
    #}}
    
    {{#def.snippet:{t:234}}} 

    then, Template has an error: SyntaxError: Unexpected token :

    bug set is OK

    {{#def.snippet:{t:234} }} 

    Consider using array concatenation to speed up older browsers

    I've found that I can get a substantial speed increase on older browsers such as IE7 by using array concatenation in the output template function instead of string concatenation. In one instance, it decreased the render time from upwards of 60 seconds to around 4 seconds on IE7 (all other browsers were essentially instant with either). Changing the output function to use arrays did not seem to have an adverse effect on the newer browsers either, but it could easily be made into a configuration option. The append setting did not seem to help with render speed on IE7.

    Use:
    var out = []; out.push(...);

    Rather than:
    var out = ''; out += '...';

    Mixed defines in shared include.

    I am attempting to use doT for a multi-processor messaging application that is sending emails. Most emails include the same header partial, with only the title being variable. I just noticed, while sending three different emails, that the titles are getting mixed up.

    Following the advanced snippet, this is how I wired up the top part of my template:

    {{##def.sTitle:
    Welcome!

    }}

    {{#def.loadfile('/message/email/partials/header.dot')}}

    The 'Welcome!' is not consistently being displayed in the welcome email if other templates are simultaneously being processed. How can I set a variable in a limited scope so that my header always prints out the right thing?

    arrays/external template

    Hello,

    Im having some issues when using array iteration and external templates. I have the following code:

    main_template:

    {{#def.tpl_brother1 = def.load('templates/brother.tpl')}}
    {{##def.tpl_brother2: <div>{{=brother.name}}</div>#}}
    
    <div>
    <div>{{=it.name}}</div>
    <div>
        {{~it.brothers :brother}}
            {{#def.tpl_brother2 || 'not found'}}
        {{~}}
    </div>
    </div>
    

    data for the main_template:

    {
    "name" : "Jake",
    "brothers" : [ { "name" : "John" }, { "name" : "Brad" } ]  
    }
    

    when im using tpl_brother2 snippet works ok, i have access to "name" property of each brother. but when i use the tpl_brother1 snippet i get a error that i cant access "name" property...

    any suggestions to solve this?

    thanks
    aveiros

    Docs

    I can't seem to find the documentation. The readme leaves a little bit too much to the imagination. Is there more documentation somewhere?

    Reference grunt-dot-compiler

    Hi @olado !

    I'm the author of grunt-dot-compiler(http://github.com/tinganho/grunt-dot-compiler). Many front-enders use Grunt to execute different tasks. So I created grunt-dot-compiler which compiles dot templates for ready to use both in the client and in Node. I will add Go in the near future.

    So I wonder if you could put a comment about it in your dot website and your git repo?

    Access to flash messages

    Hi,
    I am trying to see if I could use doT from with in the express environment. I would like to use expresses 'dynamicHelpers' and have access to the session context from within doT. Alternatively, if I want to have access to the flash messages, what is the best way to pass them to doT.

    Thanks

    Bower repository version tags

    Hey olado!

    I'm using doT with bower to manage versions, however it seems that the doT tag that is included is only for version 0.2.0 rather than the recent 1.0.0 version.

    Any chance that you can add the 1.0.0 tag to the repository?

    Thanks a bunch

    the question of the doT load sort

    hi ,everybody!
    when i use doT template frame in my web page,
    and ,when i use some code for getting the value of the html by doT maked,
    but my own code run faster than the doT code, so i can not get the value or bind event ,so ,who can help me?

    More on docs

    I wrote up some docs for doT. Do these look largely correct?
    
    -------
    
    doT is a JavaScript package that supports runtime expansion of string templates.
    It was inspired by templating functions from jQote2.js (a jQuery plugin) 
    by aefxx (http://aefxx.com/jquery-plugins/jqote2/)
    and underscore.js (http://documentcloud.github.com/underscore/).
    
    You can find doT at https://github.com/olado/doT
    It was created and is maintained by Laura Doktorova.
    It is licensed under the MIT license.
    
    The doT package:
         doT.template(template, templateSettings, defininitions) - Function
            template = string (or stringifiable object) representing the template to be compiled.
            templateSettings = associative array that defines various compiler settings (see Template Settings)
            definitions = associative array accessed using the 'def' directive in templates
                        these are intended to support interpolation at template compile time
                        (note: examples imply this contains functions such as loadFile by default. It does not.
                         That example assumes the function loadFile is available in the current JavaScript context.)
    
             Compiles the given template and returns a function that can be used to expand that template on demand.
             The resulting function takes one argument, whose name may be changed using Template Settings:
                 it = an associative array of values that may be referenced during expansion of the template
              
          doT.templateSettings - associative array
              evaluate = regular expression used to locate and replace runtime evaluations in the template string
              interpolate = regular expression used to locate and replace runtime interpolations in the template string
              encode = regular expression used to locate and replace runtime interpolations which will be HTML encoded 
                      prior to insertion in the template string
              use = regular expression used to locate and replace compile time interpolation in the template string
              define = regular expression used to locate and replace compile time variable definitions in the template string
              varname = the name of the single argument to the function produced by doT.template
                      this is the associative array referenced by runtime interpolation and evaluation
              strip = Boolean that controls whether or not end of line characters, CDATA tags, and comments 
                      will be removed from compiled templates
                      defaults to true
              append = Boolean that controls how interpolations are written in the compiled template.
                      The compiled template is just a JS function that binds a string to 'out'.
                      If true then interpolations are written as "+(\<interpolation\>)+", resulting in one long string concatenation.
                      if false then interpolations are written as ";out+=(\<interpolation\>);out+=", resulting in a series of 
                              separate concatenations.
                      In some browsers, options one will be faster while option two will be faster in others. The choice is left to the user.
                      Note: I believe the second case will break if two interpolations are placed with no characters between them. Check.
                      defaults to true
    
    Some definitions:
         template - a string containing directives that fetch values from the JavaScript environment in order to construct a new string
                      this can be used to dynamically construct portions of your web page using values fetched, for example, using AJAX calls to a service.
         interpolate - to add text to either the template itself at compiletime or to the expanded string at runtime
         evaluate - to execute a bit of JavaScript and use the value returned
         expansion - the process of taking each of the directives in a template and performing the task it specifies
                      the results are inserted into the result string in place of the directive
                      because the results are often larger than the directives themselves, we think of this as expanding the template 
                              into the result
         HTML encode - sometimes strings contain letters (characters) that have special meanings in HTML
                      HTML encoding such a string marks those letters such that a browsers will just display the letters and not treat 
                              them as directions
    
    doT directives:
         compiletime definition = evaluate code at compile time and store in the 'definitions' associative array
                     Note that the 'definitions' are only available at compiletime (via the 'def' variable in JavaScript)
                          so these values will be consumed by 'use' directives, presumably
                     default syntax has several options:
                                "{{##<definition>:<value>}}"
                                "{{##def.<definition>=<value>}}"
    
                     if the 'definitions' argument passed to doT.template does not contain an entry that matches <definition>
                          if our assignment character is ':' we set definitions[<definition>] to the string <value>
                          if our assignment character is '=' we evaluate <value> in the current JavaScript context and set 
                                  definitions[<definition>] to that value
                     The 'definition' directive is removed from the template and no new text is inserted in its place. 
                     The 'definitions' associative array is exposed as 'def' in the current JavaScript environment for 'use' directives.
                     Authors may rely on 'definition' and 'use' directives being evaluated in the order they occur in the template.
                     
                     Note:
                     The examples supplied actually cannot all be parsed by default (they lack the assignment character and value).
    
          compiletime use = interpolate at compiletime, with recursive expansion of 'definition' and 'use' directives.
                      default syntax:
                              "{{#<code>}}"
                      Evaluates <code> in the current JavaScript context.
                           if <code> is not undefined, recursively expand 'definition' and 'use' directives that might be found in that string.
                           call toString() on other types of objects returned before performing this expansion.
                      The resulting string is inserted into the compiled template in place of the 'use' directive. 
                      Authors may rely on 'definition' and 'use' directives being evaluated in the order they occur in the template.
                      The 'definitions' associative array is exposed as 'def' in the current JavaScript environment.
                      Note: there is no attempt to prevent infinite recursion. A recursion counter would be a VERY VERY good idea.
                      
          runtime interpolate = evaluate code in the current JavaScript context and insert the value returned into the resulting string 
                      default syntax:
                              "{{=<code>}}"
                      Evaluates <code> in the current JavaScript context. 
                      The result is inserted into the result string in place of the 'interpolate' directive.
                      Note: the code is evaluated after all other runtime directives have been expanded into code.
                      All runtime code is then evaluated en masse. One should not count on these being evaluated in order
                             as that assumption is subject to the whim of the JavaScript interpreter. 
    
          runtime encode = evaluate code in the current JavaScript context and insert the value returned into the resulting string 
                      default syntax:
                              "{{!<code>}}"
                      Evaluates <code> in the current JavaScript context. 
                      The result is first HTM encoded (lightly) then  inserted into the result string in place of the 'encode' directive.
                      Note: the code is evaluated after all other runtime directives have been expanded into code.
                      All runtime code is then evaluated en masse. One should not count on these being evaluated in order
                             as that assumption is subject to the whim of the JavaScript interpreter.
    
          runtime evaluate = evaluate code in the current JavaScript context but DO NOT insert the value into the result string 
                      default syntax:
                              "{{<code>}}"
                      Evaluates <code> in the current JavaScript context. 
                      The result is NOT inserted into the result string. 
                      The strings resulting from 'print' calls in <code> WILL be inserted into the result string in the order they occur.
                      The 'evaluate' directive is removed from the result string.
                      Note: the code is evaluated after all other runtime directives have been expanded into code.
                      All runtime code is then evaluated en masse. One should not count on these being evaluated in order
                             as that assumption is subject to the whim of the JavaScript interpreter.
    

    how to loop?

    hi, i need to loop output, can doU do it? thanks

    custom delimiters fail in attributes

    Thanks for the customizable delimiters. Unfortunately, custom delimiters do not work in attributes

    <li class="<?= class ?>" />
    

    while the default delimiters pass

    <li class="{{= class }}" />
    

    Support for literals is missing?

    It seems like there's no way to add literal text that would otherwise get interpreted as template tags.

    For example, I'm using node.js + Backbone and would like to use doT as the template engine for the client and server side, so I've got a template that has something like this in it for the client:

    <script type="text/x-dot-template" id="choice-template">
        <ul>
            {{~ it.question.choices :choice}}
            <li>{{=choice.get("label")}}</li>
            {{~}}
        </ul>
    </script>
    

    I don't want those script tags to be interpreted by doT on the server-side, because they're meant for the client-side to consume, but there doesn't seem to be a way to tell doT not to process parts of a template.

    Do not let interpret doT numbers as integer, but as string

    {{=it.number1}}{{=it.number2}}

    evaluates to var += (it.number1)+(it.number2); which results in var += (it.number1 + it.number2);. It then concatenates the resulting number to var, which is bad.

    Please evaluate it as var += String(it.number1)+String(it.number2); โ€” this is what users really want, I think.

    Quick fix: change the lines 46 - 49 from:

        var startend = {
            append: { start: "'+(", end: ")+'", endencode: "||'').toString().encodeHTML()+'" },
            split: { start: "';out+=(", end: ");out+='", endencode: "||'').toString().encodeHTML();out+='"}
        }, skip = /$^/;

    to:

        var startend = {
            append: { start: "'+String(", end: ")+'", endencode: "||'').toString().encodeHTML()+'" },
            split: { start: "';out+=String(", end: ");out+='", endencode: "||'').toString().encodeHTML();out+='"}
        }, skip = /$^/;

    Pasing argument to partial template (#def) ?

    In the advanced examples you define a snippet like:

    {{##def.snippet1:
        Some snippet that will be included {{#def.a}} later {{=it.f1}}
    #}}
    

    I was wondering if it was at all possible to substitute "it" for that snippet.
    Given the following example:

    {{##def.row:
    {{=it.Title}}
    #}}
    
    <ul>
        {{~ it.Nodes :p}}
        <li>
            {{#def.row}}
            <ul>
                {{~ p.Nodes :s}}
                    <li>
                    {{#def.row}}
                    </li>         
             {{~}}
             </ul>
         </li>
         {{~}}
      </ul>
    

    Now the idea would be to print "p.Title" for the first level and then "s.Title" for the second level, but re-use the same template for both elements...

    Also would it be possible to make the above recursive somehow?

    <div>undefined</div>

    Apologies if this is something I should have been able to find by searching the issues. I did triy and did not find an answer to my question. Can I not use the word "undefined" in a div, span, p, etc? For example, why can't I do this in an expressjs app.

    var tempFn = doT.template(<div>undefined</div>);
    var html = tempFn({});
    res.send(html);

    I get the following error.

    Express
    500 SyntaxError: Unexpected identifier
    at Object.Function (unknown source)
    at Object.template (/usr/local/lib/node/.npm/dot/0.1.7/package/doT.js:91:11)
    ...

    There might be a legitimate use for the word "undefined." Thanks.

    Chris

    Start tagging releases

    Hi olado!

    I'm using doT in several projects and I use bower to manage packages.
    Bower integrates with github but they use tags to interpret versions.

    Can you please start tagging updates using the semantic version schema? e.g.: 0.0.1

    Thanks in advance!

    Move dot-packer to a separate npm package

    Shouldn't the packages used in dot-packer be listed as dependencies on package.json?

    These are: commander, mkdirp and uglify-js. Now listed as dev dependencies.

    "dependencies": {
      "commander": "*",
      "uglify-js": "*",
      "mkdirp": "*"
    },
    "devDependencies": {
      "mocha": "*",
      "jshint": "*"
    }
    

    I couldn't start using dot-packer right away after installing dot via npm.
    I had to run 'npm install' on the node_modules/dot folder to get these installed,
    but also mocha, jshint which you don't need if you're not developing.

    Support for partials?

    Hello, first of all congratulations for the excellent work and lightning fast engine:

    One thing I've being trying is to port the concept of partials, like in mustache {{> partial_name}}, but it seems that it doesn't interpolates the result.

    var data  = {
        name: 'John', 
        details : {age : 27},
        partial : "<p>Hello again {{= it.name}}</p>"
    };
    
    doT.template('Hello {{=it.name}}, you are {{=it.details.age}} years old! {{= it.partial }}')(data)
    
    //outputs...
    // Hello John, you are 27 years old!
    // Hello again {{= it.name}}

    As you can see the partial is not interpolated, so I was wondering if its possible to have this using doT?

    perhaps something like mustache or handlebarsjs where I can do the following:

    dot.template('...')({data: {...}, partials : {...}})

    Thanks again :)

    New features & improved extensibility

    I have made a lot of changes to doT. Most important are built-in caching, autoloading, included templates (not snippets, indeed it's like {{=dot.template(other_tmpls_code, some_data)}}), dynamic templates (a little bit more complex), and optional with wrapper for function body (everybody likes write {{=name}} instead of {{=it.name}}).
    There are just too much commits, I would not be able to create PR for each feature. If you want I'll create PR with all the stuff.
    You can take a look at some explanations and examples in my fork.

    PS. Performance is still just great.

    Including files in templates

    I have a few questions concerning doT used along with node.js and express.js:

    i18n is working without problems along with doT, but when I wanted to separate the template in - what other
    templating engine would call - "blocks", I ran into problems. As far as I am aware doT doesn't support "blocks",
    but in theory it's supposed to be capable of including files.

    I am rendering my templates using the usual express.js way:

    res.render('test.html', {pageTitle:"Test"});
    

    But how can I add stuff to the default defines? To do stuff similar to the advanced example, without doing this
    within a template:

    {{#def.loadfile(...)}}
    

    I am aware about the partial support, but I need to get a partial in my context first, without redefining it in every template.

    Thanking you in anticipation,
    Niklas Voss

    is there support to prevent a partial from being parsed?

    Hi there. I'm really stoked about using your rather simple (and apparently lightning fast) templating module. However, I'm wondering if there's any way to prevent a partial from being rendered. What I want to do is create a template for a web app that bootstraps a bunch of templates to be compiled in the future (with browser-side doT):

    <html>
        <body>
            <h1>{{=heading}}</h1>
        </body>
        <script type="text/html" id="mysnippet">
            {{#def.mysnippet}}
        </script>
    </html>

    If def.mysnippet consists of

    <p>{{=it.mytext}}</p>

    then, after compilation, the script element in the template should look like

    <script type="text/html" id="mysnippet">
        <p>{{=it.mytext}}</p>
    </script>

    hence, the {{=it.mytext}} should be unparsed so it can be sent along to the client, which can then pull it from the DOM and compile its own templates.

    If there's no such facility I could fork the code and see if I could implement it.

    Thanks in advance!
    Paul

    Inappropriate Partial Template Parameter Replacement

    If you have a partial with parameters, all instances of the parameter name get replaced in the output even if they aren't surrounded with templating syntax (such as interpolate):

    {{##def.sayhello:greeting:
    <div class='greeting'>{{=greeting}}</div>
    #}}
    
    {{#def.sayhello:it.something}}
    

    will produce:

    function anonymous(it) {var out='<div class=\'it.something\'>'+(it.something)+'</div>';return out;}
    

    instead of:

    function anonymous(it) {var out='<div class=\'greeting\'>'+(it.something)+'</div>';return out;}
    

    Semantic delimeters as an alternative

    Hi,
    I know you provide the option the change the delimeters to whatever we please. But, I was struggling to get a working example together since the regex is difficult (for me at least) to swallow. Specifically the iterate and conditional delimeters are particularly complex.
    Basically, to help ease the learning curve and increase readability at the expense of longer delimeters I was trying to create more semantic aleternative
    [if, else, endif] in place of [?, ??, ?]
    [loop, endloop] in place of ~
    use instead of #
    define instead of ##
    With the hope that it will make reading the templates easier and understandable in the absence of documentation.
    Do you think you could help post an alternative?
    Thank you very much in advance!

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google โค๏ธ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.