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

Configure kracken to use only X view engine #94

Closed
steve-lorimer opened this issue Jan 8, 2014 · 18 comments
Closed

Configure kracken to use only X view engine #94

steve-lorimer opened this issue Jan 8, 2014 · 18 comments
Assignees

Comments

@steve-lorimer
Copy link

I'm looking for pointers on how to disable the default dust and js view engines, and replace them with ejs.

I've seen from pull-request #61 that it is now possible to completely disable view engines.

However, I would like to disable dust and enable ejs

@pvenkatakrishnan
Copy link
Member

you would need to specify in the config "view engines" (the list of all possible engines you would like to use) and "express:view engine" in the config - and specify your module, that will provide the engine middleware to be used for view engine. From there you would have total control on rendering.

@pvenkatakrishnan
Copy link
Member

check this line out, as to how kraken sets view engine up... https://github.com/paypal/kraken-js/blob/master/lib/appcore.js#L124

@steve-lorimer
Copy link
Author

The problem is that kraken will always include dust and js by default. See https://github.com/paypal/kraken-js/blob/master/config/webcore.json#L23.

It is currently possible to opt out of all template rendering (see https://github.com/paypal/kraken-js/blob/master/lib/appcore.js#L76) by setting express:view engine to null.

However, as far as I can see, if you want any template rendering at all, there is currently no way to opt out of dust and js.

If you look at https://github.com/paypal/kraken-js/blob/master/lib/util/configutil.js#L244 you can see that nconf is configured with my app's custom config and then with the kraken defaults (webcore).

It is webcore which includes dust and js view engines, and there is no way I can see to remove them.

@pvenkatakrishnan
Copy link
Member

I am not sure it will if you specify "view engines" in your app's config. I think your app's view engines config will override the default in webcore.json.
DId you try specifying in your config, like

{
   "view engines": {
       "ejs": {
            "module": "myModule",
               "settings" : {<mySettings>}
       }
   }
}

@steve-lorimer
Copy link
Author

Yes, it is additive, so the above config will result in 3 view engines - dust, js and ejs.

Add the following line at https://github.com/paypal/kraken-js/blob/master/lib/appcore.js#L131

console.log(ext + ": " + JSON.stringify(meta));

@pvenkatakrishnan
Copy link
Member

ahhh then i think i know what is happening. DO you have i18n enabled and using makara ?

@steve-lorimer
Copy link
Author

I'm just using the default config as created by

yo kraken

I see that https://github.com/paypal/kraken-js/blob/master/config/webcore.json#L13 configures i18n by default.

That means https://github.com/paypal/kraken-js/blob/master/lib/appcore.js#L108 will get back a non-null string, and therefore https://github.com/paypal/kraken-js/blob/master/lib/appcore.js#L145 will pass and makara will be included.

What are your thoughts because I don't see how i18n config will have any affect on the multiple "view engines" entries?

@pvenkatakrishnan
Copy link
Member

When i18n is enabled, Inside makara, the view engine gets force switched back to js so that we can apply localization to the dust templates
https://github.com/paypal/makara/blob/master/index.js#L62
So this is what is probably overriding the engine that you are setting in your app config.

I think I see 2 issues:
1: Including view engines that were in webcore.json by default when the app overrides it (not sure if it was intentional and why)
2. When i forced switched off i18n, I am seeing some issues as well. Need to debug to figure out what that is. This I am guessing should be relatively simple.

@pvenkatakrishnan
Copy link
Member

To me it seems like fixing the above 2 is the right solve for your issue.
@totherik what do you think ?

@steve-lorimer
Copy link
Author

Ok, thanks.

So to get ejs template rendering to work I had to set "express:view engine" as well. I use .html extension for my ejs templates.

It looks as if this code (https://github.com/paypal/makara/blob/master/index.js#L62) will also break then? Not too sure as I'm not in front of my computer. I'll also dig deeper once back at my machine.

Thanks again

@pvenkatakrishnan
Copy link
Member

I am not sure either. But let me work on switching off i18n working first. That should solve the overriding your engine aspect.

@steve-lorimer
Copy link
Author

I'm in front of my computer now...

It turns out for my use case (parse .html extensions as ejs templates), the logic here https://github.com/paypal/makara/blob/master/index.js#L62 won't get invoked.

That is because views does not have property html - only dust and js (see https://github.com/paypal/makara/blob/master/lib/view/index.js#L21)

However, that said, special casing .js extensions still seems a little brittle. I can understand for .dust, but .js is not a good idea?

@totherik
Copy link
Member

totherik commented Jan 8, 2014

Unfortunately, the mapping of '.html' to ejs templates isn't supported yet. That will have to be filed as a feature issue. I was able to use ejs by doing the following:

$ yo kraken
$ cd ejs-kraken
$ npm install --save consolidate
$ npm install --save ejs
app.json
{
    "i18n": null,
    "view engines": {
        "ejs": {
            "module": "consolidate"
        }
    },

    "express": {
        "view engine": "ejs"
    }
}
index.ejs
Hello, <%= name %>!

This renders templates with the .ejs extension:

$ npm start
# ...
$ curl :8000
Hello, ejs!

@steve-lorimer
Copy link
Author

I got ejs templates working with .html extensions as follows:

I added another option renderer to the view engines config (see #93)

This means that the following config will cause express to render .html as ejs templates:

"view engines": {
    "html": {
        "module": "consolidate",
         "renderer": "ejs"
    }
},

"express": {
    "view engine": "html"
}

You can also achieve the same thing without consolidate with this config:

"view engines": {
    "html": {
        "module": "ejs",
        "renderer": "__express"
    }
},

"express": {
    "view engine": "html"
}

@gnrlbzik
Copy link

gnrlbzik commented Jan 9, 2014

Sweet, thanks @skeganga

@mwq27
Copy link

mwq27 commented Jan 10, 2014

+1 @skeganga , I will have to try your method out :)

@cmaldonadowilson
Copy link

+1

@jeffharrell
Copy link
Member

Closing this out as this is a non-issue now that the .next branch has been merged into master. The rendering engine (and all middleware) has been decoupled from the main kraken codebase.

If you're daring, there's an early release candidate published on npm as rc along with generator-kraken. Once it's official it will be updated to latest.

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

7 participants