diff --git a/articler.coffee b/articler.coffee index 3049ea4..ea53bc3 100644 --- a/articler.coffee +++ b/articler.coffee @@ -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) diff --git a/auth.coffee b/auth.coffee index 21e4c49..b67cf1f 100644 --- a/auth.coffee +++ b/auth.coffee @@ -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 '/' \ No newline at end of file diff --git a/config.coffee b/config.coffee index e867882..82eedb1 100644 --- a/config.coffee +++ b/config.coffee @@ -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 \ No newline at end of file diff --git a/main.coffee b/main.coffee index f470d42..a6e3e53 100644 --- a/main.coffee +++ b/main.coffee @@ -1,3 +1,6 @@ +# Configuration Files +config = require './config.coffee' + # Requires and Variables exp = require 'express' app = exp.createServer() @@ -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' @@ -22,7 +22,7 @@ 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() @@ -30,35 +30,27 @@ app.configure () -> 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('/') diff --git a/views/index.jade b/views/index.jade index 3bf2e71..8596e2a 100644 --- a/views/index.jade +++ b/views/index.jade @@ -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 \ No newline at end of file diff --git a/views/layout.jade b/views/layout.jade index bf6a894..8a9c6ca 100644 --- a/views/layout.jade +++ b/views/layout.jade @@ -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 +" " diff --git a/views/new.jade b/views/new.jade index f2772bf..5d41e5b 100644 --- a/views/new.jade +++ b/views/new.jade @@ -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") \ No newline at end of file +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.") \ No newline at end of file