Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejholmes committed Mar 24, 2013
1 parent a67d311 commit d146a62
Show file tree
Hide file tree
Showing 21 changed files with 5,118 additions and 3,292 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem 'middleman-livereload', '~> 3.0.0'
gem 'middleman-sync', '~> 3.0.7'
gem 'redcarpet', '~> 2.1.1'
gem 'coffee-filter', '~> 0.1.1'
gem 'haml-sprockets', github: 'ejholmes/haml-sprockets'

# Assets.
gem 'sass', '~> 3.2.5'
Expand Down
10 changes: 10 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
GIT
remote: git://github.com/ejholmes/haml-sprockets.git
revision: de8fad53e8a944f3b4d88a508a5df25c78d21f9a
specs:
haml-sprockets (0.0.8)
execjs (~> 1.4.0)
sprockets (~> 2.1)
tilt (~> 1.3)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -167,6 +176,7 @@ DEPENDENCIES
bourbon (~> 3.0.1)
coffee-filter (~> 0.1.1)
coffee-script (~> 2.2.0)
haml-sprockets!
middleman (~> 3.0.5)
middleman-favicon-maker (~> 3.0.0)
middleman-livereload (~> 3.0.0)
Expand Down
4 changes: 2 additions & 2 deletions config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
# end

helpers do
def api_base
ENV['API_BASE'] ||= 'http://localhost:5000'
def api_endpoint
ENV['API_ENDPOINT'] ||= 'http://localhost:5000'
end
end

Expand Down
20 changes: 14 additions & 6 deletions source/javascripts/app.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
require [
'underscore'
'backbone'
'router'
], (_, Backbone, Router) ->
initialize: -> Router.initialize()
#= require env
#= require_tree ./models
#= require_tree ./collections
#= require_tree ./views
#= require_tree ./templates
#= require router

class @Diet.App
initialize: ->
@router = new window.Diet.Router
Backbone.history.start()

@app = new @Diet.App
@app.initialize()
9 changes: 2 additions & 7 deletions source/javascripts/application.js.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
#= require vendor/require
#= require ./env

require [
'underscore'
], (_) ->
console.log _
#= require haml
#= require app
6 changes: 6 additions & 0 deletions source/javascripts/collections/feeds.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#= require lodash
#= require backbone

class @Diet.Collections.Feeds extends @Diet.Collection
model: window.Diet.Models.Feed
url: window.Diet.config.api_endpoint + '/subscriptions'
35 changes: 27 additions & 8 deletions source/javascripts/env.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
require.config
baseUrl: 'javascripts'
#= require lodash
#= require backbone

paths:
underscore: 'vendor/underscore'
backbone: 'vendor/backbone'
templates: 'templates'
# Override ajax requests to include cookies.
ajax = Backbone.ajax
Backbone.ajax = (request) ->
request.xhrFields = withCredentials: true
ajax(request)

@Diet =
api_base: $('meta[name=api-base]').attr('content')
# Holds all models, collections and views.
Models: { }
Collections: { }
Views: { }

# Base model for all models to extend.
Model: Backbone.Model.extend()

$.ajaxSetup xhrFields: withCredentials: true
# Base view for all views to extend.
View: Backbone.View.extend

# Public: Render a hamljs view.
template: (name, context = {}) ->
window.JST["templates/#{name}"](context)

# Base collection for all collections to extend.
Collection: Backbone.Collection.extend()

# Where config is stored.
config:
api_endpoint: $('meta[name=api_endpoint]').attr('content')
11 changes: 5 additions & 6 deletions source/javascripts/models/feed.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require [
'underscore',
'backbone'
], (_, Backbone) ->
Feed = Backbone.Model.extend()
#= require lodash
#= require backbone

Feed
class @Diet.Models.Feed extends @Diet.Model
defaults:
active: false
30 changes: 16 additions & 14 deletions source/javascripts/router.coffee
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
require [
'underscore'
'backbone'
], (_, Backbone) ->
AppRouter = Backbone.Router.extend
routes:
'items': 'items'

items: ->
console.log 'foo'

initialize: ->
router = new AppRouter
Backbone.history.start()
#= require lodash
#= require backbone

class @Diet.Router extends Backbone.Router
routes:
'' : 'index'

index: ->
app = window.app

app.feeds = new window.Diet.Collections.Feeds

app.view = new window.Diet.Views.App
app.view.render()

app.feeds.fetch(reset: true)
4 changes: 4 additions & 0 deletions source/javascripts/templates/app.jst.hamljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#sidebar
%ul#feeds
#subscribe
#main
3 changes: 3 additions & 0 deletions source/javascripts/templates/feed.jst.hamljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%a{href: '#', title: title}
%img{src: favicon}>
= title
Loading

0 comments on commit d146a62

Please sign in to comment.