Trestle is a scaffolding tool for node.js that originated from bumm and then truss. In 6 commands you can have complete CRUD application, your mileage may vary of course, but see my wiki for details trestle
Generated projects rely on express, mongoose, express, jade, stylus, boostrap, forms-bootstrap, and tablesorter
Done
Fixed problem with Updates to Jade and html standardsRename to TrestleSwitch to Bootstrap 3.0Added ability to sort columns using tablesorter
Doing
- Fix the following configurations that do not seem to work trestle: main: (app.js) trestle: scripts/start: (nodemon -w models -w config -w routes app.js) trestle: repository:
- Make all config mongohq ready
Future
- Add pagination
- Work on new logo
npm install trestle -g
First cd to the directory where the project should be created
cd /path/to/projects/root
Create a project skeleton via
trestle app testapp
Next cd to testapp
cd testapp
And install required packages through npm
npm install
Create a model, route and views via scaffold
command. The model
should have two properties "title" and "description" where title is required.
trestle scaffold <collection> title:string:required:true description
Minimum configuration to create a collection (all fields will be type string) trestle scaffold :required
Note: The first field must have property required as it will be the column that will be clicked on to edit the record.
Model validators are specified after property name and type in plain mongoose syntax. In case no type is specified the property will be of type string.
Mongoose types 'String', 'Number', 'Date', 'Buffer', 'Boolean', 'ObjectId', 'Array' are supported. Additionally the types 'Datetime' and 'Textarea' are supported which result in a datetime html 5 input tag and a textbox tag. Types are case insensitive. If (for example) password is recognized as a password and the test will appear as "*"s
Now start node app.js
and navigate your browser to http://localhost:3000/tests
You can create a JSON REST endpoint by scaffolding a model and its corresponding routes. The arguments are the same as above, but instead of scaffold use scafffold:rest like this
trestle resource post title:string:required:true description
Project generator for node.js using express and mongoose
Usage:
trestle [options] command [arguments]
Options:
--help, -h Output this usage dialog
--version, -v Output the version of trestle
Commands:
app <collection> Create a new application
scaffold <collection> [attrib] Create a new route, model and views for <collection>
resource <collection> [attrib] Creates a model and route for resource <collection>
view <collection> [attrib] Creates views for a <collection>
route <collection> [attrib] Creates a route for a <collection>
model <collection> [attrib] Creates a new mongoose model for a <collection>
collection:
Name should be provided as singular, so use `item` instead of `items`. For
`scaffold`, `view`, `route`, `resource`, `model` commands collection
accepts a path prefix. For example `admin/item` will create model, routes and
views in an admin directory. Routes will then point to `/admin/items`. This
option can be useful if you plan to add some authentication based on routes
later on.
attrib:
Attributes are used to describe properties of models used in routes, views
and of course models using the schema:
field:type:validator:validatorValue:validator:validatorValue...
Examples:
trestle app todo Generates an express app skeleton
trestle scaffold item Generates item model, route and views supporting
basic CRUD operations
trestle view item Generates item views
trestle scaffold collection field:string:required:true
Generates item model, route and views with a single
property "collection" that is required.
After executing trestle app <project>
you'll find the following structure in your file system.
| app.js
| helpers.js
| package.json
| README.md
|
+---config
| defaults.js
| development.js
| index.js
| production.js
|
+---lib
| model-mapper.js
|
+---public
| +---css
| | custom.css
| |
| \---vendor
| +---bootstrap
| | +---css
| | | bootstrap-responsive.css
| | | bootstrap-responsive.min.css
| | | bootstrap.css
| | | bootstrap.min.css
| | |
| | +---fonts
| | | glyphicons-halflings-regular.eot
| | | glyphicons-halflings-regular.svg
| | | glyphicons-halflings-regular.ttf
| | | glyphicons-halflings-regular.woff
| | |
| | \---js
| | bootstrap.js
| | bootstrap.min.js
| |
| \---jquery
| \---js
| jquery.min.js
| \---tablesorter
| \---addons
| \---beta-testing
| \---css
| \---docs
| \---js
| \---README.md
| \---testing
| changelog.txt
| component.json
| index.html
| package.json
| tablesorter.jquery.json
| test.html
|
+---routes
| index.js
|
\---views
| index.jade
| layout.jade
|
\---mixins
form-helpers.jade
Creates and initializes an express app with a mongoDb connection configured. Routes will be setup by requiring the routes directory directly. See routes below.
Defines some jade/html helpers for displaying error messages and displaying values. Reusable code
Initial package with value entered in the prompt dialog
Empty readme to silence npm
The config directory is required by app.js
to load the configuration files. Trestle assumes that you
have four config files and two environment variables
NODE_ENV - development or production
PORT - any valid Port number
- defaults Defines defaults that are used in development and production mode - Address, Port web page answers and the database name and location - Modify this if database if remote
- development Defines configuration values used in development mode only Verbose logging, default Port (3000) assignment, and Secret
- production Defines configuration values used in production mode only - No logging, default Port (8000) assignment, and secret Do not pass the config.address to the Express Server startup
- index.js Checks environment variables
Trestle loads defaults first, then loads the configuration file development
or production
depending on the
current NODE_ENV
environment variable and overrides all default values with the "development" or "production"
values.
Trestle ships with a single library file that is responsible to map values provided in request body to a mongoose model.
The public folder contains a quite up to date version of twitter bootstrap under vendor/boostrap
,
an up to date version of jQuery under vendor/jquery
and a custom.css
file under css.
Trestle organizes all shipped 3rd party css/javascript libraries are placed in the vendor
directory and follows a js
, css
, img
schema
for vendor libraries. You are free to place your libraries wherever you want :)
All generated routes will be generated under routes. After creating an app with Trestle, you'll find a single
index.js
file in this folder. Index.js requires all files that are in or routes or a sub directory of routes
to initialize the route. In case you require a route to be defined before another route you can always require
that route in index.js
or load routes manually in a defined order.
index.js also defines a route to /
to render a nice getting started page. This functionality can be removed
without harming the system!
All generated view will be generated under views. After creating an app with Trestle, you'll find an index.jade that is a welcome file to display some help text or defined routes, a layout.jade file that defines the layout used by all generated views and a mixin folder that defines mixins used in Trestle generated views.
- Replaced forms-bootstrap with forms
- Modified views
- Added datepicker
- Form-bootstrap disappeared - fixed
- Fixed typos
- Updated README.md
- Updated README.md
- Added forms-bootstrap and replaced portions of forms
- Added date funtionality to forms-bootstrap
- Cleaned up README.md
- Fixed bugs in app.js.ejs
- Added column sorting using tablesorter
- Added display message if using custom template
- Changed Express server startup parameters depending on whether not in "production"
- Converted original ADM icons that were on the end of each line into a clickible area in the first column
Truss Change Log
- Fixed indentation to comply with Node.js style guides
- Added a form helper for single select boxes
- Updated the edit and create templates to use the same form
- Fixed issue with ObjectId not working in model creation
- Added Bootstrap 3 support
- Errors on forms now use Bootstrap 3 class "has-error"
- Mixin invocation uses the now standard "+" symbol instead of "mixin"
- Add option to use mongodb session store
- Support directories when scaffolding models, views and routes
- Render a nice start page
- Support rest resources for api services
- Express and Mongoose updates
- Fix startup scripts
- Provide better error messages
- Use mixins to render forms
- Add
npm init
like prompt to specify generated package.json values by thomas peklak
- Minor bug fixes in views
- Basic support for array types
- Reorganizes public assets in vendor folder
- Disable 'x-powered-by' header
- Bootstrap update
- Mongoose update
- Initial version