Skip to content
Browse files

Adds track path view

  • Loading branch information...
1 parent ad52e70 commit 02e3d77b901680108a7e05d7e91290fbf20131db Dominik Guzei committed Feb 20, 2012
View
3 Guardfile
@@ -2,7 +2,6 @@
# Adds guard rules for auto-testing jasmine specs
guard 'jasmine' do
- watch(%r{app/assets/javascripts/(.+)\.(js\.coffee|js|coffee)$}) { |m| "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
- watch(%r{spec/javascripts/(.+)_spec\.(js\.coffee|js|coffee)$}) { |m| puts m.inspect; "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
+ watch(%r{app/assets/javascripts/(.+)\.(js\.coffee|js|coffee)$}) { "spec/javascripts" }
watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { "spec/javascripts" }
end
View
15 app/assets/javascripts/application.js
@@ -1,15 +0,0 @@
-// This is a manifest file that'll be compiled into application.js, which will include all the files
-// listed below.
-//
-// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
-// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
-//
-// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
-// the compiled file.
-//
-// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
-// GO AFTER THE REQUIRES BELOW.
-//
-//= require jquery
-//= require jquery_ujs
-//= require_tree .
View
7 app/assets/javascripts/application.js.coffee
@@ -0,0 +1,7 @@
+#= require jquery
+#= require jquery_ujs
+#= require ember-dev
+#= require game/controllers/game_application
+
+game.controllers.GameApplication.create()
+
View
15 app/assets/javascripts/game/controllers/game_application.js.coffee
@@ -0,0 +1,15 @@
+
+#= require helpers/namespace
+#= require vendor/raphael
+#= require game/mediators/track
+#= require game/views/track
+
+namespace 'game.controllers'
+
+@game.controllers.GameApplication = Ember.Application.extend
+
+ ready: ->
+ trackMediator = game.mediators.TrackMediator.create()
+ game.views.TrackView.create
+ mediator: trackMediator
+ paper: Raphael $(@rootElement)[0], 1024, 768
View
7 app/assets/javascripts/game/mediators/track.js.coffee
@@ -0,0 +1,7 @@
+
+#= require helpers/namespace
+
+namespace 'game.mediators'
+
+@game.mediators.TrackMediator = Ember.Object.extend
+ trackPath: 'M600,200R700,300,400,400,300,200,400,100,600,200z'
View
9 app/assets/javascripts/game/views/track.js.coffee
@@ -0,0 +1,9 @@
+
+#= require helpers/namespace
+
+namespace 'game.views'
+
+@game.views.TrackView = Ember.Object.extend
+
+ init: ->
+ @paper.path @mediator.trackPath
View
8 app/assets/javascripts/helpers/namespace.js.coffee
@@ -0,0 +1,8 @@
+
+@namespace = (path) ->
+ namespaces = path.split '.'
+ target = window
+
+ for namespace in namespaces
+ target[namespace] or= {}
+ target = target[namespace]
View
5,501 app/assets/javascripts/vendor/raphael.js
5,501 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
6 app/controllers/tracks_controller.rb
@@ -0,0 +1,6 @@
+class TracksController < ApplicationController
+
+ def index
+ end
+
+end
View
0 app/views/tracks/index.html.erb
No changes.
View
55 config/routes.rb
@@ -1,58 +1,5 @@
Slotcars::Application.routes.draw do
- # The priority is based upon order of creation:
- # first created -> highest priority.
- # Sample of regular route:
- # match 'products/:id' => 'catalog#view'
- # Keep in mind you can assign values other than :controller and :action
+ root :to => 'tracks#index'
- # Sample of named route:
- # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
- # This route can be invoked with purchase_url(:id => product.id)
-
- # Sample resource route (maps HTTP verbs to controller actions automatically):
- # resources :products
-
- # Sample resource route with options:
- # resources :products do
- # member do
- # get 'short'
- # post 'toggle'
- # end
- #
- # collection do
- # get 'sold'
- # end
- # end
-
- # Sample resource route with sub-resources:
- # resources :products do
- # resources :comments, :sales
- # resource :seller
- # end
-
- # Sample resource route with more complex sub-resources
- # resources :products do
- # resources :comments
- # resources :sales do
- # get 'recent', :on => :collection
- # end
- # end
-
- # Sample resource route within a namespace:
- # namespace :admin do
- # # Directs /admin/products/* to Admin::ProductsController
- # # (app/controllers/admin/products_controller.rb)
- # resources :products
- # end
-
- # You can have the root of your site routed with "root"
- # just remember to delete public/index.html.
- # root :to => 'welcome#index'
-
- # See how all your routes lay out with "rake routes"
-
- # This is a legacy wild controller route that's not recommended for RESTful applications.
- # Note: This route will make all actions in every controller accessible via GET requests.
- # match ':controller(/:action(/:id))(.:format)'
end
View
241 public/index.html
@@ -1,241 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Ruby on Rails: Welcome aboard</title>
- <style type="text/css" media="screen">
- body {
- margin: 0;
- margin-bottom: 25px;
- padding: 0;
- background-color: #f0f0f0;
- font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
- font-size: 13px;
- color: #333;
- }
-
- h1 {
- font-size: 28px;
- color: #000;
- }
-
- a {color: #03c}
- a:hover {
- background-color: #03c;
- color: white;
- text-decoration: none;
- }
-
-
- #page {
- background-color: #f0f0f0;
- width: 750px;
- margin: 0;
- margin-left: auto;
- margin-right: auto;
- }
-
- #content {
- float: left;
- background-color: white;
- border: 3px solid #aaa;
- border-top: none;
- padding: 25px;
- width: 500px;
- }
-
- #sidebar {
- float: right;
- width: 175px;
- }
-
- #footer {
- clear: both;
- }
-
- #header, #about, #getting-started {
- padding-left: 75px;
- padding-right: 30px;
- }
-
-
- #header {
- background-image: url("assets/rails.png");
- background-repeat: no-repeat;
- background-position: top left;
- height: 64px;
- }
- #header h1, #header h2 {margin: 0}
- #header h2 {
- color: #888;
- font-weight: normal;
- font-size: 16px;
- }
-
-
- #about h3 {
- margin: 0;
- margin-bottom: 10px;
- font-size: 14px;
- }
-
- #about-content {
- background-color: #ffd;
- border: 1px solid #fc0;
- margin-left: -55px;
- margin-right: -10px;
- }
- #about-content table {
- margin-top: 10px;
- margin-bottom: 10px;
- font-size: 11px;
- border-collapse: collapse;
- }
- #about-content td {
- padding: 10px;
- padding-top: 3px;
- padding-bottom: 3px;
- }
- #about-content td.name {color: #555}
- #about-content td.value {color: #000}
-
- #about-content ul {
- padding: 0;
- list-style-type: none;
- }
-
- #about-content.failure {
- background-color: #fcc;
- border: 1px solid #f00;
- }
- #about-content.failure p {
- margin: 0;
- padding: 10px;
- }
-
-
- #getting-started {
- border-top: 1px solid #ccc;
- margin-top: 25px;
- padding-top: 15px;
- }
- #getting-started h1 {
- margin: 0;
- font-size: 20px;
- }
- #getting-started h2 {
- margin: 0;
- font-size: 14px;
- font-weight: normal;
- color: #333;
- margin-bottom: 25px;
- }
- #getting-started ol {
- margin-left: 0;
- padding-left: 0;
- }
- #getting-started li {
- font-size: 18px;
- color: #888;
- margin-bottom: 25px;
- }
- #getting-started li h2 {
- margin: 0;
- font-weight: normal;
- font-size: 18px;
- color: #333;
- }
- #getting-started li p {
- color: #555;
- font-size: 13px;
- }
-
-
- #sidebar ul {
- margin-left: 0;
- padding-left: 0;
- }
- #sidebar ul h3 {
- margin-top: 25px;
- font-size: 16px;
- padding-bottom: 10px;
- border-bottom: 1px solid #ccc;
- }
- #sidebar li {
- list-style-type: none;
- }
- #sidebar ul.links li {
- margin-bottom: 5px;
- }
-
- .filename {
- font-style: italic;
- }
- </style>
- <script type="text/javascript">
- function about() {
- info = document.getElementById('about-content');
- if (window.XMLHttpRequest)
- { xhr = new XMLHttpRequest(); }
- else
- { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
- xhr.open("GET","rails/info/properties",false);
- xhr.send("");
- info.innerHTML = xhr.responseText;
- info.style.display = 'block'
- }
- </script>
- </head>
- <body>
- <div id="page">
- <div id="sidebar">
- <ul id="sidebar-items">
- <li>
- <h3>Browse the documentation</h3>
- <ul class="links">
- <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
- <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
- <li><a href="http://www.ruby-doc.org/core/">Ruby core</a></li>
- <li><a href="http://www.ruby-doc.org/stdlib/">Ruby standard library</a></li>
- </ul>
- </li>
- </ul>
- </div>
-
- <div id="content">
- <div id="header">
- <h1>Welcome aboard</h1>
- <h2>You&rsquo;re riding Ruby on Rails!</h2>
- </div>
-
- <div id="about">
- <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
- <div id="about-content" style="display: none"></div>
- </div>
-
- <div id="getting-started">
- <h1>Getting started</h1>
- <h2>Here&rsquo;s how to get rolling:</h2>
-
- <ol>
- <li>
- <h2>Use <code>rails generate</code> to create your models and controllers</h2>
- <p>To see all available options, run it without parameters.</p>
- </li>
-
- <li>
- <h2>Set up a default route and remove <span class="filename">public/index.html</span></h2>
- <p>Routes are set up in <span class="filename">config/routes.rb</span>.</p>
- </li>
-
- <li>
- <h2>Create your database</h2>
- <p>Run <code>rake db:create</code> to create your database. If you're not using SQLite (the default), edit <span class="filename">config/database.yml</span> with your username and password.</p>
- </li>
- </ol>
- </div>
- </div>
-
- <div id="footer">&nbsp;</div>
- </div>
- </body>
-</html>
View
48 spec/javascripts/functional/game/controllers/game_application_spec.js.coffee
@@ -0,0 +1,48 @@
+
+#= require game/controllers/game_application
+#= require game/views/track
+
+describe 'game.controllers.GameApplication', ->
+
+ GameApplication = game.controllers.GameApplication
+
+ it 'should extend Ember.Application', ->
+ (expect Ember.Application.detect GameApplication).toBe true
+
+ describe '#ready', ->
+
+ beforeEach ->
+ @mediatorBackup = game.mediators.TrackMediator
+ @mediatorInstanceStub = {}
+ @trackMediatorStub = game.mediators.TrackMediator =
+ create: sinon.stub().returns @mediatorInstanceStub
+
+ @trackViewBackup = game.views.TrackView
+ @trackViewStub = game.views.TrackView =
+ create: sinon.spy()
+
+ @RaphaelBackup = window.Raphael
+ @RaphaelStub = window.Raphael = sinon.stub()
+ @RaphaelStub.returns
+ raphael: @RaphaelStub
+
+ @application = GameApplication.create()
+
+ afterEach ->
+ game.mediators.TrackMediator = @mediatorBackup
+ game.views.TrackView = @trackViewBackup
+ window.Raphael = @RaphaelBackup
+ @application.destroy()
+
+ it 'should create track mediator', ->
+ (expect @trackMediatorStub.create).toHaveBeenCalled()
+
+ it 'should create track view and provide mediator', ->
+ (expect @trackViewStub.create).toHaveBeenCalled()
+ (expect @trackViewStub.create.args[0][0]['mediator']).toBe @mediatorInstanceStub
+
+ it 'should provide raphael paper to track view', ->
+ (expect @RaphaelStub).toHaveBeenCalledWith $(@application.get('rootElement'))[0], 1024, 768
+ (expect @trackViewStub.create.args[0][0]['paper'].raphael).toBe @RaphaelStub
+
+
View
19 spec/javascripts/functional/game/views/track_spec.js.coffee
@@ -0,0 +1,19 @@
+
+#= require game/views/track
+
+describe 'game.views.TrackView (functional)', ->
+
+ TrackView = game.views.TrackView
+
+ it 'should call paper.path with mediator.trackPath when created', ->
+ mediatorStub =
+ trackPath: "random path " + (Math.floor (Math.random 1) * 100)
+
+ paperStub =
+ path: sinon.spy()
+
+ TrackView.create
+ mediator: mediatorStub
+ paper: paperStub
+
+ (expect paperStub.path).toHaveBeenCalledWith mediatorStub.trackPath
View
1 spec/javascripts/spec.js.coffee
@@ -3,7 +3,6 @@
#= require jquery
#= require jquery_ujs
-#= require embient/require
#= require ember-dev
# ------ load testing extras -------
View
9 spec/javascripts/unit/game/mediators/track_spec.js.coffee
@@ -0,0 +1,9 @@
+
+#= require game/mediators/track
+
+describe 'game.mediators.TrackMediator', ->
+
+ TrackMediator = game.mediators.TrackMediator
+
+ it 'should extend Ember.Object', ->
+ (expect Ember.Object.detect TrackMediator).toBe true
View
9 spec/javascripts/unit/game/views/track_spec.js.coffee
@@ -0,0 +1,9 @@
+
+#= require game/views/track
+
+describe 'game.views.TrackView', ->
+
+ TrackView = game.views.TrackView
+
+ it 'should extend Ember.Object', ->
+ (expect Ember.Object.detect TrackView).toBe true
View
9 spec/javascripts/unit/helpers/namespace_spec.js.coffee
@@ -0,0 +1,9 @@
+
+#= require helpers/namespace
+
+describe 'namespace', ->
+
+ it 'should create nested objects for namespace string', ->
+ namespace('nested.objects.test')
+
+ (expect nested.objects.test).toEqual {}

0 comments on commit 02e3d77

Please sign in to comment.
Something went wrong with that request. Please try again.