// Generated by CoffeeScript 1.3.3 /* knockback-inspector.js 0.1.4 (c) 2012 Kevin Malakoff. Knockback-Inspector.js is freely distributable under the MIT license. See the following for full license details: https://github.com/kmalakoff/knockback-inspector/blob/master/LICENSE Dependencies: Knockout.js, Underscore.js, Backbone.js, and Knockback.js. */ (function() { var Backbone, kb, kbi, ko, _, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; if (typeof require !== 'undefined') { try { _ = require('lodash'); } catch (e) { _ = require('underscore'); } } else { _ = this._; } if (_ && (_.hasOwnProperty('_'))) { _ = _._; } Backbone = !window.Backbone && (typeof require !== 'undefined') ? require('backbone') : window.Backbone; ko = !window.ko && (typeof require !== 'undefined') ? require('knockout') : window.ko; kb = !window.kb && (typeof require !== 'undefined') ? require('knockback') : window.kb; kbi = this.kbi = typeof exports !== 'undefined' ? exports : {}; this.kbi.VERSION = '0.1.4'; kbi.TemplateSource = (function() { function TemplateSource(template_generator, binding_context) { this.template_generator = template_generator; this.binding_context = binding_context != null ? binding_context : {}; } TemplateSource.prototype.data = function(key, value) { if (arguments.length === 1) { return this.binding_context[key]; } return this.binding_context[key] = value; }; TemplateSource.prototype.text = function() { if (arguments.length > 0) { throw 'kbi.TemplateSource: unexpected writing to template source'; } return this.template_generator.viewText(this.binding_context); }; return TemplateSource; })(); kbi.TemplateEngine = (function(_super) { __extends(TemplateEngine, _super); function TemplateEngine() { this.allowTemplateRewriting = false; this.generators = { kbi_model_node: kbi.ModelNodeViewGenerator, kbi_collection_node: kbi.CollectionNodeViewGenerator }; } TemplateEngine.prototype.generator = function(template_name, generator_class) { if (arguments.length === 1) { return this.generators[template_name]; } return this.generators[template_name] = generator_class; }; TemplateEngine.prototype.makeTemplateSource = function(template_name) { if (this.generators.hasOwnProperty(template_name)) { return new kbi.TemplateSource(new this.generators[template_name](template_name)); } return TemplateEngine.__super__.makeTemplateSource.apply(this, arguments); }; TemplateEngine.prototype.renderTemplateSource = function(template_source, binding_context, options) { var key, value; for (key in binding_context) { value = binding_context[key]; template_source.data(key, value); } return TemplateEngine.__super__.renderTemplateSource.apply(this, arguments); }; return TemplateEngine; })(ko.nativeTemplateEngine); kbi.FetchedModel = (function(_super) { __extends(FetchedModel, _super); function FetchedModel() { return FetchedModel.__super__.constructor.apply(this, arguments); } FetchedModel.prototype.parse = function(response) { var attributes, collection, key, model, value; attributes = {}; for (key in response) { value = response[key]; if (_.isObject(value)) { model = new kbi.FetchedModel(); attributes[key] = model.set(model.parse(value)); } else if (_.isArray(value)) { collection = new kbi.FetchedCollection(); attributes[key] = collection.reset(collection.parse(value)); } else { attributes[key] = value; } } return attributes; }; return FetchedModel; })(Backbone.Model); kbi.FetchedCollection = (function(_super) { __extends(FetchedCollection, _super); function FetchedCollection() { return FetchedCollection.__super__.constructor.apply(this, arguments); } FetchedCollection.prototype.model = kbi.FetchedModel; FetchedCollection.prototype.parse = function(response) { var models; models = response.results ? response.results : response; return _.map(response.results, function(result) { var model; model = new kbi.FetchedModel(); return model.set(model.parse(result)); }); }; return FetchedCollection; })(Backbone.Collection); kbi.NodeViewModel = (function() { function NodeViewModel(name, opened, node) { var model; this.name = name; this.node = node; this.opened = ko.observable(opened); if (ko.utils.unwrapObservable(this.node) instanceof kb.ViewModel) { this.node = ko.utils.unwrapObservable(this.node); model = kb.utils.wrappedModel(this.node); this.attribute_names = ko.observableArray(model ? _.keys(model.attributes) : []); } this; } return NodeViewModel; })(); kbi.nodeViewModel = kbi.nvm = function(name, opened, node) { return new kbi.NodeViewModel(name, opened, node); }; kbi.CollectionNodeViewGenerator = (function() { function CollectionNodeViewGenerator(template_name) { this.template_name = template_name; } CollectionNodeViewGenerator.prototype.viewText = function(binding_context) { return "" + (this.nodeStart(binding_context)) + "\n" + (this.nodeManipulator(binding_context)) + "\n \n \n " + (this.modelNode(binding_context)) + "\n \n \n" + (this.nodeEnd(binding_context)); }; CollectionNodeViewGenerator.prototype.nodeStart = function(binding_context) { return "
  • "; }; CollectionNodeViewGenerator.prototype.nodeManipulator = function(binding_context) { return "
    \n \n \n
    "; }; CollectionNodeViewGenerator.prototype.modelNode = function(binding_context) { return "" + (kbi.ViewHTML.modelTree("'['+$index()+']'", false, "$data")); }; CollectionNodeViewGenerator.prototype.nodeEnd = function(binding_context) { return "
  • "; }; return CollectionNodeViewGenerator; })(); kbi.ModelNodeViewGenerator = (function() { function ModelNodeViewGenerator(template_name) { this.template_name = template_name; } ModelNodeViewGenerator.prototype.viewText = function(binding_context) { return "" + (this.nodeStart(binding_context)) + "\n" + (this.nodeManipulator(binding_context)) + "\n \n \n \n " + (this.attributeEditor(binding_context)) + "\n \n\n \n " + (this.modelTree(binding_context)) + "\n \n\n \n " + (this.collectionTree(binding_context)) + "\n \n\n \n \n" + (this.nodeEnd(binding_context)); }; ModelNodeViewGenerator.prototype.nodeStart = function(binding_context) { return "
  • "; }; ModelNodeViewGenerator.prototype.nodeManipulator = function(binding_context) { return "
    \n \n \n
    "; }; ModelNodeViewGenerator.prototype.attributeEditor = function(binding_context) { return "
    \n \n \n
    "; }; ModelNodeViewGenerator.prototype.modelTree = function(binding_context) { return "" + (kbi.ViewHTML.modelTree('$data', false, "$parent.node[$data]")); }; ModelNodeViewGenerator.prototype.collectionTree = function(binding_context) { return "" + (kbi.ViewHTML.collectionTree("$data+'[]'", true, "$parent.node[$data]")); }; ModelNodeViewGenerator.prototype.nodeEnd = function(binding_context) { return "
  • "; }; return ModelNodeViewGenerator; })(); kbi.ViewHTML = (function() { function ViewHTML() {} ViewHTML.modelTree = function(name, opened, node) { return ""; }; ViewHTML.collectionTree = function(name, opened, node) { return ""; }; return ViewHTML; })(); }).call(this);