Skip to content

Commit

Permalink
redo project generator
Browse files Browse the repository at this point in the history
  • Loading branch information
nateps committed May 29, 2013
1 parent c730c04 commit 70638c9
Show file tree
Hide file tree
Showing 55 changed files with 1,135 additions and 757 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/bin/lib
.DS_Store
*.swp
node_modules
test-output.tmp
*swp
*un~
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
*.swp
node_modules
test-output.tmp
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
language: node_js
node_js:
- 0.6
- 0.8
- 0.10
17 changes: 0 additions & 17 deletions Makefile

This file was deleted.

2 changes: 2 additions & 0 deletions bin/default-coffee/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
*.swp
1 change: 1 addition & 0 deletions bin/default-coffee/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node server.js
1 change: 1 addition & 0 deletions bin/default-coffee/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# $$project$$
27 changes: 27 additions & 0 deletions bin/default-coffee/npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
0 info it worked if it ends with ok
1 verbose cli [ 'node', '/usr/local/bin/npm', 'install' ]
2 info using npm@1.2.21
3 info using node@v0.10.7
4 verbose read json /Users/nateps/codeparty/derby/bin/default-coffee/package.json
5 error install Couldn't read dependencies
6 error Error: Invalid name: "$$project$$"
6 error at ensureValidName (/usr/local/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/fixer.js:179:15)
6 error at Object.module.exports.fixNameField (/usr/local/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/fixer.js:104:5)
6 error at /usr/local/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/normalize.js:28:38
6 error at Array.forEach (native)
6 error at normalize (/usr/local/lib/node_modules/npm/node_modules/read-package-json/node_modules/normalize-package-data/lib/normalize.js:27:15)
6 error at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:304:33)
6 error at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:118:48)
6 error at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:228:40
6 error at fs.js:266:14
6 error at Object.oncomplete (fs.js:107:15)
7 error If you need help, you may report this log at:
7 error <http://github.com/isaacs/npm/issues>
7 error or email it to:
7 error <npm-@googlegroups.com>
8 error System Darwin 12.3.0
9 error command "node" "/usr/local/bin/npm" "install"
10 error cwd /Users/nateps/codeparty/derby/bin/default-coffee
11 error node -v v0.10.7
12 error npm -v 1.2.21
13 verbose exit [ 1, true ]
27 changes: 27 additions & 0 deletions bin/default-coffee/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "$$project$$",
"description": "",
"version": "0.0.0",
"repository": {
"type": "git",
"url": ""
},
"scripts": {
"start": "./node_modules/coffee-script/bin/coffee server.coffee"
},
"dependencies": {
"derby": "0.5.x",
"express": "~3.2.5",
"redis": "~0.8.3",
"livedb-mongo": "~0.1.0",
"racer-browserchannel": "~0.1.0",
"connect-mongo": "~0.3.2",
"derby-ui-boot": "0.1.x",
"coffeeify": "~0.4.0",
"coffee-script": "~1.6.2"
},
"engines": {
"node": "0.10.x"
},
"private": true
}
1 change: 1 addition & 0 deletions bin/default-coffee/server.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('derby').run __dirname + '/src/server/index.coffee'
44 changes: 44 additions & 0 deletions bin/default-coffee/src/$$app$$/index.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
app = require('derby').createApp(module)
.use(require 'derby-ui-boot')
.use(require '../../ui/index.coffee')


# ROUTES #

# Derby routes are rendered on the client and the server
app.get '/', (page) ->
page.render 'home'

app.get '/list', (page, model, params, next) ->
# This value is set on the server in the `createUserId` middleware
userId = model.get '_session.userId'

# Create a scoped model, which sets the base path for all model methods
user = model.at 'users.' + userId

# Create a mongo query that gets the current user's items
itemsQuery = model.query 'items', {userId}

# Get the inital data and subscribe to any updates
model.subscribe user, itemsQuery, (err) ->
return next err if err

# Create references that can be used in templates or controller methods
model.ref '_page.user', user
itemsQuery.ref '_page.items'

user.increment 'visits'
page.render 'list'


# CONTROLLER FUNCTIONS #

app.fn 'list.add', (e, el) ->
newItem = @model.del '_page.newItem'
return unless newItem
newItem.userId = @model.get '_session.userId'
@model.add 'items', newItem

app.fn 'list.remove', (e) ->
id = e.get ':item.id'
@model.del 'items.' + id
20 changes: 20 additions & 0 deletions bin/default-coffee/src/server/error.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
path = require 'path'
derby = require 'derby'

module.exports = ->
staticPages = derby.createStatic path.dirname(path.dirname(__dirname))

return (err, req, res, next) ->
return next() unless err?

console.log if err.stack then err.stack else err

# Customize error handling here
message = err.message || err.toString()
status = parseInt message
status = if 400 <= status < 600 then status else 500

if status is 403 || status is 404 || status is 500
staticPages.render 'error', res, status.toString(), status
else
res.send status
78 changes: 78 additions & 0 deletions bin/default-coffee/src/server/index.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
express = require 'express'
derby = require 'derby'
racerBrowserChannel = require 'racer-browserchannel'
liveDbMongo = require 'livedb-mongo'
coffeeify = require 'coffeeify'
MongoStore = require('connect-mongo')(express)
$$app$$ = require '../$$app$$/index.coffee'
error = require './error.coffee'

expressApp = module.exports = express()

# Get Redis configuration
if process.env.REDIS_HOST
redis = require('redis').createClient process.env.REDIS_PORT, process.env.REDIS_HOST
redis.auth process.env.REDIS_PASSWORD
else if process.env.OPENREDIS_URL
redisUrl = require('url').parse process.env.OPENREDIS_URL
redis = require('redis').createClient redisUrl.port, redisUrl.hostname
redis.auth redisUrl.auth.split(":")[1]
else
redis = require('redis').createClient()
redis.select process.env.REDIS_DB || 1
# Get Mongo configuration
mongoUrl = process.env.MONGO_URL || process.env.MONGOHQ_URL ||
'mongodb://localhost:27017/project'

# The store creates models and syncs data
store = derby.createStore
db: liveDbMongo(mongoUrl + '?auto_reconnect', safe: true)
redis: redis

store.on 'bundle', (browserify) ->
# Add support for directly requiring coffeescript in browserify bundles
browserify.transform coffeeify

createUserId = (req, res, next) ->
model = req.getModel()
userId = req.session.userId ||= model.id()
model.set '_session.userId', userId
next()

expressApp
.use(express.favicon())
# Gzip dynamically
.use(express.compress())
# Respond to requests for application script bundles
.use($$app$$.scripts store)
# Serve static files from the public directory
# .use(express.static __dirname + '/../../public')

# Add browserchannel client-side scripts to model bundles created by store,
# and return middleware for responding to remote client messages
.use(racerBrowserChannel store)
# Add req.getModel() method
.use(store.modelMiddleware())

# Parse form data
# .use(express.bodyParser())
# .use(express.methodOverride())

# Session middleware
.use(express.cookieParser())
.use(express.session
secret: process.env.SESSION_SECRET || 'YOUR SECRET HERE'
store: new MongoStore(url: mongoUrl, safe: true)
)
.use(createUserId)

# Create an express middleware from the app's routes
.use($$app$$.router())
.use(expressApp.router)
.use(error())


# SERVER-SIDE ROUTES #

expressApp.all '*', (req, res, next) ->
next '404: ' + req.url
21 changes: 21 additions & 0 deletions bin/default-coffee/styles/$$app$$/home.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.home
.content > .container
margin: 0 auto
max-width: 700px

// Main marketing message and sign up button
.jumbotron
margin: 20px 0 60px
text-align: center
.jumbotron h1
font-size: 72px
line-height: 1
.jumbotron .btn
font-size: 21px
padding: 14px 24px

// Supporting marketing content
.marketing
margin: 60px 0 0
.marketing p + h4
margin-top: 28px
13 changes: 13 additions & 0 deletions bin/default-coffee/styles/$$app$$/index.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@import 'nib/vendor'
@import './home'
@import './list'

.container
padding: 0 10px

.content
padding: 80px 0

footer
border-top: 1px solid #eee
padding: 19px 0
3 changes: 3 additions & 0 deletions bin/default-coffee/styles/$$app$$/list.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.list
.visits
margin-top: 30px
3 changes: 3 additions & 0 deletions bin/default-coffee/styles/error/index.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body
padding-top: 60px
padding-left: 40px
14 changes: 14 additions & 0 deletions bin/default-coffee/styles/ui/connectionAlert.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.ui-connection
position: absolute
text-align: center
top: 0
left: 0
width: 100%
height: 0
z-index: 2000

.ui-connection > .alert
border-top: 0
border-radius: 0 0 4px 4px
padding-right: 14px
display: inline-block
2 changes: 2 additions & 0 deletions bin/default-coffee/styles/ui/index.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@import 'nib/vendor'
@import './connectionAlert'
14 changes: 14 additions & 0 deletions bin/default-coffee/ui/connectionAlert/index.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exports.setup = (library) ->
library.view.fn 'sentenceCase', (text) ->
text && text.charAt(0).toUpperCase() + text.slice(1)

exports.reconnect = ->
# Hide the reconnect link for a second after clicking it
@model.set 'hideReconnect', true
setTimeout =>
@model.set 'hideReconnect', false
, 1000
@model.reconnect()

exports.reload = ->
window.location.reload()
18 changes: 18 additions & 0 deletions bin/default-coffee/ui/connectionAlert/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<connectionAlert:>
<div class="ui-connection">
{#unless equal($connection.state, 'connected')}
<p class="alert">
{#if equal($connection.state, 'stopped')}
Unable to reconnect &ndash; <a x-bind="click: reload">Reload</a>
{else}
<span>{sentenceCase($connection.state)}</span>
<span>
<!-- a :self alias is automatically created per component -->
{#unless :self.hideReconnect}
&sp;&ndash; <a x-bind="click: reconnect">Reconnect</a>
{/}
</span>
{/}
</p>
{/}
</div>
8 changes: 8 additions & 0 deletions bin/default-coffee/ui/index.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
config =
filename: __filename
styles: '../styles/ui'
scripts:
connectionAlert: require './connectionAlert/index.coffee'

module.exports = (app, options) ->
app.createLibrary config, options
32 changes: 32 additions & 0 deletions bin/default-coffee/views/$$app$$/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Body:>
<div class="jumbotron">
<h1>Hello world!</h1>
<p class="lead">Cras justo odio, dapibus ac facilisis in, egestas eget quam. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
<a class="btn btn-large btn-success" href="/list">Try it now</a>
</div>

<hr>

<div class="row-fluid marketing">
<div class="span6">
<h4>Subheading</h4>
<p>Donec id elit non mi porta gravida at eget metus. Maecenas faucibus mollis interdum.</p>

<h4>Subheading</h4>
<p>Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Cras mattis consectetur purus sit amet fermentum.</p>

<h4>Subheading</h4>
<p>Maecenas sed diam eget risus varius blandit sit amet non magna.</p>
</div>

<div class="span6">
<h4>Subheading</h4>
<p>Donec id elit non mi porta gravida at eget metus. Maecenas faucibus mollis interdum.</p>

<h4>Subheading</h4>
<p>Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Cras mattis consectetur purus sit amet fermentum.</p>

<h4>Subheading</h4>
<p>Maecenas sed diam eget risus varius blandit sit amet non magna.</p>
</div>
</div>
Loading

0 comments on commit 70638c9

Please sign in to comment.