GithubHelp home page GithubHelp logo

Comments (16)

aredridel avatar aredridel commented on July 18, 2024 1

Aah, yes. try app.engines.dust. That should be an adaro instance.

from adaro.

kurdin avatar kurdin commented on July 18, 2024 1

@aredridel looks like this works: app.engines['.js'].dust

from adaro.

aredridel avatar aredridel commented on July 18, 2024 1

Ah, you're using precompiled templates. Yeah, in that case, what you did.

from adaro.

grawk avatar grawk commented on July 18, 2024

Adaro wraps dust and overrides its "onload" method. It also exposes an express-compatible View engine. In a typical makara2 installation, makara loads adaro under the hood, and becomes the primary point of contact with it. But that's basically for convenience. You could probably do something like store your shared dust configuration somewhere in your config.json, and pass it both to makara as well as your own dust instance. But, outside of express view rendering, I'm not sure I'd try and use adaro directly.

from adaro.

kurdin avatar kurdin commented on July 18, 2024

The problem is I don't want to load all helpers and templates in 2 different dust instances, it does not make any sense. I understand the need of overriding it's "onload" method but why not to provide special method to return instance of dust from adaro? In my local copy of adaro, I was able to do this by creating getdust method in lib/engine. Something like that:

var dust;
exports.create = function (type, config) {
...
dust = freshy('dustjs-linkedin', function (dust) {
...
};

exports.getdust = function(){ 
    return dust;
};

This is not prefect coding but it works. Maybe you can provide similar method in more elegant way because I am sure, this will be needed by many devs, and this is a better way then share same configuration, templates and helpers between kraken-js dust and adaro.

from adaro.

grawk avatar grawk commented on July 18, 2024

I see why that works and how it could be helpful. But at the same time, you are still beholden to adaro having been properly set up by the initialization of the kraken app. I personally would be more comfortable using a separate dust instance from adaro for that reason alone. But let me hang back and see if anyone else cares to comment as to the feasibility and likelihood of implementing your proposal.

from adaro.

kurdin avatar kurdin commented on July 18, 2024

I don't see how getting dust instance from adaro can be bad thing, it is just extra feature and sharing dust was working fine before adaro 1.x

@grawk thanks for your time.

from adaro.

aredridel avatar aredridel commented on July 18, 2024

Are you aware of https://github.com/krakenjs/adaro/blob/v1.x/lib/engine.js#L176?

dust is exported by the engine object. However, you have to get it through express, not through requiring dustjs -- adaro is explicitly dependent on express to do some setup work, to tie the loader to the express view engine. Look in the tests and you should find examples of dust being accessed.

If you need a dustjs separate from express, you'll want to require it separately and configure it yourself. All the parts should be available to you.

Part of this is because you can mount two kraken apps together in the same process, each with different view and rendering configurations. Shared dust instances break this in very hard to debug ways.

from adaro.

skicomdev avatar skicomdev commented on July 18, 2024

@aredridel I could not find any express method where I can get engine object back from app in controller. All I can see from tests is set not get method.

Again, I am fine with shared dust instances I understand all benefits but all I need is someway to reuse dust used by adaro to build template separately from express.

from adaro.

aredridel avatar aredridel commented on July 18, 2024

Do be aware that if you're using this with the full kraken suite and makara@2, that will not be valid until the server has processed its first request.

from adaro.

kurdin avatar kurdin commented on July 18, 2024

Yeah, app.engines has 2 props .js and .dust for precompiled template and raw dust files.

engines: 
   { '.js': { [Function: engine] settings: [Object], dust: [Object] },
     '.dust': { [Function: engine] settings: [Object], dust: [Object] } },

Do be aware that if you're using this with the full kraken suite and makara@2, that will not be valid until the server has processed its first request.

Looks like you can access dust in index.js middleware:before:route in you use kraken.

app.use(kraken(options));

app.on('middleware:before:router', function () {
    dust = app.engines['.js'].dust;   
    dust.config.whitespace = true; // preserve white space in templates

but would still prefer to get dust directly from adaro method like this:

app.on('middleware:before:router', function () {
    dust = require('adaro/lib/engine').getDust();
    dust.config.whitespace = true; // preserve white space in templates 

from adaro.

aredridel avatar aredridel commented on July 18, 2024

Yeah, that's not going to happen, because kraken supports multiple differently configured apps per process.

from adaro.

aredridel avatar aredridel commented on July 18, 2024

(an in general, that makes peerDependency relationships which just have that much more potential to make scenarios that don't work)

from adaro.

kurdin avatar kurdin commented on July 18, 2024

Yeah, that's not going to happen, because kraken supports multiple differently configured apps per process.

Looks like we talking about different things. I don't see how adding getDust method to adaro can hurt even if kraken supports multiple differently configured apps per process. I see reasons why you would isolate adaro's dust from it's parent system but there many use cases where you want to reuse same dust for different things, like rendering templates to html outside of express render engine.

Using dust = app.engines['.js'].dust; can help, but again, you need to check what configuration in what environment you using that extensions for templates js or dust.

from adaro.

aredridel avatar aredridel commented on July 18, 2024

Exactly the problem: you need an instance of adaro to get dust, because each can be configured differently. app.engines['.js'] is that instance, and so you are in fact getting dust from it that way.

from adaro.

grawk avatar grawk commented on July 18, 2024

Given that there are other ways to achieve what you want other than an accessor method to adaro's dust instance, I'm going to close this issue.

from adaro.

Related Issues (20)

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.