Browse Source

Chapter 4: collections. Working without autopublish.

Frederic G. MARAND 8 years ago
parent
commit
ae7df74636

+ 0 - 1
.gitignore

@@ -1 +0,0 @@
-.meteor

+ 8 - 0
.meteor/.finished-upgraders

@@ -0,0 +1,8 @@
+# This file contains information which helps Meteor properly upgrade your
+# app when you run 'meteor update'. You should check it into version control
+# with your project.
+
+notices-for-0.9.0
+notices-for-0.9.1
+0.9.4-platform-file
+notices-for-facebook-graph-api-2

+ 1 - 0
.meteor/.gitignore

@@ -0,0 +1 @@
+local

+ 7 - 0
.meteor/.id

@@ -0,0 +1,7 @@
+# This file contains a token that is unique to your project.
+# Check it into your repository along with the rest of this directory.
+# It can be used for purposes such as:
+#   - ensuring you don't accidentally deploy one app on top of another
+#   - providing package authors with aggregated statistics
+
+1kyt8bgs6klw786195d

+ 10 - 0
.meteor/packages

@@ -0,0 +1,10 @@
+# Meteor packages used by this project, one per line.
+# Check this file (and the other files in this directory) into your repository.
+#
+# 'meteor add' and 'meteor remove' will edit this file for you,
+# but you can also edit it by hand.
+
+meteor-platform
+iron:router
+twbs:bootstrap
+underscore

+ 2 - 0
.meteor/platforms

@@ -0,0 +1,2 @@
+browser
+server

+ 1 - 0
.meteor/release

@@ -0,0 +1 @@
+METEOR@1.1.0.3

+ 55 - 0
.meteor/versions

@@ -0,0 +1,55 @@
+autoupdate@1.2.1
+base64@1.0.3
+binary-heap@1.0.3
+blaze@2.1.2
+blaze-tools@1.0.3
+boilerplate-generator@1.0.3
+callback-hook@1.0.3
+check@1.0.5
+ddp@1.1.0
+deps@1.0.7
+ejson@1.0.6
+fastclick@1.0.3
+geojson-utils@1.0.3
+html-tools@1.0.4
+htmljs@1.0.4
+http@1.1.0
+id-map@1.0.3
+iron:controller@1.0.8
+iron:core@1.0.8
+iron:dynamic-template@1.0.8
+iron:layout@1.0.8
+iron:location@1.0.9
+iron:middleware-stack@1.0.9
+iron:router@1.0.9
+iron:url@1.0.9
+jquery@1.11.3_2
+json@1.0.3
+launch-screen@1.0.2
+livedata@1.0.13
+logging@1.0.7
+meteor@1.1.6
+meteor-platform@1.2.2
+minifiers@1.1.5
+minimongo@1.0.8
+mobile-status-bar@1.0.3
+mongo@1.1.0
+observe-sequence@1.0.6
+ordered-dict@1.0.3
+random@1.0.3
+reactive-dict@1.1.0
+reactive-var@1.0.5
+reload@1.1.3
+retry@1.0.3
+routepolicy@1.0.5
+session@1.1.0
+spacebars@1.0.6
+spacebars-compiler@1.0.6
+templating@1.1.1
+tracker@1.0.7
+twbs:bootstrap@3.3.5
+ui@1.0.6
+underscore@1.0.3
+url@1.0.4
+webapp@1.2.0
+webapp-hashing@1.0.3

+ 0 - 15
client/main.html

@@ -1,18 +1,3 @@
 <head>
   <title>Microscope</title>
 </head>
-
-<body>
-<div class="container">
-  <header class="navbar navbar-default" role="navigation">
-    <div class="navbar-header">
-      <a class="navbar-brand" href="/">Microscope</a>
-    </div>
-  </header>
-
-  <div id="main">
-    {{! postsLists est le nom du template dans posts_list.html }}
-    {{> postsList}}
-  </div>
-</div>
-</body>

+ 1 - 0
client/main.js

@@ -0,0 +1 @@
+Meteor.subscribe('posts');

+ 14 - 0
client/templates/application/layout.html

@@ -0,0 +1,14 @@
+<template name="layout">
+  <div class="container">
+    <header class="navbar navbar-default" role="navigation">
+      <div class="navbar-header">
+        <a class="navbar-brand" href="/">Microscope</a>
+      </div>
+    </header>
+
+    <div id="main">
+      {{! IronRouter magic }}
+      {{> yield}}
+    </div>
+  </div>
+</template>

+ 3 - 16
client/templates/posts/posts_list.js

@@ -6,22 +6,9 @@
  * Date: 30/08/15
  * Time: 10:07
  */
-var postsData = [
-  {
-    title: "Introducing Telescope",
-    url: "http://sachagreif.com/introducing-telescope"
-  },
-  {
-    title: "Meteor",
-    url: "http://meteor.com"
-  },
-  {
-    title: "The Meteor book",
-    url: "http://themeteorbook.com"
-  }
-];
-
 Template.postsList.helpers({
-  posts: postsData
+  posts: function () {
+    return Posts.find();
+  }
 });
 

+ 12 - 0
lib/collections/posts.js

@@ -0,0 +1,12 @@
+/**
+ * @file
+ *
+ *
+ * User: marand
+ * Date: 30/08/15
+ * Time: 10:48
+ */
+
+// Not a "var", to make it global.
+Posts = new Mongo.Collection('posts');
+

+ 14 - 0
lib/router.js

@@ -0,0 +1,14 @@
+/**
+ * @file
+ *
+ *
+ * User: marand
+ * Date: 30/08/15
+ * Time: 16:47
+ */
+
+Router.configure({
+    layoutTemplate: "layout"
+});
+
+Router.route('/', { name: 'postsList' });

+ 33 - 0
server/fixtures.js

@@ -0,0 +1,33 @@
+/**
+ * @file
+ *
+ *
+ * User: marand
+ * Date: 30/08/15
+ * Time: 11:33
+ */
+
+if (Posts.find().count() === 0) {
+  var data = [
+    {
+      title: "Introducing Telescope",
+      url: "http://sachagreif.com/introducing-telescope"
+    },
+    {
+      title: "Meteor",
+      url: "http://meteor.com"
+      },
+    {
+      title: "The Meteor book",
+      url: "http://themeteorbook.com"
+      }
+  ];
+
+  data.forEach(function (post) {
+    Meteor._debug("Inserting", post);
+    Posts.insert(post);
+  });
+}
+else {
+  Meteor._debug('Posts collection is not empty');
+}

+ 12 - 0
server/publications.js

@@ -0,0 +1,12 @@
+/**
+ * @file
+ *
+ *
+ * User: marand
+ * Date: 30/08/15
+ * Time: 11:53
+ */
+
+Meteor.publish('posts', function() {
+  return Posts.find();
+});