Skip to content

Instantly share code, notes, and snippets.

@SmokeyTheSalmon
Created September 5, 2014 11:46
Show Gist options
  • Save SmokeyTheSalmon/15214bcb91dc18661c74 to your computer and use it in GitHub Desktop.
Save SmokeyTheSalmon/15214bcb91dc18661c74 to your computer and use it in GitHub Desktop.
<head> <title>start</title> </head>
<body>
<h1>Welcome to Meteor!</h1>
{{> loginButtons}}
{{ currentUser.services.github.username }}
{{> hello}}
</body>
<template name="hello">
{{#if currentUser }}
<button>Click {{ name }}</button>
{{/if}}
<p>{{ users }}</p>
<hr/>
<ul>
{{#each gists}}
<li>{{url}}</li>
{{/each}}
</ul>
</template>
Users = new Meteor.Collection('users');
if (Meteor.isClient) {
Meteor.call('getNames', function(error, names){
Session.set('names', names);
});
//Calls the thing in starthtml to do stuff with gists
Meteor.call('getGists', function(error, result){
Session.set('gists', result);
console.log("Meteor call works");
});
Template.hello.helpers({
users: function () {
console.log("Counter works, and therefore the helper works");
console.log(Users);
//If there is a user in Meteor
if(Meteor.user()){
var user = Meteor.user().services.github.username;
console.log("There is a user and its variable is a " + typeof(user));
//Check if there is a user with a similar name in the DB
var userATM = Users.findOne({'name': user});
//If not
if(!userATM){
// Add the user to the DB
Users.insert({'name': user});
}
//Else
else {
console.log("There is no user");
return "not available or shit is still broken";
};
}
},
name: function(){
return Meteor.user().services.github.username;
},
gists: function(){
return Session.get('gists');
}
});
Template.hello.events({
'click button': function () {
var user = Meteor.user().services.github.username;
console.log(user, " clicked button");
var userATM = Users.findOne({'name': user});
// Update the list of users with said user and increase the count with one
Users.update({_id: userATM._id}, {$inc: {count: 1}});
}
});
}
if (Meteor.isServer) {
console.log("Meteor is server");
//Thank you Captain Obvious
Meteor.methods({
getGists: function(){
var GithubApi = Meteor.npmRequire('github');
var github = new GithubApi({
version: "3.0.0"
});
console.log("Meteor method works");
// Sync the asynchronus Github stuff
var gists = Async.runSync(function(done){
//Gets gists from the github of said user
github.gists.getFromUser({user: 'SmokeyTheSalmon'}, function(err, data){
done(null, data);
});
});
return gists.result;
},
getNames: function(){
if(Users.name){
return Users.name;
}
else{
return "Nobody has visited my site yet :'C"
}
}
});
//What Meteor does on activation
Meteor.startup(function () {
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment