Skip to content

Commit

Permalink
可解析大样式文件,支持https协议
Browse files Browse the repository at this point in the history
  • Loading branch information
switer committed Jan 20, 2013
1 parent 0af258d commit d0f006c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
5 changes: 2 additions & 3 deletions examples/package.js
@@ -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/"
]
}
7 changes: 6 additions & 1 deletion lib/coverhtml.js
Expand Up @@ -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 ++) {
Expand Down
2 changes: 1 addition & 1 deletion lib/loader.js
Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions phantomrun.js
Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d0f006c

Please sign in to comment.