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

Create good MVC base for app #17

Closed
cletusc opened this issue Nov 7, 2013 · 9 comments
Closed

Create good MVC base for app #17

cletusc opened this issue Nov 7, 2013 · 9 comments
Labels
CODE Some other Code related issue and it should clearly describe what it is affecting in a comment. feature Something we don't already have implemented to the best of knowledge but would like to see.
Milestone

Comments

@cletusc
Copy link
Contributor

cletusc commented Nov 7, 2013

We need a good MVC base for the app, with folder structure looking something like so:

root
    controllers
    models
    node_modules
    views
    public
        js
        css
        images
    app.js
    package.json

Controllers: Handles all logic, db calls, etc and is used directly by our routes using something like app.controllers.[category].[specific route] (e.g. app.controllers.scripts.raw to handle the .user.js and .meta.js routines).

Models: Complete schema data and db-specific logic here, which would most likely use mongoose to make it easier.

Views: All templates. Hook into using express's view engine and views so that we can easily call res.render([viewname], [data]).

Public: All the frontend publicly visible stuff.


Opinion needed

What extension should we use for templates (which will be Mustache)? Some sites I've seen use [file].mustache and others [file].tpl. I'd prefer .tpl in case we ever switched template engines down the line.

@ghost ghost assigned cletusc Nov 7, 2013
@cletusc
Copy link
Contributor Author

cletusc commented Nov 7, 2013

I've decided to go with .html extensions to get default working syntax highlighting on any capable editor. Plus we can always open up the file raw and get some sort of look of the layout.

@jerone
Copy link
Contributor

jerone commented Nov 7, 2013

+1 Sounds good to me.

Only comment I have, I usually go with media instead of images folder name to also match video's, favicons, and other media stuff.

Don't forget the .gitignore file.

@cletusc
Copy link
Contributor Author

cletusc commented Nov 7, 2013

I've got most of this working, just need to get the views fully functioning. I'll be using consolidate with hogan.js to process the templates--it is mustache, but really fast. We can always switch to some other processor later, but getting something working is the plan.

I'll finish that up after I get home from work and open a pull request.

@sizzlemctwizzle
Copy link
Member

Don't use Hogan.js, Mu is faster. It's really damn fast. I've been trying to find the fastest Mustache engine for about two weeks and even tried writing my own, but Mu has the best performance.

Also don't waste time with consolidate. It is unnecessarily bloated for what it does (it has a hook for Mu but it's incredibly unoptimized), and we'll never use the other template engines it supports.

I'd also say ignore Express's stupid view engine. Just use its routing and call mu.compileAndRender('template.html', view).pipe(res);. Where template.html is the relevant template for that route and view is an object for Mustache. If you want to wrap that logic into some function to simplify things, go ahead. See my implementation of a Express view engine wrapper for Mu in the comment below.

@sizzlemctwizzle
Copy link
Member

Here you go. It's the world's simplest wrapper to make Mu a view engine (see the comments for usage). I high-jacked the callback parameter on renderer to send the response stream, since that callback is just used to pass the template rendered as a string to the caller so they can send it as a response. That is inefficient, both in terms of speed and memory usage, and adds an extra step. Might as well just pipe to the response stream directly.

@sizzlemctwizzle
Copy link
Member

I know I have the power to merge this pull request, but I'll leave it up to Cletus to make the decision since he's assigned to this issue and has been working on something of his own. Feel free to all/part/none of this patch.

@cletusc
Copy link
Contributor Author

cletusc commented Nov 8, 2013

Woops, looks like this doesn't work--missing muExpress. Did you put that module in the node_modules? .gitignore is ignoring that folder. Perhaps we should change that to a different folder for custom modules?

@sizzlemctwizzle
Copy link
Member

We were both working on a fix for my screw up at the same time. I put the file in a libs directory since they're custom libraries that we'll use throughout development, and I just favor short names lol. I just pushed this to master (in several commits because I was being a moron and couldn't make up my mind).

@Martii
Copy link
Member

Martii commented Mar 25, 2016

Btw I've never assigned or unassigned myself to this issue... not to mention I wasn't here back in late 2013. No mention of team biz label adding either from anyone. :\ Ahh GH glitches. :) UPDATE Appears my contact to GH support fixered some of it. :)


FYI

This is the generic, wip, structure that has been observed since entry (e.g. a visual aid for reference):

MVC Exemplar

We don't quite follow this completely yet but it is a goal none-the-less.

Ref:

@Martii Martii added feature Something we don't already have implemented to the best of knowledge but would like to see. CODE Some other Code related issue and it should clearly describe what it is affecting in a comment. and removed team biz This is similar to a meta discussion. labels Mar 25, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CODE Some other Code related issue and it should clearly describe what it is affecting in a comment. feature Something we don't already have implemented to the best of knowledge but would like to see.
Development

No branches or pull requests

4 participants