Skip to content

Commit

Permalink
Simple application which using backbone.offline
Browse files Browse the repository at this point in the history
  • Loading branch information
alekseykulikov committed Mar 12, 2012
0 parents commit 7c60084
Show file tree
Hide file tree
Showing 66 changed files with 1,047 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
@@ -0,0 +1,15 @@
# Ignore bundler config
/.bundle

# Ignore local database configuration
/config/database.yml

# Ignore all logfiles and tempfiles
/log/*.log
/tmp

# OS X specific file
.DS_Store

# Ignore sprockets generated files
public/assets/
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--colour --format documentation
19 changes: 19 additions & 0 deletions Gemfile
@@ -0,0 +1,19 @@
source 'https://rubygems.org'

gem 'rails', '3.2.2'

gem 'pg'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'zurb-foundation'
gem 'jquery-rails'
gem 'rails-backbone'
gem 'eco'
end

gem 'rspec-rails', groups: [:development, :test]
142 changes: 142 additions & 0 deletions Gemfile.lock
@@ -0,0 +1,142 @@
GEM
remote: https://rubygems.org/
specs:
actionmailer (3.2.2)
actionpack (= 3.2.2)
mail (~> 2.4.0)
actionpack (3.2.2)
activemodel (= 3.2.2)
activesupport (= 3.2.2)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.1)
rack (~> 1.4.0)
rack-cache (~> 1.1)
rack-test (~> 0.6.1)
sprockets (~> 2.1.2)
activemodel (3.2.2)
activesupport (= 3.2.2)
builder (~> 3.0.0)
activerecord (3.2.2)
activemodel (= 3.2.2)
activesupport (= 3.2.2)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.2)
activemodel (= 3.2.2)
activesupport (= 3.2.2)
activesupport (3.2.2)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.0)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.2.0)
diff-lcs (1.1.3)
eco (1.0.0)
coffee-script
eco-source
execjs
eco-source (1.1.0.rc.1)
ejs (1.0.0)
erubis (2.7.0)
execjs (1.3.0)
multi_json (~> 1.0)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
jquery-rails (2.0.1)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.5)
mail (2.4.1)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.17.2)
multi_json (1.1.0)
pg (0.13.2)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.1)
rack (>= 0.4)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.2.2)
actionmailer (= 3.2.2)
actionpack (= 3.2.2)
activerecord (= 3.2.2)
activeresource (= 3.2.2)
activesupport (= 3.2.2)
bundler (~> 1.0)
railties (= 3.2.2)
rails-backbone (0.7.0)
coffee-script (~> 2.2.0)
ejs (~> 1.0.0)
railties (>= 3.1.0)
railties (3.2.2)
actionpack (= 3.2.2)
activesupport (= 3.2.2)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
rspec-mocks (~> 2.8.0)
rspec-core (2.8.0)
rspec-expectations (2.8.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.8.0)
rspec-rails (2.8.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.8.0)
sass (3.1.15)
sass-rails (3.2.4)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.31)
uglifier (1.2.3)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
zurb-foundation (2.2.0.1)
jquery-rails (>= 1.0)
rails (~> 3.1)

PLATFORMS
ruby

DEPENDENCIES
coffee-rails (~> 3.2.1)
eco
jquery-rails
pg
rails (= 3.2.2)
rails-backbone
rspec-rails
sass-rails (~> 3.2.3)
uglifier (>= 1.0.3)
zurb-foundation
1 change: 1 addition & 0 deletions README.rdoc
@@ -0,0 +1 @@
Simple web-application for your dreams
7 changes: 7 additions & 0 deletions Rakefile
@@ -0,0 +1,7 @@
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

Dreamer::Application.load_tasks
19 changes: 19 additions & 0 deletions app/assets/javascripts/application.coffee
@@ -0,0 +1,19 @@
# 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 underscore
#= require backbone
#= require backbone.offline
#
#= require dreamer
9 changes: 9 additions & 0 deletions app/assets/javascripts/collections/dreams.coffee
@@ -0,0 +1,9 @@
class App.Collections.Dreams extends Backbone.Collection
model: App.Models.Dream
url: '/api/dreams'

initialize: ->
@storage = new Storage('dreams', this)

comparator: (idea) ->
(new Date(idea.get 'created_at')).getTime()
34 changes: 34 additions & 0 deletions app/assets/javascripts/dreamer.coffee
@@ -0,0 +1,34 @@
#= require_self
#= require_tree ../templates
#= require_tree ./models
#= require_tree ./collections
#= require_tree ./views

window.l = (value) -> console.log(value)

window.keys =
backspace: 8
enter: 13
left: 37
up: 38
right: 39
down: 40

window.App =
Models: {}
Collections: {}
Views: {}
Utils: {}

init: (options) ->
App.dreams = new App.Collections.Dreams()
App.dreams.fetch()

indexView = new App.Views.DreamsIndex()
$('#content').append indexView.render().el

countView = new App.Views.DreamsCount()
$('#content').append countView.render().el

$ ->
App.init()
Empty file.
1 change: 1 addition & 0 deletions app/assets/javascripts/models/dream.coffee
@@ -0,0 +1 @@
class App.Models.Dream extends Backbone.Model
Empty file.
23 changes: 23 additions & 0 deletions app/assets/javascripts/views/dreams/count_view.coffee
@@ -0,0 +1,23 @@
class App.Views.DreamsCount extends Backbone.View
template: JST['dreams/count']
className: 'three columns'
id: 'count'

events:
'click .full': 'fullSync'
'click .part': 'incrementalSync'

initialize: ->
App.dreams.on('reset add destroy', this.render)

render: =>
$(this.el).html @template count: App.dreams.length
return this

fullSync: (event) ->
App.dreams.storage.fullSync()
return false

incrementalSync: (event) ->
App.dreams.storage.incrementalSync()
return false
55 changes: 55 additions & 0 deletions app/assets/javascripts/views/dreams/dream_view.coffee
@@ -0,0 +1,55 @@
class App.Views.DreamsItem extends Backbone.View
template: JST['dreams/dream']
className: 'panel dream'

events:
'click': 'select'
'keydown': 'keydown'
'focusout p': 'save'

initialize: (options) ->
{@parent} = options
@model.on('change', this.render)
@model.on('destroy', => $(@el).remove())

render: =>
$(@el).html @template(@model.toJSON())
$(@el).attr('id', @model.id)
@oldValue = @model.get('name')
@needSync = false

return this

select: (event) =>
@parent.deactivateDream()
@parent.activeDreamId = @model.id

$(@el).addClass('active')
this.$('p').attr('contenteditable', 'true')
this.$('p').focus()

keydown: (event) ->
startPosition = document.getSelection().baseOffset
value = this.$('p').html()
totalPosition = value.length

switch event.keyCode
when keys.left then return @parent.up() if startPosition is 0
when keys.right then return @parent.down() if startPosition is totalPosition
when keys.enter then return @parent.down()
when keys.backspace then return this.destroy() if value is '<br>' or event.ctrlKey

save: (event) ->
newValue = this.$('p').html()

if newValue isnt @oldValue and newValue isnt '<br>'
@needSync = true
@oldValue = newValue
@model.save name: newValue

destroy: ->
@parent.up()
@model.destroy()
this.remove()

return false

0 comments on commit 7c60084

Please sign in to comment.