<commit_before>import {bootstrap} from 'angular2/angular2';
import {AppViewManager} from 'angular2/src/core/compiler/view_manager';
import {Compiler} from 'angular2/angular2';
import {ElementRef} from 'angular2/src/core/compiler/element_ref';
import {bind} from 'angular2/di';
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';

import {IonicConfig} from '../../config/config';
import {Platform} from '../../platform/platform';
import {Registry} from '../../registry';
import * as util from '../../util/util';


export class IonicApp {

  constructor() {
    this.overlays = [];

    // Our component registry map
    this.components = {};
  }

  /**
   * Register a known component with a key, for easy lookups later.
   */
  register(key, component) {
    this.components[key] = component;
    console.log('App: Registered component', key, component);
    // TODO(mlynch): We need to track the lifecycle of this component to remove it onDehydrate
  }

  /**
   * Get the component for the given key.
   */
  getComponent(key) {
    return this.components[key];
  }

  config(val) {
    if (arguments.length) {
      this._config = val;
    }
    return this._config;
  }

  url(val) {
    if (arguments.length) {
      this._url = val;
      this._qs = util.getQuerystring(val);
    }
    return this._url;
  }

  query(key) {
    return (this._qs || {})[key];
  }

  userAgent(val) {
    if (arguments.length) {
      this._ua = val;
    }
    return this._ua;
  }

  matchQuery(queryValue) {
    let val = this.query('ionicplatform');
    if (val) {
      let valueSplit = val.toLowerCase().split(';');
      for (let i = 0; i < valueSplit.length; i++) {
        if (valueSplit[i] == queryValue) {
          return true;
        }
      }
    }
    return false;
  }

  matchUserAgent(userAgentExpression) {
    if (this._ua) {
      let rx = new RegExp(userAgentExpression, 'i');
      return rx.exec(this._ua);
    }
  }

  isPlatform(queryValue, userAgentExpression) {
    if (!userAgentExpression) {
      userAgentExpression = queryValue;
    }
    return (this.matchQuery(queryValue)) ||
           (this.matchUserAgent(userAgentExpression) !== null);
  }

  width(val) {
    if (arguments.length) {
      this._w = val;
    }
    return this._w || 0;
  }

  height(val) {
    if (arguments.length) {
      this._h = val;
    }
    return this._h || 0;
  }

  /**
   * Create and append the given component into the root
   * element of the app.
   *
   * @param Component the ComponentType to create and insert
   * @return Promise that resolves with the ContainerRef created
   */
  appendComponent(ComponentType: Type) {
    return new Promise((resolve, reject) => {
      let injector = this._ref.injector;
      let compiler = injector.get(Compiler);
      let viewMngr = injector.get(AppViewManager);
      let rootComponentRef = this._ref._hostComponent;
      let viewContainerLocation = rootComponentRef.location;

      compiler.compileInHost(ComponentType).then(protoViewRef => {

        let atIndex = 0;
        let context = null;

        let hostViewRef = viewMngr.createViewInContainer(
                                      viewContainerLocation,
                                      atIndex,
                                      protoViewRef,
                                      context,
                                      injector);

        hostViewRef.elementRef = new ElementRef(hostViewRef, 0);
        hostViewRef.instance = viewMngr.getComponent(hostViewRef.elementRef);

        hostViewRef.dispose = () => {
          viewMngr.destroyViewInContainer(viewContainerLocation, 0, 0, hostViewRef.viewRef);
        };

        resolve(hostViewRef);

      }).catch(err => {
        console.error('IonicApp appendComponent:', err);
        reject(err);
      });
    });
  }

  ref(val) {
    if (arguments.length) {
      this._ref = val;
    }
    return this._ref;
  }

}

export function ionicBootstrap(ComponentType, config) {
  return new Promise((resolve, reject) => {
    try {
      let app = new IonicApp();
      app.url(window.location.href);
      app.userAgent(window.navigator.userAgent);
      app.width(window.innerWidth);
      app.height(window.innerHeight);

      let platform = Platform.load(app);

      config = config || new IonicConfig();

      // copy default platform settings into the user config platform settings
      // user config platform settings should override default platform settings
      config.setPlatform(platform);


      GlobalIonicConfig = config;

      let injectableBindings = [
        bind(IonicApp).toValue(app),
        bind(IonicConfig).toValue(config)
      ];

      bootstrap(ComponentType, injectableBindings).then(appRef => {
        app.ref(appRef);

        platform.run();

        resolve({
          app,
          config,
          platform
        });
<commit_msg>add platform css to body<commit_after>import {bootstrap} from 'angular2/angular2';
import {AppViewManager} from 'angular2/src/core/compiler/view_manager';
import {Compiler} from 'angular2/angular2';
import {ElementRef} from 'angular2/src/core/compiler/element_ref';
import {bind} from 'angular2/di';
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';

import {IonicConfig} from '../../config/config';
import {Platform} from '../../platform/platform';
import {Registry} from '../../registry';
import * as util from '../../util/util';


export class IonicApp {

  constructor() {
    this.overlays = [];

    // Our component registry map
    this.components = {};
  }

  /**
   * Register a known component with a key, for easy lookups later.
   */
  register(key, component) {
    this.components[key] = component;
    console.log('App: Registered component', key, component);
    // TODO(mlynch): We need to track the lifecycle of this component to remove it onDehydrate
  }

  /**
   * Get the component for the given key.
   */
  getComponent(key) {
    return this.components[key];
  }

  config(val) {
    if (arguments.length) {
      this._config = val;
    }
    return this._config;
  }

  url(val) {
    if (arguments.length) {
      this._url = val;
      this._qs = util.getQuerystring(val);
    }
    return this._url;
  }

  query(key) {
    return (this._qs || {})[key];
  }

  userAgent(val) {
    if (arguments.length) {
      this._ua = val;
    }
    return this._ua;
  }

  matchQuery(queryValue) {
    let val = this.query('ionicplatform');
    if (val) {
      let valueSplit = val.toLowerCase().split(';');
      for (let i = 0; i < valueSplit.length; i++) {
        if (valueSplit[i] == queryValue) {
          return true;
        }
      }
    }
    return false;
  }

  matchUserAgent(userAgentExpression) {
    if (this._ua) {
      let rx = new RegExp(userAgentExpression, 'i');
      return rx.exec(this._ua);
    }
  }

  isPlatform(queryValue, userAgentExpression) {
    if (!userAgentExpression) {
      userAgentExpression = queryValue;
    }
    return (this.matchQuery(queryValue)) ||
           (this.matchUserAgent(userAgentExpression) !== null);
  }

  width(val) {
    if (arguments.length) {
      this._w = val;
    }
    return this._w || 0;
  }

  height(val) {
    if (arguments.length) {
      this._h = val;
    }
    return this._h || 0;
  }

  /**
   * Create and append the given component into the root
   * element of the app.
   *
   * @param Component the ComponentType to create and insert
   * @return Promise that resolves with the ContainerRef created
   */
  appendComponent(ComponentType: Type) {
    return new Promise((resolve, reject) => {
      let injector = this._ref.injector;
      let compiler = injector.get(Compiler);
      let viewMngr = injector.get(AppViewManager);
      let rootComponentRef = this._ref._hostComponent;
      let viewContainerLocation = rootComponentRef.location;

      compiler.compileInHost(ComponentType).then(protoViewRef => {

        let atIndex = 0;
        let context = null;

        let hostViewRef = viewMngr.createViewInContainer(
                                      viewContainerLocation,
                                      atIndex,
                                      protoViewRef,
                                      context,
                                      injector);

        hostViewRef.elementRef = new ElementRef(hostViewRef, 0);
        hostViewRef.instance = viewMngr.getComponent(hostViewRef.elementRef);

        hostViewRef.dispose = () => {
          viewMngr.destroyViewInContainer(viewContainerLocation, 0, 0, hostViewRef.viewRef);
        };

        resolve(hostViewRef);

      }).catch(err => {
        console.error('IonicApp appendComponent:', err);
        reject(err);
      });
    });
  }

  ref(val) {
    if (arguments.length) {
      this._ref = val;
    }
    return this._ref;
  }

  applyCss(platform, config) {
    let className = document.body.className;
    platform.platforms().forEach(platformName => {
      className += ' platform-' + platformName;
    });
    className += ' mode-' + config.setting('mode');
    document.body.className = className.trim();
  }

}

export function ionicBootstrap(ComponentType, config) {
  return new Promise((resolve, reject) => {
    try {
      let app = new IonicApp();
      app.url(window.location.href);
      app.userAgent(window.navigator.userAgent);
      app.width(window.innerWidth);
      app.height(window.innerHeight);

      let platform = Platform.load(app);

      config = config || new IonicConfig();

      // copy default platform settings into the user config platform settings
      // user config platform settings should override default platform settings
      config.setPlatform(platform);

      app.applyCss(platform, config)

      GlobalIonicConfig = config;

      let injectableBindings = [
        bind(IonicApp).toValue(app),
        bind(IonicConfig).toValue(config)
      ];

      bootstrap(ComponentType, injectableBindings).then(appRef => {
        app.ref(appRef);

        platform.run();

        resolve({
          app,
          config,
          platform
        });

{'fraction_non_alphanumeric': 0.12014203985006905, 'fraction_numerical': 0.002959163543105149, 'mean_word_length': 2.3395915678524375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6785820', 'n_tokens_mistral': 3010, 'n_tokens_neox': 2912, 'n_words': 676}