Permalink
Browse files

可解析大样式文件,支持https协议

  • Loading branch information...
1 parent 0af258d commit d0f006c3b58efe20903f85dcaaa8c92b472b7df2 @switer committed Jan 20, 2013
Showing with 13 additions and 8 deletions.
  1. +2 −3 examples/package.js
  2. +6 −1 lib/coverhtml.js
  3. +1 −1 lib/loader.js
  4. +4 −3 phantomrun.js
View
@@ -1,9 +1,8 @@
{
"style" : [
- "style.css",
- "cv_style.css"
+ "https://a248.e.akamai.net/assets.github.com/assets/github-b6e4a9de2a215d2d19f092cdbe4739e525ed6061.css"
],
"html" : [
- "./script_insert_example.html"
+ "http://www.12306.cn/mormhweb/"
]
}
View
@@ -4,10 +4,15 @@
* @notice console log here will be takes error
*/
var args = require('system').args,
+ SELECTOR_TEMP_FILE = 'doverjs_temp_file';
+ fs = require('fs');
count = 0;
-var styleString = args[args.length - 1],
+var cwd = args[args.length - 1],
+ styleString = fs.read(cwd + SELECTOR_TEMP_FILE),
//TODO <encode:uri{encode:sel1,encode:sel2,...]encode:uri{encode:sel1,...>
styleRuleSet = styleString.split(',');
+ //guo he chai qiao
+ fs.remove(cwd + SELECTOR_TEMP_FILE);
// Console log a JSON Object
console.log('[');
for (var i = 0, len = args.length - 1; i < len ; i ++) {
View
@@ -35,7 +35,7 @@ function _loadStyleContent (uri, callback) {
//Http resource
var content = '';
if (uri.match(URI_MATCHED_REGEX)) {
- var protocal = URI_MATCHED_REGEX.match(/^https:\/\//) ? https : http;
+ var protocal = uri.match(/^https:\/\//) ? https : http;
protocal.get(uri, function(res) {
if (res.statusCode == 200) {
res.on('data', function (buffer) {
View
@@ -9,7 +9,8 @@ var HTML_TEMP_URI = 'http://localhost:3013/temp/',
HTML_TEMP_FILE_PREFIX = 'run_result_',
HTML_TEMP_FILE_SUFFIX = '.html',
DEADWEIGHT_LIB_PATH = './deadweight/bin/deadweight',
- CAPTURE_HTML_SCRIPT = './lib/coverhtml.js';
+ CAPTURE_HTML_SCRIPT = './lib/coverhtml.js',
+ SELECTOR_TEMP_FILE = 'doverjs_temp_file';
var args = process.argv.slice(2),
optionType = args.shift(),
@@ -145,8 +146,8 @@ function _captureHTMLWhithArray (htmls, styles, callback) {
for ( var s = 0; s < styles.length ; s ++ ) {
var styleRules = styles[s];
//@param <html1 html2 ...> TODO<encode:uri{encode:sel1,encode:sel2,...]encode:uri{encode:sel1,...>
- cmd = 'phantomjs ' + CAPTURE_HTML_SCRIPT + ' ' + htmls.join(' ') + ' ' + parser.parse(styleRules["content"], true).join(',');
- console.log(cmd);
+ fs.writeFileSync(localPath + '/' + SELECTOR_TEMP_FILE, parser.parse(styleRules["content"], true).join(','), 'UTF-8');
+ cmd = 'phantomjs ' + CAPTURE_HTML_SCRIPT + ' ' + htmls.join(' ') + ' ' + localPath + '/';
cp.exec(cmd, function (err, stdout,stderr) {
err && console.log(err);
console.log(stderr);

0 comments on commit d0f006c

Please sign in to comment.