resolver.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import Ember from 'ember';
  2. import Resolver from 'ember/resolver';
  3. export default Resolver.extend({
  4. _startsWith: function(string, beginning) {
  5. return string.indexOf(beginning) === 0;
  6. },
  7. _endsWith: function(string, tail) {
  8. return string.indexOf(tail, string.length - tail.length) !== -1;
  9. },
  10. misagoFormModuleName: function(parsedName) {
  11. if (this._endsWith(parsedName.name, '-form')) {
  12. var isComponent = parsedName.type === 'component';
  13. var isComponentTemplate = this._startsWith(parsedName.name, 'components/');
  14. if (isComponent || isComponentTemplate) {
  15. var path = parsedName.prefix + '/' + this.pluralize(parsedName.type) + '/';
  16. if (isComponentTemplate) {
  17. path += 'components/forms/' + parsedName.fullNameWithoutType.substr(11);
  18. } else {
  19. path += 'forms/' + parsedName.fullNameWithoutType;
  20. }
  21. return path;
  22. }
  23. }
  24. },
  25. misagoModalModuleName: function(parsedName) {
  26. if (this._endsWith(parsedName.name, '-modal')) {
  27. var isComponent = parsedName.type === 'component';
  28. var isComponentTemplate = this._startsWith(parsedName.name, 'components/');
  29. if (isComponent || isComponentTemplate) {
  30. var path = parsedName.prefix + '/' + this.pluralize(parsedName.type) + '/';
  31. if (isComponentTemplate) {
  32. path += 'components/modals/' + parsedName.fullNameWithoutType.substr(11);
  33. } else {
  34. path += 'modals/' + parsedName.fullNameWithoutType;
  35. }
  36. return path;
  37. }
  38. }
  39. },
  40. // register custom lookup
  41. moduleNameLookupPatterns: Ember.computed(function(){
  42. return Ember.A([
  43. this.misagoFormModuleName,
  44. this.misagoModalModuleName,
  45. this.podBasedModuleName,
  46. this.podBasedComponentsInSubdir,
  47. this.mainModuleName,
  48. this.defaultModuleName
  49. ]);
  50. })
  51. });