Skip to content

Instantly share code, notes, and snippets.

@abstrctn
Created May 7, 2012 16:29
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 abstrctn/2628792 to your computer and use it in GitHub Desktop.
Save abstrctn/2628792 to your computer and use it in GitHub Desktop.
Oly template debugger
// Toggle display of template paths
$('.oly-debug, .oly-debug-template-path').toggle();
/* Ruby helper: create ruby variables for a given segment of the template:
e = Event
p = Phase
u = Unit (best guess)
r = UnitResult
cr = CumulativeResult
pr = PhaseResult
*/
function add_inspector(div, ruby) {
var inspector = $("<div style='overflow:hidden'><input class='oly-debug' value='" + ruby + "' style='border: 0; width: 71px; height: 23px; margin: 0 12px 0 -7px; background-color: black; color: white; font-weight: bold;' onclick='javascript:this.select();'></div>");
$(div).before(inspector);
}
// UnitRunner
$.each($('.oly-game-detail'), function() {
if (!$(this).hasClass('oly-debug-ruby-check')) {
var unit_id = $(this).data('unit-id');
var value = '" run "; ';
value += 'r = UnitRunner.new(Unit.find("' + unit_id + '")); ';
value += 'r.files; ';
value += 'r.reset! ';
add_inspector(this, value);
}
$(this).addClass('oly-debug-ruby-check');
});
$.each($('.result-table'), function() {
//var matched = $(this).attr('class').match(/([A-Z]{3}\d{3}[A-Z1-9])/);
if (!$(this).hasClass('oly-debug-ruby-check') && $(this).data('event-id') != undefined) {
var value = '" inspect.rb "; ';
value += 'e = Event.find("' + $(this).data('event-id') + '"); ';
value += 'd = e.discipline; ';
value += 'u = e.units.displayable.first; ';
if ($(this).data('phase-id')) {
value += 'p = Phase.find("' + $(this).data('phase-id') + '"); ';
value += 'u = p.units.displayable.first; ';
value += 'cr = p.cumulative_results.first; ';
value += 'pr = p.results.first; ';
}
if ($(this).data('unit-id')) {
value += 'u = Unit.find("' + $(this).data('unit-id') + '"); ';
}
value += 'r = u.results.first';
add_inspector(this, value);
}
$(this).addClass('oly-debug-ruby-check');
});
/*
$.each($('.legend'), function() {
var matched = $(this).data('id').match(/([A-Z]{3}\d{3}[A-Z1-9]\d{2})/)
if (matched != null && !$(this).hasClass('oly-debug-ruby-check')) {
var unit_id = matched[0];
var value = '" inspect.rb "; ';
value += 'u = Unit.find("' + unit_id + '"); ';
value += 'p = u.phase; ';
value += 'e = u.event; ';
value += 'd = e.discipline; ';
value += 'r = u.results.first; ';
value += 'cr = p.cumulative_results.first; ';
value += 'pr = p.results.first';
add_inspector(this, value);
}
$(this).addClass('oly-debug-ruby-check');
});
*/
// Show the event id
var event_id = $('#oly-results').attr('class').match(/([A-Z]{3}\d{3})/)[0];
if (event_id != undefined && $('.oly-debug-event-id').length == 0) {
$('.oly-header h2').append($('<span class="oly-debug oly-debug-event-id"> / <input type="text" value="' + event_id + '" onclick="javascript:this.select();" style="width: 150px; font-size: 31px; background-color: rgb(255, 239, 213);"></span>'))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment