Commit 77bf6ea0

mo khan <mo@mokhan.ca>
2014-08-31 04:45:40
add tutorial show page.
1 parent dd7d513
Changed files (4)
app
assets
javascripts
app/assets/javascripts/backbone/controllers/tutorials_controller.js.coffee
@@ -15,6 +15,15 @@ class CakeSide.Controllers.TutorialsController extends Marionette.Controller
     @comment_view.hide()
     @content_region.show(new @views.NewView(collection: @tutorials))
 
+  show: (id) ->
+    @selectTab()
+    tutorial = @tutorials.get(id)
+    @content_region.show(new @views.ShowView(model: tutorial))
+    @comment_view.render
+      identifier: "t-#{tutorial.id}"
+      title: tutorial.get('name')
+      url: tutorial.public_url()
+
   selectTab: ->
     $('.nav-list').children().removeClass('active')
     $('#tutorial-tab').addClass('active')
app/assets/javascripts/backbone/routers/tutorials_router.js.coffee
@@ -2,3 +2,4 @@ class CakeSide.Routers.TutorialsRouter extends Marionette.AppRouter
   appRoutes:
     "tutorials": "index"
     "tutorials/new": "new"
+    "tutorials/:id": "show"
app/assets/javascripts/backbone/templates/tutorials/show.jst.ejs
@@ -0,0 +1,16 @@
+<div class="row-fluid">
+  <div class="span12">
+    <h3><a href="#tutorials/<%= id %>"><%= heading %></a> <small><%= displayDate(created_at) %></small></h3>
+    <a href="#tutorials/<%= id %>">
+      <img src="<%= image_url %>" />
+    </a>
+    <p>
+      <% _.each(tags, function(tag) { %>
+        <a href="/tt/<%= tag.name %>">
+          <span class="label"><%= tag.name %></span>
+        </a>
+      <% }); %>
+    </p>
+    <p><%= description %></p>
+  </div>
+</div>
app/assets/javascripts/backbone/views/tutorials/show_view.js.coffee
@@ -0,0 +1,7 @@
+CakeSide.Views.Tutorials ||= {}
+
+class CakeSide.Views.Tutorials.ShowView extends Marionette.ItemView
+  template: JST["backbone/templates/tutorials/show"]
+  templateHelpers:
+    displayDate: (date) ->
+      date