Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] Make It Backbone #92

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Guardfile
capybara-*.html
config/application.yml
config/projections.json
config/environments/*.local.yml
config/settings.local.yml
config/settings/*.local.yml
Expand Down
11 changes: 11 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
source 'https://rubygems.org'
source 'https://rails-assets.org'

ruby '2.1.1'

gem 'rails', '4.0.3'
Expand Down Expand Up @@ -34,6 +36,7 @@ group :development do
gem 'view_source_map'
gem 'i18n-tasks'
gem 'thin'
gem 'coffee-rails-source-maps'
end

group :test, :development do
Expand Down Expand Up @@ -70,4 +73,12 @@ gem 'erb2haml'
gem 'font-awesome-rails'
gem 'figaro'
gem 'unicorn'
gem 'backbone-on-rails'
gem 'haml_coffee_assets'
gem 'therubyracer', platforms: :ruby

gem 'jbuilder', '~> 1.2'
gem 'rails-assets-backbone.marionette'
gem 'rails-assets-backbone.stickit'
gem 'rails-assets-moment'

56 changes: 56 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
GEM
remote: https://rubygems.org/
remote: https://rails-assets.org/
specs:
actionmailer (4.0.3)
actionpack (= 4.0.3)
Expand All @@ -19,6 +20,10 @@ GEM
activesupport (= 4.0.3)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activeresource (4.0.0)
activemodel (~> 4.0)
activesupport (~> 4.0)
rails-observers (~> 0.1.1)
activesupport (4.0.3)
i18n (~> 0.6, >= 0.6.4)
minitest (~> 4.2)
Expand All @@ -29,6 +34,15 @@ GEM
arel (4.0.2)
atomic (1.1.15)
awesome_print (1.2.0)
backbone-on-rails (1.1.1.0)
actionmailer
actionpack
activemodel
activeresource
eco
ejs
jquery-rails
railties
bcrypt (3.1.7)
bcrypt-ruby (3.1.5)
bcrypt (>= 3.1.3)
Expand Down Expand Up @@ -76,6 +90,8 @@ GEM
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-rails-source-maps (1.4.0)
coffee-script-source (>= 1.6.1)
coffee-script (2.2.0)
coffee-script-source
execjs
Expand Down Expand Up @@ -109,6 +125,12 @@ GEM
json
thread
thread_safe
eco (1.0.0)
coffee-script
eco-source
execjs
eco-source (1.1.0.rc.1)
ejs (1.1.1)
erb2haml (0.1.5)
html2haml
erubis (2.7.0)
Expand Down Expand Up @@ -149,6 +171,10 @@ GEM
activesupport (>= 4.0.1)
haml (>= 3.1, < 5.0)
railties (>= 4.0.1)
haml_coffee_assets (1.16.0)
coffee-script (~> 2.0)
sprockets (~> 2.0)
tilt (~> 1.1)
hashie (2.0.5)
highline (1.6.21)
hike (1.2.3)
Expand Down Expand Up @@ -187,6 +213,7 @@ GEM
addressable (~> 2.3)
letter_opener (1.2.0)
launchy (~> 2.2)
libv8 (3.16.14.3)
listen (2.7.0)
celluloid (>= 0.15.2)
celluloid-io (>= 0.15.0)
Expand Down Expand Up @@ -254,7 +281,25 @@ GEM
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.3)
sprockets-rails (~> 2.0.0)
rails-assets-backbone (1.1.2)
rails-assets-underscore (>= 1.5.0)
rails-assets-backbone.babysitter (0.1.1)
rails-assets-backbone.marionette (1.8.3)
rails-assets-backbone (>= 1.0.0, < 1.1.3)
rails-assets-backbone.babysitter (>= 0.1.0, < 0.2)
rails-assets-backbone.wreqr (>= 1.0.0, < 2)
rails-assets-jquery (>= 1.8.0, < 2.1.1)
rails-assets-underscore (>= 1.4.4, < 1.6.1)
rails-assets-backbone.stickit (0.7.0)
rails-assets-backbone.wreqr (1.2.0)
rails-assets-backbone (>= 1.0.0, < 1.1.3)
rails-assets-underscore (>= 1.4.4, < 1.6.1)
rails-assets-jquery (2.1.0)
rails-assets-moment (2.6.0)
rails-assets-underscore (1.6.0)
rails-db-resetup (0.0.2)
rails-observers (0.1.2)
activemodel (~> 4.0)
railties (4.0.3)
actionpack (= 4.0.3)
activesupport (= 4.0.3)
Expand All @@ -265,6 +310,7 @@ GEM
rb-fsevent (0.9.4)
rb-inotify (0.9.3)
ffi (>= 0.5.0)
ref (1.0.5)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
Expand Down Expand Up @@ -317,6 +363,9 @@ GEM
term-ansicolor (1.3.0)
tins (~> 1.0)
terminal-table (1.4.5)
therubyracer (0.12.1)
libv8 (~> 3.16.14.0)
ref
thin (1.6.2)
daemons (>= 1.0.9)
eventmachine (>= 1.0.0)
Expand Down Expand Up @@ -355,13 +404,15 @@ PLATFORMS

DEPENDENCIES
awesome_print
backbone-on-rails
better_errors
binding_of_caller
brakeman
bugsnag
bullet
capybara
coffee-rails (~> 4.0.0)
coffee-rails-source-maps
compass-rails
database_cleaner
delorean
Expand All @@ -375,6 +426,7 @@ DEPENDENCIES
guard-rspec
guard-sprockets2
haml-rails
haml_coffee_assets
hirb
hirb-unicode
i18n-tasks
Expand All @@ -395,6 +447,9 @@ DEPENDENCIES
pry-stack_explorer
quiet_assets
rails (= 4.0.3)
rails-assets-backbone.marionette
rails-assets-backbone.stickit
rails-assets-moment
rails-db-resetup
rb-fsevent
rspec-rails
Expand All @@ -404,6 +459,7 @@ DEPENDENCIES
spring-commands-rspec
sqlite3
tapp
therubyracer
thin
uglifier (>= 1.3.0)
unicorn
Expand Down
15 changes: 0 additions & 15 deletions app/assets/javascripts/application.js

This file was deleted.

19 changes: 19 additions & 0 deletions app/assets/javascripts/application.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#= require jquery
#= require jquery_ujs
#= require hamlcoffee
#= require underscore
#= require backbone
#= require backbone.marionette
#= require backbone.stickit/backbone.stickit
#= require ktra
#= require_tree ./templates
#= require_tree ./models
#= require_tree ./collections
#= require_tree ./views
#= require_tree ./layouts
#= require_tree ./controllers
#= require_tree ./routers
#= require_self

$(document).ready ->
Ktra.initialize()
4 changes: 4 additions & 0 deletions app/assets/javascripts/collections/tasks.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Ktra.Collections.Tasks extends Backbone.Collection
model: Ktra.Models.Task
url: '/tasks'

4 changes: 4 additions & 0 deletions app/assets/javascripts/collections/weeks.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Ktra.Collections.Weeks extends Backbone.Collection
model: Ktra.Models.Week
url: '/weeks'

23 changes: 23 additions & 0 deletions app/assets/javascripts/controllers/main.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Ktra.Controllers.Main extends Marionette.Controller
initialize: ->
Ktra.Application.addRegions
header: '.header'
form: '.new-task'
tasks: '.tasks'

@user ?= new Ktra.Models.User()
@user.fetch(reset: true).done =>
headerView = new Ktra.Views.Header(model: @user)
Ktra.Application.header.show(headerView)

tasks: ->
formView = new Ktra.Views.Form()
Ktra.Application.form.show(formView)

@tasks = new Ktra.Collections.Tasks()

@tasks.fetch(reset: true).done =>
tasksView = new Ktra.Views.Tasks(collection: @tasks)
Ktra.Application.tasks.show(tasksView)

tasksView.listenTo formView, 'task:created', tasksView.rebuild
16 changes: 14 additions & 2 deletions app/assets/javascripts/ktra.js.coffee
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
jQuery ->
$(document).on "keypress", "input:not(.allow-submit)", (event) -> event.which != 13
window.Ktra =
Models: {}
Collections: {}
Controllers: {}
Layouts: {}
Views: {}
Routers: {}
Application: new Backbone.Marionette.Application()
initialize: ->
Ktra.Application.addInitializer ->
new Ktra.Routers.Main()
Backbone.history.start()
Ktra.Application.start()

5 changes: 5 additions & 0 deletions app/assets/javascripts/models/task.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Ktra.Models.Task extends Backbone.Model
urlRoot: '/tasks'
defaults:
status: 'unstarted'
point: '0'
3 changes: 3 additions & 0 deletions app/assets/javascripts/models/user.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Ktra.Models.User extends Backbone.Model
urlRoot: '/account'
parse: (res) -> res.user
2 changes: 2 additions & 0 deletions app/assets/javascripts/models/week.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Ktra.Models.Week extends Backbone.Model
urlRoot: '/weeks'
6 changes: 6 additions & 0 deletions app/assets/javascripts/routers/main.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Ktra.Routers.Main extends Backbone.Marionette.AppRouter
controller: new Ktra.Controllers.Main()

appRoutes:
'': 'tasks'
'tasks': 'tasks'
36 changes: 0 additions & 36 deletions app/assets/javascripts/tasks.js.coffee

This file was deleted.

1 change: 1 addition & 0 deletions app/assets/javascripts/templates/empty_task.jst.hamlc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%p.error-message There's no tasks yet.
12 changes: 12 additions & 0 deletions app/assets/javascripts/templates/form.jst.hamlc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
%form#new_task.new_task
.field
%input{autocomplete: "off", id: "task_title", name: "task[title]", placeholder: "NEW TASK TITLE", required: "required", type: "text"}
%i.fa.fa-pencil
.field.point-radio
%ul
- _.each [0, 1, 2, 3, 5, 8], (pt) ->
%li{class: "pt#{pt}"}
%input{type: 'radio', id: "task_point_#{pt}", value: "#{pt}", name: 'task[point]'}
%label{for: "task_point_#{pt}"}
%span.num<>= pt
pt
9 changes: 9 additions & 0 deletions app/assets/javascripts/templates/header.jst.hamlc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
%h1
%a K-tra!
.user
%p.image
%a{href: '#weeks'}
%img{src: "#{@image}", alt: "#{@nickname}"}
%p.name
%a{href: '#weeks'}
= @nickname
10 changes: 10 additions & 0 deletions app/assets/javascripts/templates/task.jst.hamlc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
%a
%span.title<>= @title
%span.point<>
%span.num<>= @point
pt
%i.fa.fa-chevron-right
%span.status<>
%button{type: 'submit'}
%i.fa.fa-play-circle
START
2 changes: 2 additions & 0 deletions app/assets/javascripts/views/empty_task.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Ktra.Views.EmptyTask extends Backbone.Marionette.ItemView
template: JST['templates/empty_task']
Loading