Commit 69a79609

mo <mokha@cisco.com>
2017-09-02 21:53:55
move bonebone code for my/* to my/* namespace.
1 parent 3512ca4
app/assets/javascripts/controllers/cakes_controller.js.coffee → app/assets/javascripts/controllers/my/cakes_controller.js.coffee
@@ -1,5 +1,5 @@
-class CakeSide.Controllers.CakesController extends Marionette.Controller
-  views: CakeSide.Views.Cakes
+class CakeSide.Controllers.My.CakesController extends Marionette.Controller
+  views: CakeSide.Views.My.Cakes
   initialize: (options) ->
     @content_region = CakeSide.Application.content_region
     @cakes = CakeSide.Application.request('CakesRepository')
app/assets/javascripts/controllers/dashboard_controller.js.coffee → app/assets/javascripts/controllers/my/dashboard_controller.js.coffee
@@ -1,4 +1,4 @@
-class CakeSide.Controllers.DashboardController extends Marionette.Controller
+class CakeSide.Controllers.My.DashboardController extends Marionette.Controller
   initialize: (options) ->
     #@comment_view = CakeSide.Application.request('CommentView')
 
app/assets/javascripts/controllers/profile_controller.js.coffee → app/assets/javascripts/controllers/my/profile_controller.js.coffee
@@ -1,5 +1,5 @@
-class CakeSide.Controllers.ProfileController extends Marionette.Controller
-  views: CakeSide.Views.Profiles
+class CakeSide.Controllers.My.ProfileController extends Marionette.Controller
+  views: CakeSide.Views.My.Profiles
   initialize: (options) ->
     @content_region = CakeSide.Application.content_region
     #@comment_view = CakeSide.Application.request('CommentView')
app/assets/javascripts/controllers/tutorials_controller.js.coffee → app/assets/javascripts/controllers/my/tutorials_controller.js.coffee
@@ -1,5 +1,5 @@
-class CakeSide.Controllers.TutorialsController extends Marionette.Controller
-  views: CakeSide.Views.Tutorials
+class CakeSide.Controllers.My.TutorialsController extends Marionette.Controller
+  views: CakeSide.Views.My.Tutorials
   initialize: (options) ->
     @content_region = CakeSide.Application.content_region
     @tutorials = CakeSide.Application.request('TutorialsRepository')
app/assets/javascripts/infrastructure/auto_view.js.coffee
@@ -0,0 +1,22 @@
+class CakeSide.AutoView extends Backbone.View
+  @views: {}
+  @constructors: {}
+
+  @viewName: (name) ->
+    @constructors[name] = this
+
+  @install: (element) ->
+    name = $(element).data('autoview')
+    constructor = @constructors[name]
+    if constructor == undefined
+      console.error("Could not find autoview for #{name}")
+      return
+
+    view = new constructor
+      el: element
+      $el: $(element)
+    view.render()
+    @views[name] ?= []
+    @views[name].push(view)
+
+  render: -> { }
app/assets/javascripts/infrastructure/auto_view_setup.js.coffee
@@ -0,0 +1,8 @@
+#= require ./behaviour
+
+class CakeSide.AutoViewSetup extends CakeSide.Behaviour
+  @on "load"
+
+  execute: ->
+    for element in $('[data-autoview]')
+      CakeSide.AutoView.install(element)
app/assets/javascripts/infrastructure/behaviour.js.coffee
@@ -0,0 +1,13 @@
+class CakeSide.Behaviour
+  @events: {}
+
+  @on: (event) ->
+    @events[event] ?= []
+    @events[event].push(@)
+
+  @install: ->
+    for event of @events
+      window.addEventListener event, () =>
+        for behaviour in @events[event]
+          new behaviour().execute()
+
app/assets/javascripts/templates/cakes/cake.jst.ejs → app/assets/javascripts/templates/my/cakes/cake.jst.ejs
File renamed without changes
app/assets/javascripts/templates/cakes/delete_modal.jst.ejs → app/assets/javascripts/templates/my/cakes/delete_modal.jst.ejs
File renamed without changes
app/assets/javascripts/templates/cakes/edit.jst.ejs → app/assets/javascripts/templates/my/cakes/edit.jst.ejs
File renamed without changes
app/assets/javascripts/templates/cakes/new.jst.ejs → app/assets/javascripts/templates/my/cakes/new.jst.ejs
File renamed without changes
app/assets/javascripts/templates/cakes/no_cakes.jst.ejs → app/assets/javascripts/templates/my/cakes/no_cakes.jst.ejs
File renamed without changes
app/assets/javascripts/templates/cakes/show.jst.ejs → app/assets/javascripts/templates/my/cakes/show.jst.ejs
File renamed without changes
app/assets/javascripts/templates/cakes/thumbnail.jst.ejs → app/assets/javascripts/templates/my/cakes/thumbnail.jst.ejs
File renamed without changes
app/assets/javascripts/templates/photos/new-modal.jst.ejs → app/assets/javascripts/templates/my/photos/new-modal.jst.ejs
File renamed without changes
app/assets/javascripts/templates/profiles/show.jst.ejs → app/assets/javascripts/templates/my/profiles/show.jst.ejs
File renamed without changes
app/assets/javascripts/templates/tutorials/new.jst.ejs → app/assets/javascripts/templates/my/tutorials/new.jst.ejs
File renamed without changes
app/assets/javascripts/templates/tutorials/no_tutorials.jst.ejs → app/assets/javascripts/templates/my/tutorials/no_tutorials.jst.ejs
File renamed without changes
app/assets/javascripts/templates/tutorials/show.jst.ejs → app/assets/javascripts/templates/my/tutorials/show.jst.ejs
File renamed without changes
app/assets/javascripts/templates/tutorials/tutorial.jst.ejs → app/assets/javascripts/templates/my/tutorials/tutorial.jst.ejs
File renamed without changes
app/assets/javascripts/views/cakes/index_view.js.coffee
@@ -1,7 +0,0 @@
-#= require views/cakes/no_cakes_view
-
-class CakeSide.Views.Cakes.IndexView extends Marionette.CollectionView
-  childView: CakeSide.Views.Cakes.CakeView
-  emptyView: CakeSide.Views.Cakes.NoCakesView
-  className: ''
-  tagName: 'div'
app/assets/javascripts/views/cakes/no_cakes_view.js.coffee
@@ -1,3 +0,0 @@
-class CakeSide.Views.Cakes.NoCakesView extends Marionette.ItemView
-  template: JST["templates/cakes/no_cakes"]
-  tagName: 'li'
app/assets/javascripts/views/cakes/cake_view.js.coffee → app/assets/javascripts/views/my/cakes/cake_view.js.coffee
@@ -1,5 +1,5 @@
-class CakeSide.Views.Cakes.CakeView extends Marionette.ItemView
-  template: JST["templates/cakes/cake"]
+class CakeSide.Views.My.Cakes.CakeView extends Marionette.ItemView
+  template: JST["templates/my/cakes/cake"]
   tagName: 'div'
   className: 'media'
   templateHelpers:
app/assets/javascripts/views/cakes/delete_cake_modal_view.js.coffee → app/assets/javascripts/views/my/cakes/delete_cake_modal_view.js.coffee
@@ -1,5 +1,5 @@
-class CakeSide.Views.Cakes.DeleteCakeModalView extends Marionette.ItemView
-  template: JST["templates/cakes/delete_modal"]
+class CakeSide.Views.My.Cakes.DeleteCakeModalView extends Marionette.ItemView
+  template: JST["templates/my/cakes/delete_modal"]
   ui:
     remove_button: "#remove-button"
     confirmation_textbox: '#confirmation-textbox'
app/assets/javascripts/views/cakes/edit_view.js.coffee → app/assets/javascripts/views/my/cakes/edit_view.js.coffee
@@ -1,8 +1,8 @@
-#= require views/cakes/thumbnail_view
+#= require views/my/cakes/thumbnail_view
 
-class CakeSide.Views.Cakes.EditView extends Marionette.CompositeView
-  template : JST["templates/cakes/edit"]
-  childView: CakeSide.Views.Cakes.ThumbnailView
+class CakeSide.Views.My.Cakes.EditView extends Marionette.CompositeView
+  template : JST["templates/my/cakes/edit"]
+  childView: CakeSide.Views.My.Cakes.ThumbnailView
   childViewContainer: '.card-columns'
   ui:
     name: "#cake_name"
app/assets/javascripts/views/my/cakes/index_view.js.coffee
@@ -0,0 +1,7 @@
+#= require views/my/cakes/no_cakes_view
+
+class CakeSide.Views.My.Cakes.IndexView extends Marionette.CollectionView
+  childView: CakeSide.Views.My.Cakes.CakeView
+  emptyView: CakeSide.Views.My.Cakes.NoCakesView
+  className: ''
+  tagName: 'div'
app/assets/javascripts/views/cakes/new_view.js.coffee → app/assets/javascripts/views/my/cakes/new_view.js.coffee
@@ -1,5 +1,5 @@
-class CakeSide.Views.Cakes.NewView extends Marionette.ItemView
-  template: JST["templates/cakes/new"]
+class CakeSide.Views.My.Cakes.NewView extends Marionette.ItemView
+  template: JST["templates/my/cakes/new"]
   ui:
     name: "#cake_name"
     category: "#cake_category_id"
app/assets/javascripts/views/my/cakes/no_cakes_view.js.coffee
@@ -0,0 +1,3 @@
+class CakeSide.Views.My.Cakes.NoCakesView extends Marionette.ItemView
+  template: JST["templates/my/cakes/no_cakes"]
+  tagName: 'li'
app/assets/javascripts/views/cakes/show_view.js.coffee → app/assets/javascripts/views/my/cakes/show_view.js.coffee
@@ -1,8 +1,8 @@
-#= require views/cakes/thumbnail_view
+#= require views/my/cakes/thumbnail_view
 
-class CakeSide.Views.Cakes.ShowView extends Marionette.CompositeView
-  template: JST["templates/cakes/show"]
-  childView: CakeSide.Views.Cakes.ThumbnailView
+class CakeSide.Views.My.Cakes.ShowView extends Marionette.CompositeView
+  template: JST["templates/my/cakes/show"]
+  childView: CakeSide.Views.My.Cakes.ThumbnailView
   childViewContainer: '.card-columns'
 
   events:
app/assets/javascripts/views/cakes/thumbnail_view.js.coffee → app/assets/javascripts/views/my/cakes/thumbnail_view.js.coffee
@@ -1,5 +1,5 @@
-class CakeSide.Views.Cakes.ThumbnailView extends Marionette.ItemView
-  template: JST['templates/cakes/thumbnail']
+class CakeSide.Views.My.Cakes.ThumbnailView extends Marionette.ItemView
+  template: JST['templates/my/cakes/thumbnail']
   tagName: 'div'
   className: 'card'
   modelEvents:
app/assets/javascripts/views/photos/new_modal_view.js.coffee → app/assets/javascripts/views/my/photos/new_modal_view.js.coffee
@@ -1,5 +1,5 @@
-class CakeSide.Views.Photos.NewModalView extends Marionette.ItemView
-  template: JST["templates/photos/new-modal"]
+class CakeSide.Views.My.Photos.NewModalView extends Marionette.ItemView
+  template: JST["templates/my/photos/new-modal"]
   ui:
     watermark: '#watermark'
     upload_button: "#upload-photo-button"
app/assets/javascripts/views/profiles/show_view.js.coffee → app/assets/javascripts/views/my/profiles/show_view.js.coffee
@@ -1,5 +1,5 @@
-class CakeSide.Views.Profiles.ShowView extends Marionette.ItemView
-  template: JST["templates/profiles/show"]
+class CakeSide.Views.My.Profiles.ShowView extends Marionette.ItemView
+  template: JST["templates/my/profiles/show"]
   ui:
     name: '#user_name'
     email: '#user_email'
app/assets/javascripts/views/my/tutorials/index_view.js.coffee
@@ -0,0 +1,8 @@
+#= require views/my/tutorials/no_tutorials_view
+#= require views/my/tutorials/tutorial_view
+
+class CakeSide.Views.My.Tutorials.IndexView extends Marionette.CollectionView
+  childView: CakeSide.Views.My.Tutorials.TutorialView
+  emptyView: CakeSide.Views.My.Tutorials.NoTutorialsView
+  className: ''
+  tagName: 'div'
app/assets/javascripts/views/tutorials/new_view.js.coffee → app/assets/javascripts/views/my/tutorials/new_view.js.coffee
@@ -1,7 +1,7 @@
 #= require service/embedly_service
 
-class CakeSide.Views.Tutorials.NewView extends Marionette.ItemView
-  template: JST['templates/tutorials/new']
+class CakeSide.Views.My.Tutorials.NewView extends Marionette.ItemView
+  template: JST['templates/my/tutorials/new']
   ui:
     url: '#tutorial_url'
     url_group: '#url-group'
app/assets/javascripts/views/my/tutorials/no_tutorials_view.js.coffee
@@ -0,0 +1,3 @@
+class CakeSide.Views.My.Tutorials.NoTutorialsView extends Marionette.ItemView
+  template: JST['templates/my/tutorials/no_tutorials']
+  tagName: 'li'
app/assets/javascripts/views/my/tutorials/show_view.js.coffee
@@ -0,0 +1,5 @@
+class CakeSide.Views.My.Tutorials.ShowView extends Marionette.ItemView
+  template: JST["templates/my/tutorials/show"]
+  templateHelpers:
+    displayDate: (date) ->
+      date
app/assets/javascripts/views/tutorials/tutorial_view.js.coffee → app/assets/javascripts/views/my/tutorials/tutorial_view.js.coffee
@@ -1,5 +1,5 @@
-class CakeSide.Views.Tutorials.TutorialView extends Marionette.ItemView
-  template: JST['templates/tutorials/tutorial']
+class CakeSide.Views.My.Tutorials.TutorialView extends Marionette.ItemView
+  template: JST['templates/my/tutorials/tutorial']
   tagName: 'div'
   className: 'media'
 
app/assets/javascripts/views/profiles/index.js.coffee
app/assets/javascripts/views/tutorials/index_view.js.coffee
@@ -1,8 +0,0 @@
-#= require views/tutorials/no_tutorials_view
-#= require views/tutorials/tutorial_view
-
-class CakeSide.Views.Tutorials.IndexView extends Marionette.CollectionView
-  childView: CakeSide.Views.Tutorials.TutorialView
-  emptyView: CakeSide.Views.Tutorials.NoTutorialsView
-  className: ''
-  tagName: 'div'
app/assets/javascripts/views/tutorials/no_tutorials_view.js.coffee
@@ -1,3 +0,0 @@
-class CakeSide.Views.Tutorials.NoTutorialsView extends Marionette.ItemView
-  template: JST['templates/tutorials/no_tutorials']
-  tagName: 'li'
app/assets/javascripts/views/tutorials/show_view.js.coffee
@@ -1,5 +0,0 @@
-class CakeSide.Views.Tutorials.ShowView extends Marionette.ItemView
-  template: JST["templates/tutorials/show"]
-  templateHelpers:
-    displayDate: (date) ->
-      date
app/assets/javascripts/views/index.js.coffee
@@ -1,7 +1,8 @@
 #= require_self
 #= require_tree .
 
-CakeSide.Views.Cakes ||= {}
-CakeSide.Views.Photos ||= {}
-CakeSide.Views.Profiles ||= {}
-CakeSide.Views.Tutorials ||= {}
+CakeSide.Views.My ||= {}
+CakeSide.Views.My.Cakes ||= {}
+CakeSide.Views.My.Photos ||= {}
+CakeSide.Views.My.Profiles ||= {}
+CakeSide.Views.My.Tutorials ||= {}
app/assets/javascripts/application.js
@@ -15,7 +15,9 @@
 //= require backbone_datalink
 //= require backbone-model-file-upload
 //= require cakeside
+//= require_self
 
+CakeSide.Behaviour.install()
 var initialize = function(){
   $(window).scroll(function(){
     if ($(window).scrollTop() >= ($(document).height() - $(window).height())*0.8){
app/assets/javascripts/cakeside.js.coffee
@@ -1,4 +1,5 @@
 #= require_self
+#= require_tree ./infrastructure
 #= require_tree ./templates
 #= require_tree ./models
 #= require ./views
@@ -11,7 +12,7 @@ window.CakeSide =
   Collections: {}
   Routers: {}
   Views: {}
-  Controllers: {}
+  Controllers: { My: {} }
   initialize: (data) ->
     $(document).ajaxSend  (event, xhr) ->
       if data.access_token
@@ -24,13 +25,13 @@ window.CakeSide =
 
     CakeSide.Application.addInitializer (options) ->
       new CakeSide.Routers.CakesRouter
-        controller: new CakeSide.Controllers.CakesController()
+        controller: new CakeSide.Controllers.My.CakesController()
       new CakeSide.Routers.TutorialsRouter
-        controller: new CakeSide.Controllers.TutorialsController()
+        controller: new CakeSide.Controllers.My.TutorialsController()
       new CakeSide.Routers.DashboardRouter
-        controller: new CakeSide.Controllers.DashboardController()
+        controller: new CakeSide.Controllers.My.DashboardController()
       new CakeSide.Routers.ProfileRouter
-        controller: new CakeSide.Controllers.ProfileController()
+        controller: new CakeSide.Controllers.My.ProfileController()
 
     CakeSide.Application.on 'start', ->
       if Backbone.history
spec/javascripts/backbone/views/cake_view_spec.js.coffee
@@ -1,8 +1,8 @@
-describe "CakeSide.Views.Cakes.CakeView", ->
+describe "CakeSide.Views.My.Cakes.CakeView", ->
   cake = new CakeSide.Models.Cake
     id: '1'
     name: 'chocolate'
-  subject = new CakeSide.Views.Cakes.CakeView
+  subject = new CakeSide.Views.My.Cakes.CakeView
     model: cake
 
   describe "when there are no photos", ->