Permalink
Browse files

refactored

  • Loading branch information...
1 parent 67f9308 commit c7c252776635f1668fb23766bc3e5643a81eccfb @juliangruber committed Feb 17, 2013
Showing with 171 additions and 201 deletions.
  1. +1 −1 .gitignore
  2. +20 −10 README.md
  3. +1 −1 example/{ → cached}/cache.js
  4. +0 −16 example/sites.js
  5. +21 −0 example/sites/sites.js
  6. +45 −65 lib/review.js
  7. +77 −102 lib/snapshot.js
  8. +6 −6 views/index.jade
View
@@ -1,2 +1,2 @@
node_modules
-example/cache/
+example/cached/cache
View
@@ -2,16 +2,20 @@
_Get screenshots of all your running sites in different resolutions!_
-Updating large and possibly responsively designed sites can be a hassle. You never know whether your change breakes
-anything on the other end of your sitemap, or in a certain resolution, except if have a look at every individual
+Updating large and possibly responsively designed sites can be a hassle. You
+never know whether your change breakes anything on the other end of your
+sitemap, or in a certain resolution, except if have a look at every individual
page...in every resolution you care about.
-The idea of `review` is not to test everything (and visual testing is hard) but rather use the human mind's excellent
-ability to quickly scan information and filter out what you need, i.e. what is broken.
+The idea of `review` is not to test everything (and visual testing is hard) but
+rather use the human mind's excellent ability to quickly scan information and
+filter out what you need, i.e. what is broken.
![preview](http://f.cl.ly/items/3O1w3Y0X2i0s1F1M273x/Screen%20Shot%202013-01-24%20at%2012.50.38%20PM.png)
-This screenshot is from [review-host](https://github.com/juliangruber/review-host), which hosts multiple reviews in one server.
+This screenshot is from
+[review-host](https://github.com/juliangruber/review-host), which hosts multiple
+reviews in one server.
## Usage
@@ -74,7 +78,9 @@ Display `title` in the review. Defaults to `Review`.
### review#sites(sites | fn)
-Either pass an object with titles as keys and urls as values, or a `Function` that fetches the sites to be displayed. This way, on every page load that list is refreshed and you can e.g. display all sites present in your sitemap.
+Either pass an object with titles as keys and urls as values, or a `Function`
+that fetches the sites to be displayed. This way, on every page load that list
+is refreshed and you can e.g. display all sites present in your sitemap.
```js
review.sites(function (cb) {
@@ -85,15 +91,17 @@ review.sites(function (cb) {
})
```
-See [example/sites.js](https://github.com/juliangruber/review/blob/master/example/sites.js)
+See [example/sites](https://github.com/juliangruber/review/blob/master/example/sites/sites.js)
### review#resolutions(["WxH", "WxH", ...])
Configure the resolutions to use for screenshots. Defaults to `["1200x800"]`
### review#wait(x)
-PhantomJS will wait for `x` milliseconds after loading the page before it takes the screenshot, so you can make sure your page is completely loaded. Defaults to `0`.
+PhantomJS will wait for `x` milliseconds after loading the page before it takes
+the screenshot, so you can make sure your page is completely loaded.
+Defaults to `0`.
### review#cache({ dir : 'directory', expires : 60 })
@@ -119,15 +127,17 @@ The cookie format is:
### review#cut(bool)
-If `bool` is `true` then screenshots will be cut to the exact dimensions that you specified. Without this pages can be longer than your specified height.
+If `bool` is `true` then screenshots will be cut to the exact dimensions that
+you specified. Without this pages can be longer than your specified height.
### review#listen(port)
Start the review server on port `port`.
## Installation
-You need to have phantomjs (>=1.7 if you want to use cookies) installed, get it via
+You need to have phantomjs (>=1.7 if you want to use cookies) installed, get it
+via
```bash
$ brew install phantomjs
@@ -1,4 +1,4 @@
-var review = require('..')
+var review = require('../..')
review()
.title('Super Review')
View
@@ -1,16 +0,0 @@
-var review = require('..')
-
-review()
- .title('My Review')
- .sites(function (cb) {
- setTimeout(function () {
- Math.random() > 0.5
- ? cb(null, { google : 'http://google.com/', github : 'https://github.com/' })
- : cb(null, { apple : 'http://apple.com/', yahoo : 'http://yahoo.com/' })
- }, 10)
- })
- .resolutions(['1900x1600', '1280x1024', '800x600'])
- .cut(true)
- .listen(5000, function () {
- console.log('-> Review on port 5000')
- })
@@ -0,0 +1,21 @@
+var review = require('../..')
+
+review()
+ .title('My Review')
+ .sites(function (cb) {
+ cb(null, Math.random() > 0.5
+ ? {
+ microsoft : 'http://www.microsoft.com/',
+ bootstrap : 'http://twitter.github.com/bootstrap/'
+ }
+ : {
+ words : 'http://www.newnet-soft.com/beta/',
+ alistapart : 'http://alistapart.com/'
+ }
+ )
+ })
+ .resolutions(['1900x1600', '1280x1024', '800x600'])
+ .cut(true)
+ .listen(5000, function () {
+ console.log('-> Review on port 5000')
+ })
View
@@ -1,17 +1,25 @@
+/**
+ * module dependencies
+ */
+
var express = require('express')
var span = require('span')
+var snapshot = require('./snapshot')
-module.exports = review
+/**
+ * review app
+ */
-function review () {
- var title = 'Review'
- var sites = {}
- var resolutions = ['1200x800']
- var wait = 0
- var cache = false
-
+module.exports = function review () {
var app = express()
- var snapshot = require('./snapshot')
+
+ app.set('title', 'Review')
+ app.set('sites', {})
+ app.set('resolutions', ['1200x800'])
+ app.set('wait', 0)
+ app.set('cache', false)
+ app.set('cookie', {})
+ app.set('cut', false)
app.set('view engine', 'jade')
app.set('views', __dirname + '/../views')
@@ -20,62 +28,39 @@ function review () {
/**
* setters
*/
-
- app.title = function (_title) {
- title = _title
- return app
- }
-
- app.sites = function (_sites) {
- sites = _sites
- return app
- }
-
- app.resolutions = function (_resolutions) {
- resolutions = _resolutions
- return app
- }
-
- app.wait = function (_wait) {
- wait = _wait
- return app
- }
-
- app.cache = function (_cache) {
- cache = _cache
- snapshot.cache(_cache)
- return app
- }
-
- app.cookie = function (cookie) {
- snapshot.cookie(cookie)
- return app
- }
-
- app.cut = function (cut) {
- snapshot.cut(cut)
- return app
- }
+
+ var setters = [
+ 'title', 'sites', 'resolutions', 'wait', 'cache', 'cookie', 'cut'
+ ]
+ setters.forEach(function (key) {
+ app[key] = function (value) {
+ return app.set(key, value)
+ }
+ })
/**
- * routes
+ * snapshot route
+ */
+
+ app.get('/snapshot/:url/:resolution/:wait', snapshot(app))
+
+ /**
+ * index
*/
- app.get('/', function (req, res, next) {
- if (!sites) return res.status(500).end('sites not set')
+ app.get('/', function (req, res, next) {
+ if (typeof app.get('sites') == 'function') app.get('sites')(onSites)
+ else onSites(null, app.get('sites'))
- if (typeof sites == 'function') sites(onSites)
- else onSites(null, sites)
-
- function onSites (err, sites) {
+ function onSites (err, _sites) {
if (err) return next(err)
/**
* calculate maximum screenshot width, used for scaling
*/
var maxWidth
- resolutions.forEach(function (resolution) {
+ app.get('resolutions').forEach(function (resolution) {
var width = parseInt(resolution.split('x')[0], 10)
if (!maxWidth || width > maxWidth) maxWidth = width
})
@@ -84,7 +69,7 @@ function review () {
* add css information to resolutions
*/
- var _resolutions = resolutions.map(function (resolution) {
+ var resolutions = app.get('resolutions').map(function (resolution) {
var width = parseInt(resolution.split('x')[0], 10)
return {
@@ -98,27 +83,22 @@ function review () {
* encode sites' URLs to be URL-safe
*/
- var _sites = {}
- Object.keys(sites).forEach(function (title) {
- _sites[title] = encodeURIComponent(sites[title])
+ var sites = {}
+ Object.keys(_sites).forEach(function (title) {
+ sites[title] = encodeURIComponent(_sites[title])
})
/**
* render
*/
res.render('index', {
- title : title,
- sites : _sites,
- resolutions : _resolutions,
- wait : wait,
- cache : cache,
- expires : cache? span(cache.expires * 1000) : null
+ sites : sites,
+ resolutions : resolutions,
+ expires : app.get('cache')? span(app.get('cache').expires * 1000) : null
})
}
})
-
- app.use('/snapshot', snapshot)
return app
}
Oops, something went wrong. Retry.

0 comments on commit c7c2527

Please sign in to comment.