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

[view] convention for exporting views of a resource #52

Open
ahdinosaur opened this issue Jun 12, 2013 · 1 comment
Open

[view] convention for exporting views of a resource #52

ahdinosaur opened this issue Jun 12, 2013 · 1 comment
Labels

Comments

@ahdinosaur
Copy link

for resources to be self-contained, they need a way to present themselves to the user, ie. on a web page. an obvious solution is of course the view resource. what is the most conventional way to incorporate views into a resource?

i was thinking

// in .start(), a conventional resource method for initializing a resource
var view = resource.use('view');
view.create({ path: __dirname + '/view' }, function(err, _view) {
    <resource>.view = _view;
}

that way when you want to view the resource,

<resource>.view.index.present(options, function(err, result) { ...

or

<resource>.view.sub.dir.upload.present(options, function(err, result) { ...
@Marak
Copy link
Member

Marak commented Jun 13, 2013

If a /view/ folder exists in a resource, it should be considered the default view for that resource. A few apps and resources exist with this convention already.

The best way to specify a view is to explicitly set the view in the resource itself, then set resource.view to the generated view.

The sync api for view.create was removed, so putting view.create in a resource.start method is good. You could also try using a resource.before hook on start to keep the code more compact.

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

No branches or pull requests

2 participants