Expose `View` constructor via `express` module #1383

Closed
ericf opened this Issue Oct 24, 2012 · 10 comments

Comments

Projects
None yet
5 participants
Contributor

ericf commented Oct 24, 2012

Both the Route and Router constructors are exposed via the main express module; why not also expose the View constructor here?

To gain access to the View constructor one must currently:

var View = require('express/lib/view');

Whereas, the following seems cleaner:

var express = require('express'),
    View    = express.View;
Owner

tj commented Oct 24, 2012

they're all private, I should hide router / route as well ideally, just need to adjust the tests that reference these exports

Contributor

ericf commented Oct 24, 2012

Okay, fair enough. I wasn't sure if you were trying to expose them for
extensibility…

Owner

tj commented Oct 24, 2012

we could but it would be an at-your-own-risk scenario

Contributor

ericf commented Oct 24, 2012

The use case I have is wanting to reintroduce the concept of a view layout in a template specific way. I was looking to see if I could leverage View to provide the same filename lookup that's performed for all other templates.

Owner

tj commented Oct 24, 2012

even better is we move this portion into npm-land and retain the current api, but then you could use View for whatever you want. if i have time tomorrow ill toy around with that a bit

Contributor

ericf commented Oct 24, 2012

Sounds good, thanks!

@jonathanong jonathanong reopened this Sep 26, 2013

Contributor

caridy commented Sep 27, 2013

@jonathanong, thanks for reopening this. We (@ericf and myself) have been discussing it lately, and it will be great if we can abstract it into its own package. At the moment we are doing some tricks in express-view to redefine it for synthetic views and fallback to the express' internal implementation when needed, but it is hacky.

Member

jonathanong commented Sep 27, 2013

I didn't reopen it, I just accidentally closed it. Pressed close instead of label. Haha

Contributor

defunctzombie commented Nov 20, 2013

@ericf Can you please clarify how this can't be done just by using a specific view engine? I use layouts with the hbs view engine and it works fine.

Contributor

ericf commented Nov 27, 2013

@ericf Can you please clarify how this can't be done just by using a specific view engine? I use layouts with the hbs view engine and it works fine.

@defunctzombie my reason was around code re-use; I wanted to reuse the same code that Express uses to lookup templates to lookup a layout template. But this thread is old and since then I created Express3 Handlebars and I'm doing my own layout lookup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment