Sha256: 364b6e9e7ad150073df5e04e8f85d4bff342b0db3a2a315daf82510cfb62f710

Contents?: true

Size: 1.52 KB

Versions: 8

Compression:

Stored size: 1.52 KB

Contents

/*globals Handlebars */

sc_require('ext/handlebars');

Handlebars.registerHelper('collection', function(path, options) {
  var fn = options.fn;
  var data = options.data;
  var inverse = options.inverse;
  var hash = options.hash;
  var collectionClass, collectionObject;

  collectionClass = path ? SC.getPath(this, path) || SC.getPath(path) :
    SC.TemplateCollectionView;

  // @if (debug)
  if (!collectionClass) {
    throw "%@ #collection: Could not find %@".fmt(data.view, path);
  }
  // @endif

  var extensions = {};

  if (hash) {
    var itemHash = {}, match;

    for (var prop in hash) {
      if (hash.hasOwnProperty(prop)) {
        match = prop.match(/^item(.)(.*)$/);

        if(match) {
          itemHash[match[1].toLowerCase() + match[2]] = hash[prop];
          delete hash[prop];
        }
      }
    }

    extensions = SC.clone(hash);
    extensions.itemViewOptions = itemHash;
  }

  if (fn) { extensions.itemViewTemplate = fn; }
  if (inverse) { extensions.inverseTemplate = inverse; }

  if(collectionClass.isClass) {
    collectionObject = collectionClass.extend(extensions);
  } else {
    collectionObject = SC.mixin(collectionClass, extensions);
  }

  options.fn = function() { return ""; };

  return Handlebars.helpers.view.call(this, collectionObject, options);
});

Handlebars.registerHelper('each', function(path, options) {
  options.hash.contentBinding = SC.Binding.from('*'+path, this).oneWay();
  options.hash.itemContextProperty = 'content';
  return Handlebars.helpers.collection.call(this, null, options);
});

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sproutcore-1.6.0.1-java lib/frameworks/sproutcore/frameworks/core_foundation/ext/handlebars/collection.js
sproutcore-1.6.0.1 lib/frameworks/sproutcore/frameworks/core_foundation/ext/handlebars/collection.js
sproutcore-1.6.0.1-x86-mingw32 lib/frameworks/sproutcore/frameworks/core_foundation/ext/handlebars/collection.js
sproutcore-1.6.0 lib/frameworks/sproutcore/frameworks/core_foundation/ext/handlebars/collection.js
sproutcore-1.6.0-java lib/frameworks/sproutcore/frameworks/core_foundation/ext/handlebars/collection.js
sproutcore-1.6.0.rc.2-x86-mingw32 lib/frameworks/sproutcore/frameworks/core_foundation/ext/handlebars/collection.js
sproutcore-1.6.0.rc.2 lib/frameworks/sproutcore/frameworks/core_foundation/ext/handlebars/collection.js
sproutcore-1.6.0.rc.2-java lib/frameworks/sproutcore/frameworks/core_foundation/ext/handlebars/collection.js