Skip to content

Instantly share code, notes, and snippets.

@danielricecodes
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielricecodes/633c464151f0f1a53e3d to your computer and use it in GitHub Desktop.
Save danielricecodes/633c464151f0f1a53e3d to your computer and use it in GitHub Desktop.
Code Test: This is real code. What does this code do?
function program1(depth0,data) {
var buffer = "", stack1;
buffer += "\n <img alt='";
foundHelper = helpers.product;
stack1 = foundHelper || depth0.product;
stack1 = (stack1 === null || stack1 === undefined || stack1 === false ? stack1 : stack1.name);
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "product.name", { hash: {} }); }
buffer += escapeExpression(stack1) + "' src='";
foundHelper = helpers.product;
stack1 = foundHelper || depth0.product;
stack1 = (stack1 === null || stack1 === undefined || stack1 === false ? stack1 : stack1.heroImage);
stack1 = (stack1 === null || stack1 === undefined || stack1 === false ? stack1 : stack1.baseHTTP);
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "product.heroImage.baseHTTP", { hash: {} }); }
buffer += escapeExpression(stack1);
foundHelper = helpers.product;
stack1 = foundHelper || depth0.product;
stack1 = (stack1 === null || stack1 === undefined || stack1 === false ? stack1 : stack1.heroImage);
stack1 = (stack1 === null || stack1 === undefined || stack1 === false ? stack1 : stack1.relativeURI);
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "product.heroImage.relativeURI", { hash: {} }); }
buffer += escapeExpression(stack1) + "' />\n ";
return buffer;}
function program3(depth0,data) {
var buffer = "", stack1;
buffer += "\n <img alt='";
foundHelper = helpers.product;
stack1 = foundHelper || depth0.product;
stack1 = (stack1 === null || stack1 === undefined || stack1 === false ? stack1 : stack1.name);
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "product.name", { hash: {} }); }
buffer += escapeExpression(stack1) + "' src='/celebrity-asr/images/destinations/ASR/shore_excursions/preview_unavailable.gif' />\n ";
return buffer;}
buffer += "\n <div class='small-package-module' id='";
foundHelper = helpers.id;
stack1 = foundHelper || depth0.id;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "id", { hash: {} }); }
buffer += escapeExpression(stack1) + "'>\n <dl>\n <dt class='thumbnail'>\n ";
foundHelper = helpers.product;
stack1 = foundHelper || depth0.product;
stack1 = (stack1 === null || stack1 === undefined || stack1 === false ? stack1 : stack1.heroImage);
stack2 = helpers['if'];
tmp1 = self.program(1, program1, data);
tmp1.hash = {};
tmp1.fn = tmp1;
tmp1.inverse = self.program(3, program3, data);
stack1 = stack2.call(depth0, stack1, tmp1);
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n </dt>\n <dt class='location'>\n ";
stack1 = 35;
foundHelper = helpers.product;
stack2 = foundHelper || depth0.product;
stack2 = (stack2 === null || stack2 === undefined || stack2 === false ? stack2 : stack2.location);
stack2 = (stack2 === null || stack2 === undefined || stack2 === false ? stack2 : stack2.name);
foundHelper = helpers.truncate;
stack3 = foundHelper || depth0.truncate;
if(typeof stack3 === functionType) { stack1 = stack3.call(depth0, stack2, stack1, { hash: {} }); }
else if(stack3=== undef) { stack1 = helperMissing.call(depth0, "truncate", stack2, stack1, { hash: {} }); }
else { stack1 = stack3; }
buffer += escapeExpression(stack1) + "\n </dt>\n <dd class='blue name'>\n <a href='#'>";
foundHelper = helpers.product;
stack1 = foundHelper || depth0.product;
stack1 = (stack1 === null || stack1 === undefined || stack1 === false ? stack1 : stack1.name);
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "product.name", { hash: {} }); }
buffer += escapeExpression(stack1) + "</a>\n </dd>\n <dd>\n";
foundHelper = helpers.product;
stack1 = foundHelper || depth0.product;
stack1 = (stack1 === null || stack1 === undefined || stack1 === false ? stack1 : stack1.href);
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "product.href", { hash: {} }); }
tmphref=window.location.protocol + "//" + window.location.host+escapeExpression(stack1);
foundHelper = helpers.product;
stack1 = foundHelper || depth0.product;
stack1 = (stack1 === null || stack1 === undefined || stack1 === false ? stack1 : stack1.productID);
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "product.productID", { hash: {} }); }
buffer += "\n <div id='BVRRInlineRating-"+(escapeExpression(stack1).toLowerCase())+"'></div>\n ";
buffer += "\n </dd>\n </dl>\n <div class='detail' \n onmouseover=document.getElementById('InlineRatingTwo-"+escapeExpression(stack1)+"').innerHTML=document.getElementById('BVRRInlineRating-"+(escapeExpression(stack1).toLowerCase())+"').innerHTML; > \n" ;
buffer += " \n <dl>\n <dt class='location'>\n ";
stack1 = 30;
foundHelper = helpers.product;
stack2 = foundHelper || depth0.product;
stack2 = (stack2 === null || stack2 === undefined || stack2 === false ? stack2 : stack2.location);
stack2 = (stack2 === null || stack2 === undefined || stack2 === false ? stack2 : stack2.name);
foundHelper = helpers.truncate;
stack3 = foundHelper || depth0.truncate;
if(typeof stack3 === functionType) { stack1 = stack3.call(depth0, stack2, stack1, { hash: {} }); }
else if(stack3=== undef) { stack1 = helperMissing.call(depth0, "truncate", stack2, stack1, { hash: {} }); }
else { stack1 = stack3; }
buffer += escapeExpression(stack1) + "\n </dt>\n <dd class='blue name'>\n <a href='";
foundHelper = helpers.product;
stack1 = foundHelper || depth0.product;
stack1 = (stack1 === null || stack1 === undefined || stack1 === false ? stack1 : stack1.href);
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "product.href", { hash: {} }); }
buffer += escapeExpression(stack1) + "'>\n ";
foundHelper = helpers.product;
stack1 = foundHelper || depth0.product;
stack1 = (stack1 === null || stack1 === undefined || stack1 === false ? stack1 : stack1.name);
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "product.name", { hash: {} }); }
buffer += escapeExpression(stack1) + "\n </a>\n </dd>\n <dd>";
foundHelper = helpers.product;
stack1 = foundHelper || depth0.product;
stack1 = (stack1 === null || stack1 === undefined || stack1 === false ? stack1 : stack1.productID);
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "product.productID", { hash: {} }); }
buffer += "\n <div id='InlineRatingTwo-"+(escapeExpression(stack1).toLowerCase())+"' > </div> ";
buffer += " \n </dd> \n <dd class='description'> ";
stack1 = 70;
foundHelper = helpers.product;
stack2 = foundHelper || depth0.product;
stack2 = (stack2 === null || stack2 === undefined || stack2 === false ? stack2 : stack2.shortDescription);
foundHelper = helpers.truncate;
stack3 = foundHelper || depth0.truncate;
if(typeof stack3 === functionType) { stack1 = stack3.call(depth0, stack2, stack1, { hash: {} }); }
else if(stack3=== undef) { stack1 = helperMissing.call(depth0, "truncate", stack2, stack1, { hash: {} }); }
else { stack1 = stack3; }
buffer += escapeExpression(stack1) + "</dd>\n <dd class='details-link'>\n <a class='right-arrow-with-divider' href='";
foundHelper = helpers.product;
stack1 = foundHelper || depth0.product;
stack1 = (stack1 === null || stack1 === undefined || stack1 === false ? stack1 : stack1.href);
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "product.href", { hash: {} }); }
buffer += escapeExpression(stack1) + "'>View Details</a>\n </dd>\n </dl>\n </div>\n </div>\n ";
return buffer;});
})();
@danielricecodes
Copy link
Author

This is actual code that is actually in production somewhere.

Goal: look over this and know what it does. Second Goal: how would you refactor something like this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment