From c55a96083a4c465a24be193683f377f28416fb2e Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Sat, 1 Jun 2013 15:30:42 -0400 Subject: [PATCH] server side half of #83 --- core/shared/api.js | 2 +- core/shared/models/post.js | 23 +++++++++++++++++------ core/test/ghost/api_posts_spec.js | 15 +++++++++++---- core/test/ghost/helpers.js | 17 ++++++++++++----- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/core/shared/api.js b/core/shared/api.js index 0d32514bc6..f30ebc7ec6 100644 --- a/core/shared/api.js +++ b/core/shared/api.js @@ -24,7 +24,7 @@ // takes filter / pagination parameters // returns a list of posts in a json response browse: function (options) { - return dataProvider.Post.findAll(options); + return dataProvider.Post.findPage(options); }, // takes an identifier (id or slug?) // returns a single post in a json response diff --git a/core/shared/models/post.js b/core/shared/models/post.js index 115a875792..143132ac3d 100644 --- a/core/shared/models/post.js +++ b/core/shared/models/post.js @@ -16,6 +16,10 @@ hasTimestamps: true, + defaults: { + status: 'draft' + }, + initialize: function () { this.on('creating', this.creating, this); this.on('saving', this.saving, this); @@ -69,17 +73,24 @@ var postCollection; // Allow findPage(n) - if (!_.isObject(opts)) { + if (_.isString(opts) || _.isNumber(opts)) { opts = {page: opts}; } - opts = _.defaults(opts || {}, { - page: 1, + opts = _.extend({page: 1}, { limit: 15, - where: null - }); + where: {}, + status: 'published' + }, opts); + postCollection = Posts.forge(); + // Unless `all` is passed as an option, filter on + // the status provided. + if (opts.status !== 'all') { + opts.where.status = opts.status; + } + // If there are where conditionals specified, add those // to the query. if (opts.where) { @@ -93,7 +104,7 @@ return postCollection .query('limit', opts.limit) .query('offset', opts.limit * (opts.page - 1)) - .fetch(_.omit(opts, 'page', 'limit', 'where')) + .fetch(_.omit(opts, 'page', 'limit', 'where', 'status')) .then(function (collection) { var qb; diff --git a/core/test/ghost/api_posts_spec.js b/core/test/ghost/api_posts_spec.js index 95524025f1..295dab497e 100644 --- a/core/test/ghost/api_posts_spec.js +++ b/core/test/ghost/api_posts_spec.js @@ -72,7 +72,7 @@ }).then(null, done); }); - it('can add', function (done) { + it('can add, defaulting as a draft', function (done) { var newPost = { title: 'Test Title 1', content: 'Test Content 1' @@ -81,9 +81,10 @@ PostModel.add(newPost).then(function (createdPost) { should.exist(createdPost); - createdPost.attributes.title.should.equal(newPost.title, "title is correct"); - createdPost.attributes.content.should.equal(newPost.content, "content is correct"); - createdPost.attributes.slug.should.equal(newPost.title.toLowerCase().replace(/ /g, '-'), 'slug is correct'); + createdPost.get('status').should.equal('draft'); + createdPost.get('title').should.equal(newPost.title, "title is correct"); + createdPost.get('content').should.equal(newPost.content, "content is correct"); + createdPost.get('slug').should.equal(newPost.title.toLowerCase().replace(/ /g, '-'), 'slug is correct'); done(); }).then(null, done); @@ -173,6 +174,12 @@ paginationResult.pages.should.equal(3); + return PostModel.findPage({limit: 10, page: 2, status: 'all'}); + + }).then(function (paginationResult) { + + paginationResult.pages.should.equal(11); + done(); }).then(null, done); diff --git a/core/test/ghost/helpers.js b/core/test/ghost/helpers.js index 7d1d422ad2..31202b291d 100644 --- a/core/test/ghost/helpers.js +++ b/core/test/ghost/helpers.js @@ -5,13 +5,14 @@ process.env.NODE_ENV = process.env.TRAVIS ? 'travis' : 'testing'; var knex = require('../../shared/models/base').Knex, + when = require('when'), migrations = { one: require("../../shared/data/migration/001") }, helpers, samplePost; - samplePost = function (i, lang) { + samplePost = function (i, status, lang) { return { title: "Test Post " + i, slug: "ghost-from-fiction-to-function-" + i, @@ -19,7 +20,7 @@ content_html: "

Three days ago I released a concept page<\/a> for a lite version of WordPress that I've been thinking about for a long time, called Ghost. I think it's fair to say that I didn't quite anticipate how strong the reaction would be - and I've hardly had time to catch my breath in the last 72 hours.<\/p>\n

The response was overwhelming, and overwhelmingly positive. In the first 6 hours my site got 35,000 page views after hitting the number 1 slot on Hacker News<\/a>. As of right now, the traffic count is just over 91,000 page views<\/a> - and Ghost has been featured all over the place. Notable mentions so far include Christina Warren from Mashable, who wrote about it<\/a>. Michael Carney from PandoDaily interviewed me about it<\/a>. Someone even wrote about it in Chinese<\/a>. That's pretty cool.\\n

The feedback has been amazing, and while it's impossible to reply to all of the messages individually, I'm getting to as many of them as I can and I want to thank each and every one of you who took the time to send me a message or share the concept because you liked it. Now that the initial storm has died down a bit, I wanted to take some time to answer some of the more common questions and talk about what's next.<\/p>\n

FAQ - Continued...<\/h2>\n

The most common question, bizarrely:<\/p>\n

Oh my god, why is that whole page made of images? What's wrong with you? \/\/ I can't take you seriously \/\/ Don't you know anything about the web? \/\/ You are literally Satan re-incarnate.<\/strong><\/em><\/h5>\n

This was really the only negativity I got in response to the post, and it surprised me. I put together the concept page as... just that... a concept. It was a way for me to get the ideas out of my head and \"down on paper\" - or so to speak. I used photoshop as a tool<\/em> to write down my idea with text and images. If I used a sketchbook as a tool <\/em>to create images and handwritten notes, then uploaded scans of it, I doubt anyone would complain. The concept page was never supposed to be a finished product because I had no idea if there would be any interest in it. I had no motivation to waste hours coding a custom layout for something might only ever be read by a few people and then forgotten.<\/p>\n

Hardware manufacturers make hundreds of foam cutout prototypes of products before they build one with working buttons and screens. I'm aware of all the usability problems with a web page made of images, and equally, foam cutouts without buttons or screens aren't particularly user friendly either. They're not supposed to be.<\/p>\n

Let's move on.<\/p>\n

What? Why no comments? I need comments.<\/strong><\/em><\/h5>\n

Because comments add a layer of complexity that is beyond the core focus of this platform, which is publishing. Again, that's not to say you couldn't have any comments. This could easily be added with a dedicated plugin where you own the data or (as mentioned) there are third party providers such as Disqus, IntenseDebate, Livefyre and Facebook who all have great platforms. The point of this isn't to say \"you can't have comments\" - it's to say \"comments aren't on by default\". It's about simplicity, more than anything else.<\/p>\n

Yeah, but WordPress are already going to revise their dashboard, WordPress.com is experimenting with a potential simplified version... so why bother with this?<\/strong><\/em><\/h5>\n

\"\"<\/a><\/p>\n

Sorry, but Tumblr already did this - it's not the future of blogging, it's the past.<\/p>\n

Ghost isn't about sharing \"Fuck Yeah [Dogs<\/a>\/Sharks<\/a>\/Girls with Tattoos<\/a>]\" - it's about publishing - which means writing - rather than mashing a few buttons to make sure that everyone can see and appreciate your latest funny picture\/status, which is surely the most funny picture\/status you've ever posted.<\/p>\n

Tumblr, Pinterest and Facebook already have this locked down. It's not the future.<\/p>\n

So... are you actually going to build this thing?<\/strong><\/em><\/h5>\n

The concept page was a way for me to test demand and interest. To see if anyone actually agreed with my frustrations and, more importantly, my solutions. I plucked a random figure of \"10,000 pageviews\" out of the air before I hit the publish button. If it got less than 10,000 pageviews, I would surrender to the fact that it would only ever be an idea. I've now exceeded that goal 9 times over, so yes, I'm looking at how Ghost can now be made into a reality.<\/p>\n

How can I find out when it's done? \/\/ SHUT UP AND TAKE MY MONEY<\/strong><\/em><\/h5>\n

Ok, ok - there's a holding page up on http:\/\/TryGhost.org<\/a> - put your email address in.<\/p>\n


\n

How are you going to do this?<\/h3>\n

There's three main ways of going about this, each has merits as well as drawbacks.<\/p>\n

1.) Build it from scratch<\/strong><\/em> - Many people (particularly the Hacker News crowd) expressed the sentiment that there was little point in forking WordPress. When you're going to strip out so much, you get to a point where you might as well start from scratch anyway. Take away the crutches of being stuck with older technologies and put together something which is as sophisticated in code as it is in UI\/UX.<\/p>\n