Jelajahi Sumber

W4.5: set up iron:router.

Frederic G. MARAND 8 tahun lalu
induk
melakukan
a9ba66c18b
6 mengubah file dengan 52 tambahan dan 10 penghapusan
  1. 3 0
      .eslintrc.js
  2. 1 0
      .meteor/packages
  3. 8 0
      .meteor/versions
  4. 9 3
      client/docList.html
  5. 24 0
      client/main.js
  6. 7 7
      client/textcircle.html

+ 3 - 0
.eslintrc.js

@@ -22,6 +22,9 @@ module.exports = {
     "Tinytest": true,
     "check": true,
 
+    // IronRouter
+    "Router": true,
+
     // Project-specific.
     "Documents": true,
     "EditingUsers": true

+ 1 - 0
.meteor/packages

@@ -24,3 +24,4 @@ ecmascript
 accounts-password
 ian:accounts-ui-bootstrap-3
 babrahams:editable-text
+iron:router

+ 8 - 0
.meteor/versions

@@ -39,6 +39,14 @@ htmljs@1.0.5
 http@1.1.1
 ian:accounts-ui-bootstrap-3@1.2.89
 id-map@1.0.4
+iron:controller@1.0.12
+iron:core@1.0.11
+iron:dynamic-template@1.0.12
+iron:layout@1.0.12
+iron:location@1.0.11
+iron:middleware-stack@1.0.11
+iron:router@1.0.12
+iron:url@1.0.11
 jquery@1.11.4
 lai:collection-extensions@0.1.4
 launch-screen@1.0.4

+ 9 - 3
client/docList.html

@@ -1,5 +1,11 @@
 <template name="docList">
-  {{#each documents }}
-    {{title}}
-  {{/each}}
+  <div class="container top-margin">
+    <div class="row">
+      <div class="col-md-12">
+        {{#each documents }}
+          {{ title }}
+        {{/each}}
+      </div>
+    </div>
+  </div>
 </template>

+ 24 - 0
client/main.js

@@ -6,6 +6,23 @@
 Meteor.subscribe("documents");
 Meteor.subscribe("editingUsers");
 
+Router.configure({
+  layoutTemplate: "ApplicationLayout"
+});
+
+Router.route("/", function () {
+  Meteor._debug("Routing /");
+  this.render("navbar", { to: "header" });
+  this.render("docList", { to: "main" });
+});
+Router.route("/documents/:_id", function () {
+  Meteor._debug("Routing /documents/" + this.params._id);
+  Session.set("docid", this.params._id);
+  this.render("navbar", { to: "header" });
+  this.render("docItem", { to: "main" });
+});
+
+
 Template.editor.helpers({
   // Return the id of the first document you can find.
   docid: function () {
@@ -61,6 +78,13 @@ Template.navbar.helpers({
   }
 });
 
+Template.docList.helpers({
+  // Retrieve a list of documents.
+  documents: function () {
+    return Documents.find();
+  }
+});
+
 Template.docMeta.helpers({
   // Find current document.
   document: function () {

+ 7 - 7
client/textcircle.html

@@ -1,8 +1,8 @@
-<head>
-  <title>textcircle</title>
-</head>
-
-<body>
-  {{> navbar }}
-</body>
+<template name="ApplicationLayout">
+  <head>
+    <title>textcircle</title>
+  </head>
 
+  {{> yield "header" }}
+  {{> yield "main" }}
+</template>