Skip to content

Commit

Permalink
images.and icons.
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidkahl committed Mar 7, 2012
1 parent 40b26b9 commit af2dfa1
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 36 deletions.
7 changes: 4 additions & 3 deletions articler.coffee
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Articler Class - Handles all article functions
config = require './config.coffee'
cradle = require 'cradle'

class Articler
constructor: (host, port) ->
constructor: (host, port, collection) ->
@.connect = new cradle.Connection host, port, {
cache: true
raw: false
}
@.db = @.connect.database 'sparks'
@.db = @.connect.database collection

findAll: (callback) ->
@.db.view 'sparks/all', {descending: true}, (err, res) ->
if (err)
Expand Down
10 changes: 6 additions & 4 deletions auth.coffee
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
config = require './config.coffee'

everyauth = module.exports = require 'everyauth'
everyauth.debug = false
everyauth.debug = true
everyauth.everymodule.moduleErrback (err) ->
console.log err
console.log "Auth ERROR - "+err
everyauth.twitter
.consumerKey('umY6lNpuhh4B6I1BshJMLA')
.consumerSecret('I4qEqVHgZM0LEVY61sE9w1tFW5lTATCxOy7CwaO0NA')
.consumerKey(config.twitterConsumerKey)
.consumerSecret(config.twitterConsumerSecret)
.findOrCreateUser((session, token, secret, user) ->
promise = @.Promise().fulfill user
).redirectPath '/'
7 changes: 5 additions & 2 deletions config.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
config = {}
config.port = 5984
config.host = 'arvidkahl.iriscouch.com'
config.mainDBPort = 5984
config.sessionDBHost = config.mainDBHost = 'arvidkahl.iriscouch.com'
config.mainDB = 'sparks'
config.sessionDBName = 'sessions'
config.twitterConsumerKey = 'umY6lNpuhh4B6I1BshJMLA'
config.twitterConsumerSecret = 'I4qEqVHgZM0LEVY61sE9w1tFW5lTATCxOy7CwaO0NA'

module.exports = config
26 changes: 9 additions & 17 deletions main.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Configuration Files
config = require './config.coffee'

# Requires and Variables
exp = require 'express'
app = exp.createServer()
Expand All @@ -7,13 +10,10 @@ less = require 'less'
fs = require 'fs'
md = require('node-markdown').Markdown
auth = require './auth.coffee'
config = require './config.coffee'

# Session perstistence implemented with CouchDB
sessionDB = require('connect-couchdb')(exp)

#auth.helpExpress app

# App Configuration
app.configure () ->
app.set 'view engine', 'jade'
Expand All @@ -22,43 +22,35 @@ app.configure () ->
app.use exp.methodOverride()
app.use exp.bodyParser()
app.use exp.cookieParser()
app.use exp.session {secret: 'nawollenwirdochmalsehn', store: new sessionDB({host: config.host,name: config.sessionDBName, reapInterval: 600000, compactInterval: 300000})}
app.use exp.session {secret: 'nawollenwirdochmalsehn', store: new sessionDB({host: config.sessionDBHost,name: config.sessionDBName, reapInterval: 600000, compactInterval: 300000})}
app.use exp.compiler { src: __dirname + '/public', dest: __dirname + '/public', enable: ['less'] }
app.use exp.static __dirname + '/public'
app.use auth.middleware()

auth.helpExpress app

# Articler Class
Articler = require('./articler').Articler
article = new Articler config.host, config.port
Articler = require('./articler.coffee').Articler
article = new Articler config.mainDBHost, config.mainDBPort, config.mainDB

app.get '/', (req, res) ->
# if (req.session.auth)
# console.log "You are authed."
# else
# console.log "You are not authed."
article.findAll (err, docs) ->
# console.log "GET /"
# console.log req.user
res.render 'index', {
locals: {
title: 'Sparks'
title: 'Spark.'
articles: docs
}
}

app.get '/new', (req, res) ->
# console.log "GET /new"
console.log req.user
res.render 'new', {locals: {title: 'Sparks / New Post - '}}
res.render 'new', {locals:{title:'Spark.'}}

app.post '/new', (req, res) ->
# console.log "POST /new"
# console.log req.param 'title'
article.save {
title: req.param 'title'
body: req.param 'body'
url: req.param 'url'
created_at: new Date()
}, (err, docs) ->
res.redirect('/')
Expand Down
8 changes: 5 additions & 3 deletions views/index.jade
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
div.span10
- each article in articles
.article
.article.well
h1= article.title
span.created= article.created_at
span.body= article.body
div.created= article.created_at
div.image
img(src=article.url)
div.body= article.body
div.span2
h3 Secondary content
16 changes: 13 additions & 3 deletions views/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,21 @@ html
div.nav-collapse
ul.nav
li
a(href='#') Home
a(href='/')
i.icon-home.icon-white
| Home
li
a(href='#') About
a(href='/all')
i.icon-book.icon-white
| Browse Images
li
a(href='#') Contact
a(href='/new')
i.icon-plus-sign.icon-white
| Add Image
li
a(href='#')
i.icon-envelope.icon-white
| Contact
p.navbar-text.pull-right
- if (everyauth.loggedIn)
span= "Logged in as "+ everyauth.twitter.user.name +" "
Expand Down
13 changes: 9 additions & 4 deletions views/new.jade
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
form(method="post")
input(type="text", id="title", name="title", placeholder="Title")
textarea(name="body", id="body", rows="20")
input(type="submit", value="Publish")
form.form-horizontal(method="post")
.control-group
input.input-medium(type="text", id="title", name="title", placeholder="Title of the image")
.control-group
input.input-medium(type="text", id="url", name="url", placeholder="URL to image")
.control-group
textarea(name="body", id="body", rows="20", placeholder="Please enter a short description here.")
.control-group
input.btn(type="submit", value="Add Image to Spark.")

0 comments on commit af2dfa1

Please sign in to comment.