<script>
  window.assetPath = (function(){

    // TODO: automate this to grab from the manifest, Rails voodoo should be able to get it
    var map = {
      'defer/html-sanitizer-bundle': <%= asset_path('defer/html-sanitizer-bundle.js').inspect.html_safe %>,
      'defer/google_diff_match_patch': <%= asset_path('defer/google_diff_match_patch.js').inspect.html_safe %>
    };

    return function(asset){ return map[asset]; };
  })();
</script>

<script>
  Ember.RSVP.configure('onerror', function(e) {
    <% if Rails.env.development? %>
      if (e) {
        if (e.message || e.stack) {
          console.log(e.message);
          console.log(e.stack);
        } else {
          console.log("Uncaught promise: ", e);
        }
      } else {
        console.log("A promise failed but was not caught.");
      }
    <% end %>
    window.onerror(e && e.message, null,null,null,e);
  });
</script>

<script>
  Discourse.CDN = '<%= Rails.configuration.action_controller.asset_host %>';
  Discourse.BaseUrl = '<%= RailsMultisite::ConnectionManagement.current_hostname %>';
  Discourse.BaseUri = '<%= Discourse::base_uri "/" %>';
  Discourse.Environment = '<%= Rails.env %>';
  Discourse.SiteSettings = PreloadStore.get('siteSettings');
  Discourse.LetterAvatarVersion = <%= LetterAvatar::VERSION %>;
  Discourse.Router = Ember.Router.extend({ location: 'discourse-location' });
  Discourse.Route.mapRoutes();
  Discourse.start();
  Discourse.set('assetVersion','<%= Discourse.assets_digest %>');
</script>

<%= javascript_include_tag 'browser-update.js' %>
