Guest User

Untitled

a guest
Aug 16th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. (function() {
  2.  
  3. // Essentially function(name = "SC.View", options = {data: {}, hash: {}})
  4. var parseHelperArguments = function(viewClassNameOrOptions, options) {
  5. var viewClass;
  6. if (_.isString(viewClassNameOrOptions)) {
  7. viewClass = SC.getPath(viewClassNameOrOptions);
  8. sc_assert( "Could not find view class %@".fmt(viewClassNameOrOptions), viewClass != null );
  9. options = options || {};
  10. } else {
  11. viewClass = SC.View;
  12. options = viewClassNameOrOptions || {};
  13. }
  14.  
  15. options.data = options.data || {};
  16. options.hash = options.hash || {};
  17. return [viewClass, options];
  18. };
  19.  
  20. var addChildView = function() {
  21. var parsedArguments = parseHelperArguments.apply(this, arguments),
  22. viewClass = parsedArguments[0],
  23. options = parsedArguments[1],
  24. parentView = options.data.view,
  25. childViewClass,
  26. childView;
  27.  
  28. sc_assert( "childView can only be used inside of a TemplateContainerView", TemplateContainerView.detect(parentView) );
  29.  
  30. childViewClass = SC.Handlebars.ViewHelper.viewClassFromHTMLOptions(viewClass, options.hash, this);
  31. childView = parentView.createChildView(childViewClass, {
  32. template: options.fn
  33. });
  34.  
  35. parentView.get('childViews').pushObject(childView);
  36. };
  37.  
  38. Handlebars.registerHelper('childView', addChildView);
  39.  
  40. }());
Add Comment
Please, Sign In to add comment