(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o | <%= level %> | <%= message %>"; this.level = this._parseLevel(options); this._format = _.template(this.formatText); } Logger.prototype.log = function(level, message) { var entry, line, lines, _i, _j, _len, _len1, _results, _results1; if (!(level.value >= this.level.value)) { return; } if (_.isFunction(message)) { message = message(); } entry = { timestamp: new Date(), level: level, message: message }; if (entry.level == null) { entry.level = this.level; } lines = this._formatEntry(entry); if (entry.level.value < Logger.WARNING.value) { _results = []; for (_i = 0, _len = lines.length; _i < _len; _i++) { line = lines[_i]; _results.push(console.log(line)); } return _results; } else { _results1 = []; for (_j = 0, _len1 = lines.length; _j < _len1; _j++) { line = lines[_j]; _results1.push(console.error(line)); } return _results1; } }; Logger.prototype.trace = function(message) { return this.log(Logger.TRACE, message); }; Logger.prototype.debug = function(message) { return this.log(Logger.DEBUG, message); }; Logger.prototype.verbose = function(message) { return this.log(Logger.VERBOSE, message); }; Logger.prototype.info = function(message) { return this.log(Logger.INFO, message); }; Logger.prototype.warning = function(message) { return this.log(Logger.WARNING, message); }; Logger.prototype.error = function(message) { if (message.stack != null) { message = "" + message.stack; } return this.log(Logger.ERROR, message); }; Logger.prototype.fatal = function(message) { return this.log(Logger.FATAL, message); }; Logger.prototype._formatEntry = function(entry, lines) { var line, message, result, _i, _len, _ref; if (lines == null) { lines = []; } message = entry.message.replace(/\\n/g, '\n'); _ref = message.split('\n'); for (_i = 0, _len = _ref.length; _i < _len; _i++) { line = _ref[_i]; result = []; result.push(this._format({ timestamp: "" + entry.timestamp, level: entry.level.name, message: line })); lines.push(result.join('')); } return lines; }; Logger.prototype._parseLevel = function(options) { var candidates, l, level; if (!_(options).has('level')) { return Logger.FATAL; } level = options.level; if (level == null) { candidates = []; } else if (_.isString(level)) { candidates = (function() { var _i, _len, _results; _results = []; for (_i = 0, _len = ALL_LEVELS.length; _i < _len; _i++) { l = ALL_LEVELS[_i]; if (l.name.trim().toLowerCase() === level.trim().toLowerCase()) { _results.push(l); } } return _results; })(); } else if (_.isNumber(level)) { candidates = (function() { var _i, _len, _results; _results = []; for (_i = 0, _len = ALL_LEVELS.length; _i < _len; _i++) { l = ALL_LEVELS[_i]; if (l.value === level) { _results.push(l); } } return _results; })(); } else if (level != null) { candidates = (function() { var _i, _len, _results; _results = []; for (_i = 0, _len = ALL_LEVELS.length; _i < _len; _i++) { l = ALL_LEVELS[_i]; if (l === level) { _results.push(l); } } return _results; })(); } if (!(candidates.length > 0)) { throw new Error("invalid level: " + level); } return candidates[0]; }; return Logger; })(); },{}],8:[function(require,module,exports){ (function (global){ /* * Crafting Guide - main.coffee * * Copyright (c) 2014 by Redwood Labs * All rights reserved. */ var CraftingGuideRouter, Logger, views; views = require('./views'); Logger = require('./logger'); CraftingGuideRouter = require('./crafting_guide_router'); if (typeof global === 'undefined') { window.global = window; } global.views = views; global.logger = new Logger({ level: Logger.TRACE }); global.router = new CraftingGuideRouter; logger.info("CraftingGuide is ready"); Backbone.history.start({ pushState: true }); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./crafting_guide_router":6,"./logger":7,"./views":17}],9:[function(require,module,exports){ /* * crafting_guide - base_model.coffee * * Copyright (c) 2014 by Redwood Labs * All rights reserved. */ var BaseModel, __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; }; module.exports = BaseModel = (function(_super) { __extends(BaseModel, _super); function BaseModel(attributes, options) { var makeGetter, makeSetter, name, _i, _len, _ref; if (attributes == null) { attributes = {}; } if (options == null) { options = {}; } BaseModel.__super__.constructor.call(this, attributes, options); makeGetter = function(name) { return function() { return this.get(name); }; }; makeSetter = function(name) { return function(value) { return this.set(name, value); }; }; _ref = _.keys(attributes); for (_i = 0, _len = _ref.length; _i < _len; _i++) { name = _ref[_i]; if (name === 'id') { continue; } Object.defineProperty(this, name, { get: makeGetter(name), set: makeSetter(name) }); } } BaseModel.prototype.sync = function() {}; BaseModel.prototype.toString = function() { return "" + this.constructor.name + " (" + this.cid + ")"; }; return BaseModel; })(Backbone.Model); },{}],10:[function(require,module,exports){ /* * Crafting Guide - item.coffee * * Copyright (c) 2014 by Redwood Labs * All rights reserved. */ var BaseModel, Item, __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; }; BaseModel = require('./base_model'); module.exports = Item = (function(_super) { __extends(Item, _super); function Item(attributes, options) { if (attributes == null) { attributes = {}; } if (options == null) { options = {}; } if (attributes.name == null) { attributes.name = ''; } if (attributes.quantity == null) { attributes.quantity = 1; } Item.__super__.constructor.call(this, attributes, options); } return Item; })(BaseModel); },{"./base_model":9}],11:[function(require,module,exports){ /* * Crafting Guide - landing_page.coffee * * Copyright (c) 2014 by Redwood Labs * All rights reserved. */ var BaseModel, LandingPage, RecipeCatalog, __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; }; BaseModel = require('./base_model'); RecipeCatalog = require('./recipe_catalog'); module.exports = LandingPage = (function(_super) { __extends(LandingPage, _super); function LandingPage(attributes, options) { if (attributes == null) { attributes = {}; } if (options == null) { options = {}; } if (attributes.catalog == null) { attributes.catalog = new RecipeCatalog; } LandingPage.__super__.constructor.call(this, attributes, options); } return LandingPage; })(BaseModel); },{"./base_model":9,"./recipe_catalog":16}],12:[function(require,module,exports){ /* * Crafting Guide - v1.coffee * * Copyright (c) 2014 by Redwood Labs * All rights reserved. */ var Item, Recipe, RecipeBook, V1; Item = require('../item'); Recipe = require('../recipe'); RecipeBook = require('../recipe_book'); module.exports = V1 = (function() { function V1() { this._errorLocation = 'the header information'; } V1.prototype.parse = function(data) { return this._parseRecipeBook(data); }; V1.prototype._parseRecipeBook = function(data) { var book, index, recipeData, _i, _ref; if (data == null) { throw new Error('recipe book data is missing'); } if (data.version == null) { throw new Error('version is required'); } if (data.mod_name == null) { throw new Error('mod_name is required'); } if (data.mod_version == null) { throw new Error('mod_version is required'); } if (!_.isArray(data.recipes)) { throw new Error('recipes must be an array'); } book = new RecipeBook({ version: data.version, modName: data.mod_name, modVersion: data.mod_version }); book.description = data.description || ''; for (index = _i = 0, _ref = data.recipes.length; 0 <= _ref ? _i < _ref : _i > _ref; index = 0 <= _ref ? ++_i : --_i) { this._errorLocation = "recipe " + (index + 1); recipeData = data.recipes[index]; book.recipes.push(this._parseRecipe(recipeData)); } return book; }; V1.prototype._parseRecipe = function(data, options) { var input, output, tools; if (options == null) { options = {}; } if (data == null) { throw new Error("recipe data is missing for " + this._errorLocation); } if (data.output == null) { throw new Error("" + this._errorLocation + " is missing output"); } if (data.input == null) { throw new Error("" + this._errorLocation + " is missing input"); } output = this._parseItemList(data.output, { field: 'output', canBeEmpty: false }); this._errorLocation = "recipe for output[0].name"; if (data.tools == null) { data.tools = []; } input = this._parseItemList(data.input, { field: 'input', canBeEmpty: false }); tools = this._parseItemList(data.tools, { field: 'tools', canBeEmpty: true }); return new Recipe({ input: input, output: output, tools: tools }); }; V1.prototype._parseItemList = function(data, options) { var index, itemData, result, _i, _ref; if (options == null) { options = {}; } if (data == null) { throw new Error("" + this._errorLocation + " must have an " + options.field + " field"); } if (!_.isArray(data)) { data = [data]; } if (data.length === 0 && !options.canBeEmpty) { throw new Error("" + options.field + " for " + this._errorLocation + " cannot be empty"); } result = []; for (index = _i = 0, _ref = data.length; 0 <= _ref ? _i < _ref : _i > _ref; index = 0 <= _ref ? ++_i : --_i) { itemData = data[index]; result.push(this._parseItem(itemData, { field: options.field, index: index })); } return result; }; V1.prototype._parseItem = function(data, options) { var errorBase; if (options == null) { options = {}; } errorBase = "" + options.field + " element " + options.index + " for " + this._errorLocation; if (data == null) { throw new Error("" + errorBase + " is missing"); } if (_.isString(data)) { data = [1, data]; } if (!_.isArray(data)) { throw new Error("" + errorBase + " must be an array"); } if (data.length === 1) { data.unshift(1); } if (data.length !== 2) { throw new Error("" + errorBase + " must have at least one element"); } if (!_.isNumber(data[0])) { throw new Error("" + errorBase + " must start with a number"); } return new Item({ quantity: data[0], name: data[1] }); }; return V1; })(); },{"../item":10,"../recipe":13,"../recipe_book":14}],13:[function(require,module,exports){ /* * Crafting Guide - recipe.coffee * * Copyright (c) 2014 by Redwood Labs * All rights reserved. */ var BaseModel, Recipe, __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; }; BaseModel = require('./base_model'); module.exports = Recipe = (function(_super) { __extends(Recipe, _super); function Recipe(attributes, options) { if (attributes == null) { attributes = {}; } if (options == null) { options = {}; } Recipe.__super__.constructor.call(this, attributes, options); Object.defineProperty(this, 'name', { get: function() { return this.output[0].name; } }); } return Recipe; })(BaseModel); },{"./base_model":9}],14:[function(require,module,exports){ /* * Crafting Guide - recipe_book.coffee * * Copyright (c) 2014 by Redwood Labs * All rights reserved. */ var BaseModel, RecipeBook, __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; }; BaseModel = require('./base_model'); module.exports = RecipeBook = (function(_super) { __extends(RecipeBook, _super); function RecipeBook(attributes, options) { if (attributes == null) { attributes = {}; } if (options == null) { options = {}; } if (_.isEmpty(attributes.modName)) { throw new Error('modName cannot be empty'); } if (_.isEmpty(attributes.modVersion)) { throw new Error('modVersion cannot be empty'); } if (attributes.description == null) { attributes.description = ''; } if (attributes.recipes == null) { attributes.recipes = []; } RecipeBook.__super__.constructor.call(this, attributes, options); } RecipeBook.prototype.getRecipes = function(name) { var recipe, result, _i, _len, _ref; result = []; _ref = this.recipes; for (_i = 0, _len = _ref.length; _i < _len; _i++) { recipe = _ref[_i]; if (recipe.name === name) { result.push(recipe); } } return result; }; RecipeBook.prototype.toString = function() { return "RecipeBook (" + this.cid + ") { modName:" + this.modName + ", modVersion:" + this.modVersion + ", recipes:" + this.recipes.length + " items}"; }; return RecipeBook; })(BaseModel); },{"./base_model":9}],15:[function(require,module,exports){ /* * Crafting Guide - recipe_book_parser.coffee * * Copyright (c) 2014 by Redwood Labs * All rights reserved. */ var RecipeBookParser, V1; V1 = require('./parser_versions/v1'); module.exports = RecipeBookParser = (function() { function RecipeBookParser() { this._parsers = { '1': new V1 }; } RecipeBookParser.prototype.parse = function(data) { var parser; if (data == null) { throw new Error('recipe book data is missing'); } if (data.version == null) { throw new Error('version is required'); } parser = this._parsers["" + data.version]; if (parser == null) { throw new Error("cannot parse version " + data.version + " recipe books"); } return parser.parse(data); }; return RecipeBookParser; })(); },{"./parser_versions/v1":12}],16:[function(require,module,exports){ /* * Crafting Guide - recipe_catalog.coffee * * Copyright (c) 2014 by Redwood Labs * All rights reserved. */ var BaseModel, Event, RecipeBookParser, RecipeCatalog, __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; }; BaseModel = require('./base_model'); Event = require('../constants').Event; RecipeBookParser = require('./recipe_book_parser'); module.exports = RecipeCatalog = (function(_super) { __extends(RecipeCatalog, _super); function RecipeCatalog(attributes, options) { if (attributes == null) { attributes = {}; } if (options == null) { options = {}; } if (attributes.books == null) { attributes.books = []; } RecipeCatalog.__super__.constructor.call(this, attributes, options); this._parser = new RecipeBookParser; } RecipeCatalog.prototype.loadBook = function(url) { this.trigger(Event.book.load.started, this, url); return $.ajax({ url: url, dataType: 'json', success: (function(_this) { return function(data, status, xhr) { return _this.onBookLoaded(data, status, xhr); }; })(this), error: (function(_this) { return function(xhr, status, error) { return _this.onBookLoadFailed(error, status, xhr); }; })(this) }); }; RecipeCatalog.prototype.onBookLoaded = function(data, status, xhr) { var e; try { this.books.push(this._parser.parse(data)); _(this.books).sortBy('name'); logger.info("loaded recipe book: " + book); this.trigger(Event.book.load.succeeded, this, book); return this.trigger(Event.book.load.finished, this); } catch (_error) { e = _error; return this.onBookLoadFailed(error, status, xhr); } }; RecipeCatalog.prototype.onBookLoadFailed = function(error, status, xhr) { logger.error("failed to load recipe book: " + error); this.trigger(Event.book.load.failed, this, error.message); return this.trigger(Event.book.load.finished, this); }; RecipeCatalog.prototype.toString = function() { return "RecipeCatalog (" + this.cid + ") {books:" + this.books.length + " items}"; }; return RecipeCatalog; })(BaseModel); },{"../constants":2,"./base_model":9,"./recipe_book_parser":15}],17:[function(require,module,exports){ var jade = jade || require('jade').runtime; this["JST"] = this["JST"] || {}; this["JST"]["landing_page"] = function template(locals) { var buf = []; var jade_mixins = {}; var jade_interp; var jade_indent = []; buf.push("\n
\n
\n
\n
");;return buf.join(""); }; this["JST"]["recipe_catalog"] = function template(locals) { var buf = []; var jade_mixins = {}; var jade_interp; var jade_indent = []; buf.push("\n
\n

\n

Recipe Catalog

\n

\n \n \n \n \n \n
 \n \n \n
\n
\n

\n
\n
");;return buf.join(""); }; this["JST"]["test"] = function template(locals) { var buf = []; var jade_mixins = {}; var jade_interp; var jade_indent = []; buf.push("\n

Hello world!

");;return buf.join(""); }; if (typeof exports === 'object' && exports) {module.exports = this["JST"];} },{"jade":1}]},{},[8]);