Created
January 31, 2012 18:03
-
-
Save Phoscur/1711898 to your computer and use it in GitHub Desktop.
Revisions
-
Phoscur created this gist
Jan 31, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ var View = require("./View"); function ResourcesView(language) { View.call(this, this.getTemplate("#resourcesTemplate"), language); } ResourcesView.prototype = Object.create(View.prototype); ResourcesView.prototype.render = function(resources) { return resources.map(function(res) { return View.prototype.render.call(this, { resourceType: res.getType(), resourceAmount: res.getAmount() }); }).join("\n"); }; module.exports = ResourcesView; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ var View = require("./View") , ResourcesView = require("./ResourcesView"); function SolarsystemView(language) { View.call(this, this.getTemplate("#solarsystemTemplate"), language); this.resources = new ResourcesView(language); } SolarsystemView.prototype = Object.create(View.prototype); SolarsystemView.prototype.render = function(solarsystem) { return View.prototype.render.call(this, { solarsystemName: solarsystem.getName(), solarsystemSize: solarsystem.getSize(), solarsystemResources: this.resources.render(solarsystem.getResources()) }); }; module.exports = SolarsystemView; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ var Plates = require("Plates") , $ = jQuery = require("jQuery") , _ = require("underscore") , sprintf = require("sprintf"); function View(template, language) { this.language = language; this.template = template; this.map = new this.plates.Map(); } View.prototype.getTemplate = function(selector) { return $(selector).html(); }; View.prototype.plates = Plates; View.prototype.jQuery = jQuery; View.prototype.sprintf = sprintf; View.prototype.render = function(data) { return this.plates.bind(this.parseData(data, this.language), this.template, this.map); }; View.prototype.parseData = function(data, language) { var self = this; var newData = {}; _.each(data, function(value, key) { if (_.isArray(value)) { value.unshift(null, language[key]); newData[key] = self.sprintf.apply(value); } else { newData[key] = language[key] ? self.sprintf(language[key], value) : value; } }); return newData; }; module.exports = View; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ <div id="resourcesTemplate"> <dl class="resources"> <div class="resource"> <dt class="resourceType">Iron</dt> <dd class="resourceAmount">100t</dd> </div> </dl> </div> <div id="solarsystemTemplate"> <div class="solarsystem"> <h2 class="solarsystemName">Solarsystem</h2> <div class="solarsystemResources">100t iron</div> <dl> <dt>Diameter</dt><dd class="solarsystemSize">8999 <em title="10^12 m">terrametres</em></dd> </dl> </div> </div>