Commit 33c5b428 authored by chriseth's avatar chriseth Committed by GitHub

Merge pull request #233 from ethereum/github-import

Do GitHub imports properly
parents 62fb4713 50aac904
......@@ -2,6 +2,7 @@
var $ = require('jquery');
var semver = require('semver');
var base64 = require('js-base64').Base64;
var utils = require('./app/utils');
var QueryParams = require('./app/query-params');
......@@ -403,7 +404,17 @@ var run = function () {
function handleGithubCall (root, path, cb) {
$('#output').append($('<div/>').append($('<pre/>').text('Loading github.com/' + root + '/' + path + ' ...')));
return $.getJSON('https://api.github.com/repos/' + root + '/contents/' + path, cb);
return $.getJSON('https://api.github.com/repos/' + root + '/contents/' + path)
.done(function (data) {
if ('content' in data) {
cb(null, base64.decode(data.content));
} else {
cb('Content not received');
}
})
.fail(function (xhr, text, err) {
cb(err);
});
}
var executionContext = new ExecutionContext();
......
......@@ -3,8 +3,6 @@ var solc = require('solc/wrapper');
var webworkify = require('webworkify');
var utils = require('./utils');
var Base64 = require('js-base64').Base64;
var EventManager = require('../lib/eventManager');
/*
......@@ -237,21 +235,23 @@ function Compiler (editor, handleGithubCall) {
files[m] = cachedRemoteFiles[m];
reloop = true;
} else if ((githubMatch = /^(https?:\/\/)?(www.)?github.com\/([^\/]*\/[^\/]*)\/(.*)/.exec(m))) {
handleGithubCall(githubMatch[3], githubMatch[4], function (result) {
if ('content' in result) {
var content = Base64.decode(result.content);
cachedRemoteFiles[m] = content;
files[m] = content;
gatherImports(files, importHints, cb);
} else {
cb(null, 'Unable to import "' + m + '"');
handleGithubCall(githubMatch[3], githubMatch[4], function (err, content) {
if (err) {
cb(null, 'Unable to import "' + m + '": ' + err);
return;
}
}).fail(function () {
cb(null, 'Unable to import "' + m + '"');
cachedRemoteFiles[m] = content;
files[m] = content;
gatherImports(files, importHints, cb);
});
return;
} else if (/^[^:]*:\/\//.exec(m)) {
cb(null, 'Unable to import "' + m + '": Unsupported URL');
return;
} else {
cb(null, 'Unable to import "' + m + '"');
cb(null, 'Unable to import "' + m + '": File not found');
return;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment