Skip to content

Commit

Permalink
Added a complete CRUD example, code refactor and removed/added packages
Browse files Browse the repository at this point in the history
  • Loading branch information
kjetilhau committed Aug 31, 2014
1 parent e53b629 commit 950a4ff
Show file tree
Hide file tree
Showing 34 changed files with 256 additions and 1,070 deletions.
4 changes: 0 additions & 4 deletions .gitignore

This file was deleted.

16 changes: 9 additions & 7 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
# but you can also edit it by hand.

standard-app-packages
insecure
cmather:iron-router
alanning:roles
aldeed:simple-schema

# Atmosphere

aldeed:collection2
aldeed:simple-schema
aldeed:autoform
manuelschoebel:less-fontawesome-4
manuelschoebel:less-bootstrap-3
mrt:bootstrap-3
iron:router
alanning:roles
mizzao:bootstrap-3
mrt:moment
accounts-base
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
# Meteor-skeleton
Opinionated skeleton for Meteor - giving you a more organized and structured way to create projects.
A skeleton/boilerplate for Meteor - giving you a more organized and structured way to create projects.

It contains a few helpers, routes and views. Oh, and a collection with pubs and subs.
It comes with a complete collection sample including publications, subscriptions and CRUD functionality. Routes, views and some nice helpers are also included.

## Dependencies
- iron-router
- roles
- simple-schema
- collection2
- autoform
- moment
- less-fontawesome
- less-bootstrap-3
- iron-router-progress
## Packages used

- standard-app-packages
- accounts-base
- iron:router
- aldeed:simple-schema
- aldeed:collection2
- aldeed:autoform
- mrt:moment
- mizzao:bootstrap-3
- alanning:roles

The Meteor packages 'autopublish' and 'insecure' are removed by default.

# Usage
1. Clone it: ```git clone https://github.com/kjetilhau/meteor-skeleton.git```
2. ```cd meteor-skeleton```
3. Delete everything git related (.git folder and .gitignore)
3. Remove the .git folder
4. ```git init```
5. ```meteor add less```
6. ```meteor```

## Structure

```
client/ # Client code
config/ # Configuration files
lib/ # Library files that get executed first
helpers/ # Helpers that helps you help others
helpers/ # Helpers that helps you and yours
routes/ # Everything related to client-side routing
startup/ # Stuff that gets launched at client load
stylesheets/ # CSS/LESS/SCSS files
components/ # Styles for specific components
sites/ # Styles for a site or for a collection's CRUD views
sites/ # Styles for sites and collections
subscriptions/ # Collection subscriptions that are not defined in routes
views/ # View templates
documents/ # Views related to the Documents collection
layouts/ # Layout files defined with Iron Router
pages/ # Views for static pages
shared/ # Usually templates that are shared between views
collections/ # Collection files, separate files for each collection
lib/ # Code shared with client and server files
collections/ # Collection files, separate files for each collection
helpers/ # Helpers that is accessible on both client and server
public/ # Public files
img/ # Images
fonts/ # Fonts
img/ # Static image folder
fonts/ # Static fonts folder
server/ # Server code
config/ # Server configuration files
fixtures/ # Fixtures for defining pre-loaded data
Expand Down
6 changes: 3 additions & 3 deletions client/config/accounts.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Accounts.ui.config({
passwordSignupFields: 'EMAIL_ONLY'
});
//Accounts.ui.config({
// passwordSignupFields: 'EMAIL_ONLY'
//});
41 changes: 17 additions & 24 deletions client/lib/autoform_hooks.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
// Autoform hooks

AutoForm.hooks({
documentForm: {
before: {
insert: function(doc) {},
update: function(docId, modifier) {},
remove: function(docId) {},
"methodName": function(doc) {}
AutoForm.addHooks(['documentForm'], {
after: {
insert: function(error, result) {
if (error) {
console.log("Insert Error:", error);
} else {
console.log("Insert Result:", result);
Router.go('documentsIndex')
}
},
after: {
insert: function(error, result, template) { },
update: function(error, result, template) { },
remove: function(error, result, template) {},
"methodName": function(error, result, template) {}
},
onSubmit: function(insertDoc, updateDoc, currentDoc) {},

//called when any operation succeeds, where operation will be
//"insert", "update", "remove", or the method name.
onSuccess: function(operation, result, template) {},

//called when any operation fails, where operation will be
//"validation", "insert", "update", "remove", or the method name.
onError: function(operation, error, template) {},
formToDoc: function(doc) {},
docToForm: function(doc) {}
update: function(error) {
if (error) {
console.log("Update Error:", error);
} else {
console.log("Updated!");
Router.go('documentsIndex')
}
}
}
});
52 changes: 18 additions & 34 deletions client/lib/helpers/common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Common helpers
// Client-side common helpers

// Style link as active if it is the current path
// Usage: <li class="{{active 'frontpage'}}"><a href="{{pathFor 'frontpage'}}">Home</a></li>
Expand All @@ -9,49 +9,33 @@ UI.registerHelper('active', function(path) {
}
});

// Very basic pluralization
// Cheap pluralization
UI.registerHelper('pluralize', function(count, word) {
if (count === 1) {
return '1 ' + word;
} else {
return count + ' ' + word + 's';
}
return count === 1 ? '1 ' + word : count + ' ' + word + 's';
});

// Outputs e.g. 12 days ago or 2 hours ago with Moment
UI.registerHelper('showTimeago', function(date){
if (!date) {
return ("");
}
else {
return moment(date).fromNow();
}
// Outputs e.g. 12 days ago or 2 hours ago
UI.registerHelper('showTimeAgo', function(date) {
return !date ? "" : moment(date).fromNow();
});

// Outputs e.g. Jan, 2013
UI.registerHelper('showMonthYear', function(date){
if (!date) {
return ("");
}
else {
var monthYear = moment(date).format("MMM, YYYY");
return (monthYear);
}
UI.registerHelper('showMonthYear', function(date) {
return !date ? "" : moment(date).format("MMM, YYYY");
});

// Outputs e.g. 12th Jan, 2013
UI.registerHelper('showDayMonthYear', function(date){
if (!date) {
return ("");
}
else {
var dayMonthYear = moment(date).format("Do MMM, YYYY");
return (dayMonthYear);
}
UI.registerHelper('showDayMonthYear', function(date) {
return !date ? "" : moment(date).format("Do MMM, YYYY")
});

// Outputs August 30th 2014, 5:33:46 pm
UI.registerHelper('showPrettyTimestamp', function(date) {
return !date ? "" : moment(date).format("MMMM Do YYYY, h:mm:ss a")
});

// Get profile image or placeholder image
UI.registerHelper('getProfileImage', function(image){
UI.registerHelper('getProfileImage', function(image) {
var imagePlaceholder = "/img/profile_placeholder.png";
if (!image || image === "") {
return imagePlaceholder;
Expand All @@ -61,8 +45,8 @@ UI.registerHelper('getProfileImage', function(image){
}
});

// Translates those bytes to something more convenient
UI.registerHelper('bytesToSize', function(bytes){
// Translates those bytes to something more readable
UI.registerHelper('bytesToSize', function(bytes) {
if (!bytes) {
return ("");
}
Expand Down
11 changes: 11 additions & 0 deletions client/routes/filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Iron-router filters / hooks that will run on certain routes

var filters = {

resetDocumentForm: function() {
AutoForm.resetForm('documentForm')
}

}

Router.onStop(filters.resetDocumentForm, {only: ['documentNew', 'documentEdit']});
18 changes: 11 additions & 7 deletions client/routes/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
// ***************************************************************

Router.map(function() {

// FRONTPAGE
// -------------------------------------------------------
this.route('frontpage', {
path: '/',
template: 'frontpage',
progress: {
enabled: false
}
template: 'frontpage'
});

});

// ABOUT
// -------------------------------------------------------
this.route('about', {
path: '/about',
template: 'about'
});

});
4 changes: 2 additions & 2 deletions client/startup/startup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Meteor.startup(function () {
// Do something
});
// Do something
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
15 changes: 0 additions & 15 deletions client/stylesheets/style.less

This file was deleted.

Loading

0 comments on commit 950a4ff

Please sign in to comment.