On Github SachaG / meteor-presentation
@SachaGreif
Discover Meteor
Showing the Dribbble homepage over the past 12 hours.
curl https://install.meteor.com | /bin/sh
Create the app.
meteor create gribbble
Open the app's directory.
cd gribbble
meteor
rm gribbble.css gribbble.html gribbble.js
mkdir client mkdir server mkdir collections
We now have a working Meteor app. Let's make it actually do something!
Snapshots = new Meteor.Collection('snapshots');
meteor add http
var url="http://api.dribbble.com/shots/popular?per_page=12"; var queryAPI = function () { HTTP.get(url, function(error, result){ if(result){ result.timestamp = new Date().getTime(); Snapshots.insert(result); } }); }
Meteor.setInterval(function(){ queryAPI(); }, 3600000);
We're now collecting the 12 most popular Dribbble shots every hour. Next step: displaying them.
<head> <title>Gribbble</title> </head> <body> <h1>Gribbble</h1> {{> grid}} </body>
<template name="grid"> <div class="grid"> {{#each snapshots}} <div class="grid-snapshot grid-col"> {{timestamp}} </div> {{/each}} </div> </template>
Template.grid.helpers({ snapshots: function () { return Snapshots.find({}, { sort: {timestamp: -1}, limit: 12 }); } });
<template name="grid"> <div class="grid"> {{#each snapshots}} <div class="grid-snapshot grid-col"> {{#each data.shots}} <p>{{title}}</p> {{/each}} </div> {{/each}} </div> </template>
<template name="shot"> <a href="{{url}}" target="_blank" class="grid-shot"> <img src="{{image_teaser_url}}" class="grid-image"/> </a> </template>
<template name="grid"> <div class="grid"> {{#each snapshots}} <div class="grid-snapshot grid-col"> {{#each data.shots}} {{>shot}} {{/each}} </div> {{/each}} </div> </template>
We're storing and displaying data. We now need to control the flow of data from server to client.
meteor remove autopublish meteor remove insecure
Meteor.publish('snapshots', function(limit) { return Snapshots.find({}, { sort: {timestamp: -1}, limit: limit }); });
Meteor.subscribe('snapshots', 12);
We built a simple web app in less than 100 lines of code, and saw an overview of the main Meteor features.