Sha256: 4494efeebaea1bd8bfe38adc422cafb102b6645a09b577627b670e049113f813

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

import { assert } from '@ember/debug';
import EmberError from '@ember/error';

function parseUnderscoredName(templateName) {
  let nameParts = templateName.split('/');
  let lastPart = nameParts[nameParts.length - 1];

  nameParts[nameParts.length - 1] = `_${lastPart}`;

  return nameParts.join('/');
}

export default function lookupPartial(templateName, owner) {
  if (templateName == null) {
    return;
  }

  let template = templateFor(owner, parseUnderscoredName(templateName), templateName);

  assert(`Unable to find partial with name "${templateName}"`, !!template);

  return template;
}

export function hasPartial(name, owner) {
  if (!owner) {
    throw new EmberError(
      'Container was not found when looking up a views template. ' +
        'This is most likely due to manually instantiating an Ember.View. ' +
        'See: http://git.io/EKPpnA'
    );
  }

  return (
    owner.hasRegistration(`template:${parseUnderscoredName(name)}`) ||
    owner.hasRegistration(`template:${name}`)
  );
}

function templateFor(owner, underscored, name) {
  if (!name) {
    return;
  }
  assert(`templateNames are not allowed to contain periods: ${name}`, name.indexOf('.') === -1);

  if (!owner) {
    throw new EmberError(
      'Container was not found when looking up a views template. ' +
        'This is most likely due to manually instantiating an Ember.View. ' +
        'See: http://git.io/EKPpnA'
    );
  }

  return owner.lookup(`template:${underscored}`) || owner.lookup(`template:${name}`);
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
discourse-ember-source-3.6.0.0 dist/es/@ember/-internals/views/lib/system/lookup_partial.js
discourse-ember-source-3.5.1.1 dist/es/ember-views/lib/system/lookup_partial.js
discourse-ember-source-3.5.1.0 dist/dist/es/ember-views/lib/system/lookup_partial.js