-
Notifications
You must be signed in to change notification settings - Fork 44
/
ratiocinate.js
48 lines (39 loc) · 1.49 KB
/
ratiocinate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* global phantom, CSS, require, console */
(function () {
'use strict';
var url,
_ = require('./vendor/underscore-1.4.2.js'),
args = require('system').args.slice(1),
resource = require('./lib/resource.js'),
responsive = require('./lib/responsive.js'),
css = require('./lib/css.js'),
verbose = false,
isOptionOrFlag = function (item) {
return item.length > 0 && item[0] === '-';
},
optionsAndFlags = _.filter(args, isOptionOrFlag);
// parse arguments {{{
args = _.reject(args, isOptionOrFlag);
verbose = _.contains(optionsAndFlags, '-v') || _.contains(optionsAndFlags, '--verbose');
if ((args.length < 1 && verbose) || !args[0]) {
console.log('No URL specified, please pass the name of a URL or file you\'d like analysed');
} else {
url = resource.resolveUrl(args[0], verbose);
}
// }}} parse arguments
responsive.stylesByMediaQuery(url, function (styles, page) {
var fonts = page.evaluate(function () { return CSS.fontDeclarations().join('\n\n'); });
if (fonts) { console.log(fonts + '\n'); }
_.each(styles, function (properties, mediaQuery) {
if (mediaQuery) { console.log(mediaQuery + ' {'); }
console.log(_.map(
properties,
function (style, selector) {
return css.renderStyle(style, selector, mediaQuery ? 1 : 0);
}
).join('\n'));
if (mediaQuery) { console.log('}\n'); }
});
phantom.exit();
});
}());