Пример #1
0
export default function appendTemplatedView(parentView, morph, viewClassOrInstance, props) {
  var viewProto;
  if (View.detectInstance(viewClassOrInstance)) {
    viewProto = viewClassOrInstance;
  } else {
    viewProto = viewClassOrInstance.proto();
  }

  Ember.assert(
    "You cannot provide a template block if you also specified a templateName",
    !props.template || (!get(props, 'templateName') && !get(viewProto, 'templateName'))
  );

  // We only want to override the `_context` computed property if there is
  // no specified controller. See View#_context for more information.

  var noControllerInProto = !viewProto.controller;
  if (viewProto.controller.isDescriptor) { noControllerInProto = true; }
  if (noControllerInProto &&
      !viewProto.controllerBinding &&
      !props.controller &&
      !props.controllerBinding) {
    props._context = get(parentView, 'context'); // TODO: is this right?!
  }

  props._morph = morph;

  return parentView.appendChild(viewClassOrInstance, props);
}
Пример #2
0
  instanceHelper: function(newView, hash, options, env) {
    var data = env.data;
    var template = options.template;

    makeBindings(hash, options, env.data.view);

    Ember.assert(
      'Only a instance of a view may be passed to the ViewHelper.instanceHelper',
      View.detectInstance(newView)
    );

    var viewOptions = this.propertiesFromHTMLOptions(hash, options, env);
    var currentView = data.view;

    if (template) {
      Ember.assert(
        "You cannot provide a template block if you also specified a templateName",
        !get(viewOptions, 'templateName') && !get(newView, 'templateName')
      );
      viewOptions.template = template;
    }

    // We only want to override the `_context` computed property if there is
    // no specified controller. See View#_context for more information.
    if (!newView.controller && !newView.controllerBinding &&
        !viewOptions.controller && !viewOptions.controllerBinding) {
      viewOptions._context = get(currentView, 'context'); // TODO: is this right?!
    }

    viewOptions._morph = options.morph;

    currentView.appendChild(newView, viewOptions);
  }
Пример #3
0
  instanceHelper: function(thisContext, newView, options) {
    var data = options.data;
    var fn   = options.fn;

    makeBindings(thisContext, options);

    Ember.assert(
      'Only a instance of a view may be passed to the ViewHelper.instanceHelper',
      View.detectInstance(newView)
    );

    var viewOptions = this.propertiesFromHTMLOptions(options, thisContext);
    var currentView = data.view;
    viewOptions.templateData = data;

    if (fn) {
      Ember.assert("You cannot provide a template block if you also specified a templateName",
                   !get(viewOptions, 'templateName') && !get(newView, 'templateName'));
      viewOptions.template = fn;
    }

    // We only want to override the `_context` computed property if there is
    // no specified controller. See View#_context for more information.
    if (!newView.controller && !newView.controllerBinding &&
        !viewOptions.controller && !viewOptions.controllerBinding) {
      viewOptions._context = thisContext;
    }

    currentView.appendChild(newView, viewOptions);
  }
Пример #4
0
export function readViewFactory(object, container) {
  var value = read(object);
  var viewClass;

  if (typeof value === 'string') {
    if (isGlobal(value)) {
      viewClass = get(null, value);
      Ember.deprecate('Resolved the view "'+value+'" on the global context. Pass a view name to be looked up on the container instead, such as {{view "select"}}. http://emberjs.com/guides/deprecations#toc_global-lookup-of-views', !viewClass);
    } else {
      Ember.assert("View requires a container to resolve views not passed in through the context", !!container);
      viewClass = container.lookupFactory('view:'+value);
    }
  } else {
    viewClass = value;
  }

  Ember.assert(fmt(value+" must be a subclass or an instance of Ember.View, not %@", [viewClass]), View.detect(viewClass) || View.detectInstance(viewClass));

  return viewClass;
}
Пример #5
0
  helper: function(thisContext, path, options) {
    var data = options.data,
        fn = options.fn,
        newView;

    makeBindings(thisContext, options);

    if ('string' === typeof path) {
      var lookup;
      // TODO: this is a lame conditional, this should likely change
      // but something along these lines will likely need to be added
      // as deprecation warnings
      //
      if (options.types[0] === 'STRING' && LOWERCASE_A_Z.test(path) && !VIEW_PREFIX.test(path)) {
        lookup = path;
      } else {
        newView = handlebarsGet(thisContext, path, options);
        if (typeof newView === 'string') {
          lookup = newView;
        }
      }

      if (lookup) {
        Ember.assert("View requires a container", !!data.view.container);
        newView = data.view.container.lookupFactory('view:' + lookup);
      }

      Ember.assert("Unable to find view at path '" + path + "'", !!newView);
    } else {
      newView = path;
    }

    Ember.assert(EmberString.fmt('You must pass a view to the #view helper, not %@ (%@)', [path, newView]), View.detect(newView) || View.detectInstance(newView));

    var viewOptions = this.propertiesFromHTMLOptions(options, thisContext);
    var currentView = data.view;
    viewOptions.templateData = data;
    var newViewProto = newView.proto ? newView.proto() : newView;

    if (fn) {
      Ember.assert("You cannot provide a template block if you also specified a templateName", !get(viewOptions, 'templateName') && !get(newViewProto, 'templateName'));
      viewOptions.template = fn;
    }

    // We only want to override the `_context` computed property if there is
    // no specified controller. See View#_context for more information.
    if (!newViewProto.controller && !newViewProto.controllerBinding && !viewOptions.controller && !viewOptions.controllerBinding) {
      viewOptions._context = thisContext;
    }

    // for instrumentation
    if (options.helperName) {
      viewOptions.helperName = options.helperName;
    }

    currentView.appendChild(newView, viewOptions);
  }