Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when block contains async helper #5

Open
Ndrou opened this issue Feb 23, 2015 · 2 comments
Open

Bug when block contains async helper #5

Ndrou opened this issue Feb 23, 2015 · 2 comments

Comments

@Ndrou
Copy link

Ndrou commented Feb 23, 2015

I have a bug when i put an async helper in a block :

    {@provide [optional params]}
      main block of dust
      {:block1}
       {@myAsyncHelper /}
    {/provide} 

It causes a problem with render method...

Any idea ?
Thanks in advance

@rragan
Copy link
Owner

rragan commented Feb 23, 2015

Send me your async helper to allow more exploration if you can.

@Ndrou
Copy link
Author

Ndrou commented Feb 23, 2015

Below my helper ;)

 dust.helpers.tr = function (chunk, context, bodies, params) {
        var key = dust.helpers.tap(params.key, chunk, context);
        var ns = dust.helpers.tap(params.ns, chunk, context);
        var filter = dust.helpers.tap(params.filter, chunk, context);

        if (!key){
            return chunk.write('No translate key');
        }
        if (!ns){
            return chunk.write('No namespace');
        }

        var locale = context.get('_locals.lng');

        if (!locale){
            return chunk.write('locale not found');
        }
        if (!i18n || !i18n.t){
            return chunk.write('i18n not found');
        }

        return chunk.map(function(chunk){
            i18n.t(locale, ns, key, params).then(function(value){
                if (filter){
                    var filters = filter.split('|');

                    for(var filterItem in filters){
                        value = dust.filters[filters[filterItem]](value);
                    }
                }

                return chunk.end(value);
            }).catch(function(err){
                return chunk.end("");
            });
        });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants