var PuddingLoader = require("ether-pudding/loader");

module.exports = function(contents, file, config, process, callback) {
  PuddingLoader.packageSource(config.environments.current.directory, function(err, result) {
    if (err != null) {
      callback(err);
    } else {

      var contract_names = Object.keys(config.contracts.classes).join(", ");

      contents = `
${result};

${contents};

// Added by Truffle bootstrap.
window.web3 = new Web3();
window.web3.setProvider(new Web3.providers.HttpProvider("http://${config.app.resolved.rpc.host}:${config.app.resolved.rpc.port}"));
Pudding.setWeb3(window.web3);
Pudding.load([${contract_names}], window);
`;

      callback(null, contents);
    }
  });
};

@@ -427,57 +427,255 @@
 ap.%0A
-window.web3 = new Web3();%0Awindow.web3.setProvider
+// Supports Mist, and other wallets that provide 'web3'.%0Aif (typeof web3 !== 'undefined') %7B%0A  // Use the Mist/wallet provider.%0A  window.web3 = new Web3(web3.currentProvider);%0A%7D else %7B%0A  // Use the provider from the config.%0A  window.web3 = new Web3
 (new
@@ -779,16 +779,19 @@
 rt%7D%22));%0A
+%7D%0A%0A
 Pudding.

Add Mist bootstrapping to all projects that use Truffle's build process.