01 sudo apt-get install curl 02 curl https://install.meteor.com | /bin/sh 03 meteor create starpublisher 04 cd starpublisher 05 meteor 01 console.log('Both contexts'); 02 if (Meteor.isServer) 03 console.log ('Web server context'); 04 else if (Meteor.isClient) 05 console.log ('Browser context'); 01 var Articles = new Meteor.Collection("articles"); 02 Articles.insert({}); 01 sudo apt-get install git 02 PATH=$PATH:~/.meteor/tools/0b2f28e18b/bin 03 npm install -g meteorite 04 mrt add moment Articles = new Meteor.Collection("articles"); 01 02 {{> articles}} 03 {{> editor}} 04 05 06 16 17 01 Template.articles.articles = function() { 02 return Articles.find({}, {sort: {date: -1}}); 03 } 04 05 Template.articles.helpers({ 06 formatDate: function(date) { 07 return moment(date).format("lll"); 08 } 09 }); 10 11 Template.articles.events({ 12 'click': function() { 13 var doc = Articles.findOne({_id: this._id}); 14 load(doc._id, doc.title, doc.text); 15 } 16 }); 17 18 Template.editor.events({ 19 'click #save': function() { 20 var now = new Date(); 21 Articles.upsert(val('id'), { title:val('title'), text:val('text'), date:now}); 22 load(); 23 }, 24 'click #remove': function() { 25 Articles.remove(val('id')); 26 load(); 27 } 28 }); 01 meteor remove insecure 02 meteor remove autopublish 03 meteor add accounts-password 04 meteor add accounts-ui 01 Meteor.publish("articles", function() { 02 return Articles.find(); 03 }); 01 Articles.allow({ 02 remove: function(userId, doc) { 03 return doc.owner === userId; 04 } 05 }); 06 07 Meteor.methods({ 08 upsert: function(id, title, text) { 09 if (!this.userId) 10 throw new Meteor.Error(403, 'Please log in first'); 11 var now = new Date(); 12 var email = Meteor.user().emails[0].address 13 var doc = {owner: this.userId, title: title, text: text, date: now, email: email}; 14 if (id) { 15 if (Articles.update({_id: id, owner: this.userId}, {$set: doc}) < 1) 16 throw new Meteor.Error(404, 'Access not Allowed'); 17 } else { 18 Articles.insert(doc); 19 } 20 } 21 }); 01 Template.editor.events({ 02 'click #save': function() { 03 error(); 04 Meteor.call('upsert', val('id'), val('title'), val('text'), function(e) { 05 error(e.message); 06 nav(); 07 }); 08 nav(1); 09 }, 10 'click #remove': function() { 11 Articles.remove(val('id')); 12 nav(1); 13 } 14 });