Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 17 files changed
  • 0 commit comments
  • 1 contributor
View
1  Gemfile
@@ -20,6 +20,7 @@ group :assets do
gem 'bootstrap-sass', '~> 2.0.1', :branch => '2.0'
gem 'haml_coffee_assets', :git => 'https://github.com/netzpirat/haml_coffee_assets.git'
gem 'execjs'
+ gem 'i18n-js', :git => 'https://github.com/fnando/i18n-js.git'
end
gem 'jquery-rails'
View
8 Gemfile.lock
@@ -17,6 +17,13 @@ GIT
paper_trail (~> 2)
GIT
+ remote: https://github.com/fnando/i18n-js.git
+ revision: eeec14066b50f72876aa789c9b1f226172452798
+ specs:
+ i18n-js (2.1.2)
+ i18n
+
+GIT
remote: https://github.com/netzpirat/haml_coffee_assets.git
revision: e5bd7108f9e49ead5cd6309c32ee7c38cb28695b
specs:
@@ -242,6 +249,7 @@ DEPENDENCIES
haml (>= 3.1.alpha.50)
haml-rails
haml_coffee_assets!
+ i18n-js!
jasmine
jasminerice
jquery-rails
View
3  app/assets/javascripts/application.js
@@ -18,6 +18,9 @@
//= require underscore
//= require backbone
//
+//= require i18n
+//= require i18n/translations
+//
//= require cojiro_app
//
//= require_tree ./models
View
10 app/assets/javascripts/cojiro_app.js.coffee
@@ -3,6 +3,10 @@ window.CojiroApp =
Collections: {}
Views: {}
Routers: {}
- init: ->
- new CojiroApp.Routers.Cothreads()
- Backbone.history.start()
+ init: (data) ->
+ @cothread = new CojiroApp.Models.Cothread(data.cothread)
+
+ new CojiroApp.Routers.Cothreads(model: @cothread)
+ if (!Backbone.history.started)
+ Backbone.history.start()
+ Backbone.history.started = true
View
3  app/assets/javascripts/collections/cothreads.js.coffee
@@ -0,0 +1,3 @@
+class CojiroApp.Collections.Cothreads extends Backbone.Collection
+ model: CojiroApp.Models.Cothread
+ url: '/cothreads'
View
4 app/assets/javascripts/models/cothread.js.coffee
@@ -1,9 +1,9 @@
class CojiroApp.Models.Cothread extends Backbone.Model
url: ->
if @isNew()
- '/threads.json'
+ '/threads'
else
- '/threads/' + @getId() + '.json'
+ '/threads/' + @getId()
defaults:
title: ''
View
7 app/assets/javascripts/routers/cothreads.js.coffee
@@ -0,0 +1,7 @@
+class CojiroApp.Routers.Cothreads extends Backbone.Router
+ routes:
+ "" : "show"
+
+ show: ->
+ view = new CojiroApp.Views.CothreadsShow( model: CojiroApp.cothread )
+ $('.content').html(view.render().el)
View
3  app/assets/javascripts/templates/cothreads/show.hamlc
@@ -1,2 +1,3 @@
// code for app/assets/javascripts/templates/hello.jst.hamlc
-%h1 Hello HAML
+%h1=@model.getTitle()
+%p=@model.getSummary()
View
4 app/assets/javascripts/views/cothreads/cothreads_show.js.coffee
@@ -2,7 +2,9 @@ class CojiroApp.Views.CothreadsShow extends Backbone.View
id: 'thread'
initialize: ->
+ _.bindAll @
+ @render()
render: ->
- @$el.html(JST['cothreads/show'])
+ @$el.html(JST['cothreads/show'](model: @model))
@
View
2  app/controllers/cothreads_controller.rb
@@ -1,8 +1,10 @@
class CothreadsController < ApplicationController
before_filter :login_required, :except => [:show]
before_filter :find_cothread, :except => [:new, :create]
+ respond_to :html, :json
def show
+ respond_with(@cothread)
end
def new
View
15 app/views/cothreads/show.html.haml
@@ -1,5 +1,14 @@
- title @cothread.title
-.page-header
- %h1
-
#thread
+
+%script#bootstrap{ type: "text/json" }
+ { "cothread":
+ =@cothread.to_json.html_safe
+ }
+
+=content_for :javascript do
+ %script{ type: "text/javascript" }
+ $(function () {
+ data = JSON.parse($('#bootstrap').text());
+ CojiroApp.init(data);
+ });
View
1  app/views/layouts/application.html.haml
@@ -30,3 +30,4 @@
- flash.each do |name, msg|
= content_tag :div, '<a class="close" href="#">×</a>'.html_safe + msg, :class => "alert alert-#{name} #{name}", :id => "flash_#{name}", :'data-dismiss' => 'alert' if msg.is_a?(String)
= yield
+ = yield :javascript
View
6 features/step_definitions/interaction_steps.rb
@@ -17,3 +17,9 @@
Then /^I (should|should not) see the text:? "([^"]*)"$/ do |expectation, text|
page.send(expectation.gsub(' ','_'),have_content(text))
end
+
+Then /^I (should|should not) see the text:? "([^"]*)" in the thread$/ do |expectation, text|
+ within(:css, '#thread') do
+ page.send(expectation.gsub(' ','_'),have_content(text))
+ end
+end
View
6 features/thread_view.feature
@@ -10,12 +10,12 @@ Feature: View a thread
| nickname | csasaki |
And my locale is "en"
+ @javascript
Scenario: View a thread
Given the following thread exists:
| user | csasaki |
| title | Co-working spaces in Tokyo |
| summary | I want to write an an article about the increased popularity of co-working spaces. |
And I am on the page for the thread "Co-working spaces in Tokyo"
- Then I should see the text "Co-working spaces in Tokyo"
- And I should see the text "I want to write an an article about the increased popularity of co-working spaces."
-
+ Then I should see the text "Co-working spaces in Tokyo" in the thread
+ And I should see the text "I want to write an an article about the increased popularity of co-working spaces." in the thread
View
22 spec/javascripts/cojiro_app_spec.js.coffee
@@ -0,0 +1,22 @@
+describe "CojiroApp", ->
+ it "has a namespace for Models", -> expect(CojiroApp.Models).toBeTruthy()
+ it "has a namespace for Collection", -> expect(CojiroApp.Collections).toBeTruthy()
+ it "has a namespace for Views", -> expect(CojiroApp.Views).toBeTruthy()
+ it "has a namespace for Routers", -> expect(CojiroApp.Routers).toBeTruthy()
+
+ describe "init()", ->
+ it "accepts JSON and instantiates collections from it", ->
+ cothreadsJSON =
+ "cothread":
+ "title": "Co-working spaces in Tokyo","summary": "I'm collecting blog posts on co-working spaces in Tokyo."
+
+ CojiroApp.init(cothreadsJSON)
+
+ expect(CojiroApp.cothread).not.toEqual(undefined)
+ expect(CojiroApp.cothread.getTitle()).toEqual("Co-working spaces in Tokyo")
+ expect(CojiroApp.cothread.getSummary()).toEqual("I'm collecting blog posts on co-working spaces in Tokyo.")
+
+ it "instantiates a Cothreads router", ->
+ CojiroApp.Routers.Cothreads = sinon.spy()
+ CojiroApp.init({})
+ expect(CojiroApp.Routers.Cothreads).toHaveBeenCalled()
View
8 spec/javascripts/collections/cothreads_spec.js.coffee
@@ -0,0 +1,8 @@
+describe "CojiroApp.Collections.Cothreads", ->
+ it "contains instances of CojiroApp.Models.Cothread", ->
+ collection = new CojiroApp.Collections.Cothreads()
+ expect(collection.model).toEqual(CojiroApp.Models.Cothread)
+
+ it "is persisted at /threads", ->
+ collection = new CojiroApp.Collections.Cothreads()
+ expect(collection.url).toEqual("/cothreads")
View
20 spec/javascripts/models/cothread_spec.js.coffee
@@ -1,7 +1,7 @@
# ref: http://blog.bandzarewicz.com/blog/2012/03/08/backbone-dot-js-tdd-with-jasmine-part-one-the-model/
#
describe 'CojiroApp.Models.Cothread', ->
- it 'should be defined', -> expect(CojiroApp.Models.Cothread).toBeDefined()
+ it 'is defined', -> expect(CojiroApp.Models.Cothread).toBeDefined()
it 'can be instantiated', ->
cothread = new CojiroApp.Models.Cothread
@@ -20,7 +20,7 @@ describe 'CojiroApp.Models.Cothread', ->
beforeEach -> @cothread = new CojiroApp.Models.Cothread()
describe '#getId', ->
- it 'should be defined', -> expect(@cothread.getId).toBeDefined()
+ it 'is defined', -> expect(@cothread.getId).toBeDefined()
it 'returns undefined if id is not defined', ->
expect(@cothread.getId()).toBeUndefined()
@@ -30,7 +30,7 @@ describe 'CojiroApp.Models.Cothread', ->
expect(@cothread.getId()).toEqual(66)
describe '#getTitle', ->
- it 'should be defined', -> expect(@cothread.getTitle).toBeDefined()
+ it 'is defined', -> expect(@cothread.getTitle).toBeDefined()
it 'returns value for the title attribute', ->
stub = sinon.stub(@cothread, 'get').returns('Thread title')
@@ -39,7 +39,7 @@ describe 'CojiroApp.Models.Cothread', ->
expect(stub).toHaveBeenCalledWith('title')
describe '#getSummary', ->
- it 'should be defined', -> expect(@cothread.getSummary).toBeDefined()
+ it 'is defined', -> expect(@cothread.getSummary).toBeDefined()
it 'returns value for the summary attribute', ->
stub = sinon.stub(@cothread, 'get').returns('Thread summary')
@@ -67,9 +67,9 @@ describe 'CojiroApp.Models.Cothread', ->
@cothread.save()
@request = @server.requests[0]
- it 'should be a POST', -> expect(@request).toBePOST()
- it 'should be async', -> expect(@request).toBeAsync()
- it 'should have a valid URL', -> expect(@request).toHaveUrl('/threads.json')
+ it 'is a POST', -> expect(@request).toBePOST()
+ it 'is async', -> expect(@request).toBeAsync()
+ it 'has a valid URL', -> expect(@request).toHaveUrl('/threads')
describe 'on update', ->
beforeEach ->
@@ -77,6 +77,6 @@ describe 'CojiroApp.Models.Cothread', ->
@cothread.save()
@request = @server.requests[0]
- it 'should be a PUT', -> expect(@request).toBePUT()
- it 'should be async', -> expect(@request).toBeAsync()
- it 'should have a valid URL', -> expect(@request).toHaveUrl('/threads/66.json')
+ it 'is a PUT', -> expect(@request).toBePUT()
+ it 'is async', -> expect(@request).toBeAsync()
+ it 'has a valid URL', -> expect(@request).toHaveUrl('/threads/66')

No commit comments for this range

Something went wrong with that request. Please try again.