Giter Club home page Giter Club logo

dustjs's People

Contributors

aredridel avatar bgmort avatar bradestey avatar brianmhunt avatar carchrae avatar codeability-ab avatar danactive avatar fhlawaczek avatar jairodemorais avatar jasonbelmonti avatar jimmyhchan avatar jleppert avatar kate2753 avatar kilianc avatar kmiyashiro avatar lalitkapoor avatar leojuliand avatar nickstefan avatar oleics avatar patrick-steele-idem avatar paulmillr avatar prashn64 avatar rragan avatar sclatter avatar seriousmanual avatar sethkinast avatar smfoote avatar sumeetkakkar avatar theinfosecguy avatar vybs 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

dustjs's Issues

Global alias or how to pull a block

I'm trying to write a
base template with blocks witch after in a
child template to reuse only some blocks from the base template and I followed global alias help for dust
but when I use them with partial doesn't want to work.

greeting.dust

{<greeting}Hello, Hola{/greeting}   
{<world} Us, Spain{/world}

partial_end.dust

{#names}
  {.} {+greeting/}
{/names}

{#projects}
  {.} {+greeting/}
{/projects}
{>greeting_template/}

partial_begining.dust

{>greeting_template/}
{#names}
  {.} {+greeting/}
{/names}

{#projects}
  {.} {+greeting/}
{/projects}

In only one file it works like this:

greeting_begining.dust

{<greeting}Hello, Hola{/greeting}   
{<world} Us, Spain{/world}
{#names}
  {.} {+greeting/}
{/names}

{#projects}
  {.} {+greeting/}
{/projects}

but I need to separate the blocks in other files.
Can some one help? I there any other way of doing this?
If now there is an real issue with this maybe I can contribute to dust and try to fix this.

PS: from the main examples it seem that blocks are global when included from partials, but this is the other way around.

The stringify filter produces escaped results

I'm not sure if this is intentional, but the output from the stringify (js) filter is HTML escaped. For example, given this template:

{foo|js}

And the following JavaScript:

dust.render("my-template", {foo: {bar: "baz"}}, function(err, out) { console.log(out); });

The console will show:

{&quot;bar&quot;:&quot;baz&quot;}

This might be useful for display on a webpage, but I'd argue a far more common use case for this filter is making server-side data available to client-side JavaScript (e.g. embedding JSON data in a script tag). For example:

<script>
  var foo = {foo|js|s};
</script>

Note that to make the above code work, I had to add a second s filter. This is confusing and unexpected, so my vote is to make unescaped the default for the stringify filter.

Fix inconsistency in resolving dust reference

given JSON

{
  "person": {
    "name": "Larry",
     "age": 45
 },
 "another": {
 in : {
  "name": "Tommy",
  "age": 44
  }
 }
}



  {#person}
    {name}, {age}
      {#another.in} // it is not a block, it is looking for local path, inside of person context
      {name}
      {age}
     {/another.in}
  {/person}

Expected : The above should work and output the data within the block. "another"
Observed: It does not output Tommy 44, instead only Larry 45 is shown

Alternatively,

The following works,

   {#another.in}
     {name}, {age}
   {/another.in}

why? since another is the top level block in the above example, using the . operator works. Any sub contexts using .operator do not work.

The only way to make the above work is reference a subcontext children is via creating a # context

 {#person}
   {name}, {age}..
  {#another}
   {#in}
     {name}
   {age}
  {/in}
 {/another}

{/person}

Related to the dust grammar relaxing whitespace

We should allow new line, tab in place of white space?

Atleast support this for inline params

test case

{#pubAuthors
paramName="pubAuthors"
formName=name
defaultContributorFirstName=defaultContributorFirstName
defaultContributorLastName=defaultContributorLastName
coContributors=coContributors
isRequestSecure=isRequestSecure
memberId=defaultAuthorId
maxNumberOfAuthors=maxNumberOfAuthors
addText=i18n_publication_author_add
removeText=i18n_publication_author_remove
maxReachedText=i18n_publication_author_max_reached}
{>"tl/apps/profile/v2/partial/contributors_input"/}
{/pubAuthors}

dust.js 0.6.0 client fails to compile template correctly.

Steps to reproduce:

<script src="https://raw.github.com/linkedin/dustjs/master/dist/dust-full-0.6.0.js"></script>

<script>
    $(function() {
            var compiled = dust.compile("Hello {name}! You have {count} new messages.", "modal");
            console.log(compiled);
    })  
</script>

Expected Output

(function() {
  dust.register("demo", body_0);

  function body_0(chk, ctx) {
    return chk.write("Hello ").reference(ctx.get("name"), ctx, "h").write("! You have ").reference(ctx.get("count"), ctx, "h").write(" new messages.");
  }
  return body_0;
})();

Actual Output

(function(){dust.register("modal",body_0);function body_0(chk,ctx){return chk.write("Hello ! You have  new messages.");}return body_0;})(); 

Notes:

As you see in the actual output, there is no reference to the context as all, so when I push context in, it will still render "Hello ! You have new messages.`

Extend dust to support Array reference

proposal from @eranl

Works both server side and client side, without any helpers. The idea is to extend the dust expression syntax to support array element entry using brackets (e.g. {a[2].b} ). It's a natural extension of dust.

So your code would look something like:

{#actors}
{@somehelper key="formattedName" type="name.full" args="first:{fn}, last:{ln}"/}
{/actors}

{@anotherhelper key="twoNames" text="{actors[0].formattedName} and {actors[1].formattedName} blah"/}

Use the tap method in the select helper

Today select helper does not support resolving of parmeters before comparing to the eq.lte ...etc

use the tap method to resolve the value, and then compare.

Dust tags generate extra whitespace in HTML

Extra whitespace is generated by Dust tags. This is especially a problem within HTML attributes like "title" for anchor tags, etc.
E.g., I have to remove all line breaks in my TL file like so

{<distanceStr}{@pre.fmt render="false" key="degree_icon_2__text_plain__formatted_name" type="name.full" args="first:{fNameP},last:{lNameP}"/}{@pre.i18n key="degree_icon_2__text_plain__NAME_is_2nd_degree_contact_key" text="{degree_icon_2__text_plain__formatted_name} is a 2nd degree contact"/}{/distanceStr}

otherwise additional white space is created in the rendered output.

losing 'this' context in handlers?

This problem exists in both akdubya's dust (0.3.0) and in your dust (0.4.0.) Since it seems 0.3.0 is no longer being maintained, I thought it prudent to ask here. (Thank you for taking this project on!)

I have also posted this question over on SO (http://stackoverflow.com/questions/10339297/dust-js-losing-this-context-in-handlers)

I hope someone will be able to point me in the right direction.

I have a [seemingly] trivial dust.js template. The context object I am using to render the template contains a handler which references another item in the context object. I also include a toString handler, which also references another item in the context object.

Template:

{error}
<pre>
{#error.getStackTrace}
{.}{~n}
{/error.getStackTrace}
</pre>

Context:

{
  error: {
    st: ['a','b','c'],
    msg: 'This is an error message',
    getStackTrace: function () {
      return this.st;
    },
    toString: function () {
      return this.msg;
    }
  }
}

Rendered:

This is an error message<pre></pre>

If I reference {#error.st} directly, it renders correctly:

This is an error message<pre>a
b
c
</pre>

If I inspect 'this' inside of the getStackTrace() handler, it is pointing back to DOMWindow. It is interesting, however, that invoking toString() implicitly, it is scoped correctly. If I explicitly invoke toString() {error.toString}, then the scope jumps back to DOMWindow.

The only reason this is a problem, (why I cannot access error.st directly) is because the st array is actually stored in a Qooxdoo property, and I only have access to the generated getter. The above example mimics the actual object as simply as I can, and yield the same results.

Is this a bug in dust.js? Is it losing the correct scope in handlers? Or am I missing something in the dust.js docs to retain scope?

Thank you!

Mobile Safari iOS 4.2.1 Parse Error on If helper

Mobile Safari on iOS 4.2 breaks on the 'if' helper method due to Parse error, most likely because "if" is a reserved word. Although it works in 5.0+, simply quoting the method name would fix this.

Support generating inline partial blocks in a list

Child template

{>base_template/}
  {#loop}
          {<"var_{$idx}"}
          {/"var_{$idx}"}
  {/loop}

Base template

  {#anotherloop}

          {+"var_{$idx}"}

  {#anotherloop}

for instance looping a list of items and each iteration of the item in a child template creates a different inline partial block ,

so this means a array.list of inline partial blocks can be created as we iterated.

Once created, we can reference the indexed inline partial block in the base template

is this good?

Allow "variable" {+name/} to appear in inline param value

Users view {<name}value{/name} as the definition of a variable value. Currently the can reference it via {+name/} and the value will be output. The compiler will not accept usages like {@ helper param="{+name/} /} so there are a lot of places where the variable cannot be used that one might want to use it.

Relax the compiler grammar to allow a "variable" to be passed via an inline param.

Update linkedin fork of dustjs on jsperf and a the public page

@jairodemorais

Milestone 1.1

We should add a "js perf" test for our fork of the dust to make sure we are not slowing down the dust core

Second, the test.html we have, we should figure out how to expose it as a public page ( like we the original dustjs site exposed )

I have noticed that some of unit tests can be renamed to better documented to express the test case/ feature it is testing

Support/relax syntax for inline params

{#helper name="Dialog" config="{
'name' : 'index' }
"}
{/helper}

The following is already supported

{#helper name="Dialog" config="{ name: 'index' }"}
{/helper}

Empty array section keys not resolving to falsy value? (Update Docs)

From the docs at http://akdubya.github.com/dustjs/#guide :

Dust outputs nothing if the friends key is empty or nonexistent. Let's change that by inserting an {:else} tag, which tells Dust to render an alternate template block when a section key resolves to a falsy value:

Template:

<ul>
{#friends}
    <li>{name}, {age}{~n}</li>
{:else}
    <p>You have no friends!</p>
{/friends}
</ul>

Context:

var context = {
    friends: [
        { name: "Moe", age: 37 },
        { name: "Larry", age: 39 },
        { name: "Curly", age: 35 }
    ]
}

This renders html as expected:

<ul><li>Moe, 37
</li><li>Larry, 39
</li><li>Curly, 35
</li></ul>

However if we change the friends array to be empty,

var context = {
    friends: [ ]
}

the {:else} block does not trigger, we are instead left with an empty

    element. Removing the friends element entirely will cause the {:else} block to render as expected.

    Is this expected behaviour i.e. is my interpretation of "Dust outputs nothing if the friends key is _empty_ or nonexistent" incorrect?

    I'm using dust-full-0.6.0.js and compiling these in the browser.

    Thanks,

    Improving test coverage for the version 1.0 release

    there is a lot of room for improvement on jasmine tests and code coverage.

    We would like to publish a code coverage report automatically henceforth

    Secondly, add automated IE browser tests if possible.

    Npm package

    Is there going to be a npm package?

    I would find it extremely useful rather than having to update through git.

    Generic helper parameter parsing

    The "if" helper currently parses it's own parameters but we need a generic way of doing so for custom helpers.

    I've currently written two functions that i use in my own projects, maybe you could add a dust.parseParemeter or something similar.

    /* Replaces {variable} with it's value
    * Example : {@Lang key="items.{id}.title" extraparam="{amount}"/}
    * Inside my "Lang" helper :  var key = TemplateFillters.renderParameter("key", chunk, context, bodies, params);
    */
    renderParameter: function (name, chunk, context, bodies, params) {
        if (params && params[name]) {
            if (typeof params[name] === "function") {
                var output = "";
                chunk.tap(function (data) {
                    output += data;
                    return "";
                }).render(params[name], context).untap();
                return output;
            } else {
                return params[name];
            }
        }
        return "";
    },
    
    /* Same but also executes javascript in {{code}}. Uses a function and not eval.  */
    execParameter: function (name, chunk, context, bodies, params) {
        var output = "", pending = false, code = "";
        if (params && params[name]) {
            if (typeof params[name] === "function") {
                chunk.tap(function (data) {
                    if (data.indexOf("{") >= 0 || data.indexOf("}") >= 0) {
                        if (data.indexOf("{") >= 0) {
                            output += data.substring(0, data.indexOf("{"));
                            pending = true;
                        }
                        if (data.indexOf("}") >= 0) {
                            code += data.substring(data.indexOf("{") + 1, data.indexOf("}"));
    
                            var exec = new Function ("chunk", "context", "bodies", "params", "return (" + code + ")");
                            output += exec(chunk, context, bodies, params);
                            code = "";
                            pending = false;
    
                            output += data.substring(data.indexOf("}") + 1);
                        } else {
                            code += data.substring(data.indexOf("{") + 1);
                        }
                    } else {
                        if (pending) {
                            if (!isNaN(data)) {
                                code += data;
                            } else {
                                code += '"' + data + '"';
                            }
                        } else {
                            output += data;
                        }
                    }
                    return "";
                }).render(params[name], context).untap();
            } else {
                output = params[name];
            }
        }
        return output;
    }

    Helpers should allow self-closing tag

    You cannot write a helper of the form {@Helper params /}. You have to write {@Helper params}{/helper}. Granted, some use cases favor the begin/end tag pattern, but there are others where no contained body is wanted or needed. Please consider a compiler change to allow a self-closing helper.

    Filter is not invoked on empty variable (or empty list)

    I've constructed a filter that outputs the number of items of a submitted list:

    {list|size}

    When the list is empty, the filter is not invoked, instead the placeholder is replaced by an empty string.

    Would be helpful to leave it to the filter function to decide what is to do in that case.
    (e.g. returning 0 in the size case)

    No result when running tests on server

    When I'm running the serverside jasmine test-suite I'm always getting this result:

    [zap@meg server]$ node specRunner.js
    undefined
    
    Finished in 0.006 seconds
    0 tests, 0 assertions, 0 failures
    

    This happens on my Windows7 machine as well as on every other Linux Server I ran it.

    Am I missing a dependency?

    The client side tests are running well.

    Add the tap support for the select helper

    refactor the if helper and abstract the "chunk.tap" to its own helper

           /**
         * Utility helping to resolve dust references in the given chunk
            */
         var tap = function( input, chunk, context ){
            // return given input if there is no dust reference to resolve
            var output = input;
            // dust compiles a string to function, if there are references
            if( typeof input === "function"){
              output = '';
             chunk.tap(function(data){
              output += data;
             return '';
             }).render(input, context).untap();
            } 
           return output;
         }
    

    --track-line-and-column for the peg.js parser args

    can we use the

    --track-line-and-column
    Makes the parser track line and column (available as line and column variables in the actions and predicates).

    isn't this useful for tracking line and column numbers.

    Need $counter or a startsIndex parameter for loops

    Outputting
    1 2 3
    is not possible at the moment.

    $idx provides a zero indexed value but there is no way to add 1 using logicless dust

    Proposal:
    Add a $counter variable

     {#loop}
       {$counter}
     {/loop}
    

    Allow loops to have a special parameter startsIndex

     {#loop startsIndex=1}
        {$idx}
     {/loop}
    

    Partial parameter passing issue

    But,
    {>"embed" test="FOOOO"/}
    {>"embed" test="BARRR"/}

    The above works fine

    Now, I tried
    {>"embed" test="FOOOO"/}
    {>"embed" test="BARRR"/}

    {>"embed" test="{foo}"/}
    {>"embed" test="{bar}"/}

    This prints the value of bar in the json, in all 4 cases.

    Compile Templates

    Hey All,

    We are using the https://github.com/akdubya/dustjs version of dust js in our grails project and we would like to move to the linked in version of this project.

    The problem is we created a plugin to precompile templates, which evals a slightly modified version of the dust-full.js file. This works fine. But due to the linkedin version hijacking the 'if' reserved word for the builtin helpers you can't eval the script. The code that is evaling the script in the plugin can be found here: https://github.com/zlegein/dustjs-plugin/blob/master/grails-app/services/DustjsEngineService.groovy

    Is there a workaround for this or can you think of a way we can do this with the linkedin. I realize using node would be one way of doing this, but I don't see why we need node just for this.

    Thanks,
    -zach

    Add /update options to peg parser

    With recent update to a new pegjs version,

    cache=true is not good as the author seems to indicate.

    Hence refactor the parser not to rely on the same. Fix any grammar dependencies.

    Try to use -track line and column option for cleaner error reporting

    Improve the dust compile times

    Although not critical, since we always serve precompiled templates from CDN, it would be interesting to investigate why the compile time for a sufficiently large template is high with peg.js

    It may benefit our dev on the fly compile timings. Not a issue in prod, since we only serve the precompiled template to browser in prod.

    Relax dust grammar for supporting spaces

    Investigate to alter the dust grammar to support arbitrary space ..

    Now Invalid gramar

    {#a root1="p1" r2="p2" }

    {/a}

    Compare the syntax with handle bars or mustache and see how they do it ?

    make global context (makeBase) global by default

    currently you can essentially define all your global contexts and helpers when you define makeBase, but in order for the global helpers and contexts to be accessible during rendering, you'd have to do use base as the main context, using

    base.push({foo:bar})

    in your render method. this makes it verbose. my assumption is, if you've set stuff to global, then you'd want them accessible globally in all your templates, so doing the above might just be a hassle. if this is acceptable, i'll issue a pull request with fixes soon

    Modify the make command to not include the dust helpers by default

    Some have expressed that adding helpers for logic pollutes the logic-less ness of dust!

    We should make the if and select helper as an extension to the core dust.

    Is there a way to have a flag on the npm install to optionally include helpers such as if and select.

    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.