var CucumberHTML = {}; CucumberHTML.DOMFormatter = function(rootNode) { var currentUri; var currentFeature; var currentElement; var currentSteps; var currentStepIndex; var currentStep; var $templates = $(CucumberHTML.templates); this.uri = function(uri) { currentUri = uri; }; this.feature = function(feature) { currentFeature = blockElement(rootNode, feature, 'feature'); }; this.background = function(background) { currentElement = featureElement(background, 'background'); currentStepIndex = 1; }; this.scenario = function(scenario) { currentElement = featureElement(scenario, 'scenario'); currentStepIndex = 1; }; this.scenarioOutline = function(scenarioOutline) { currentElement = featureElement(scenarioOutline, 'scenario_outline'); currentStepIndex = 1; }; this.step = function(step) { var stepElement = $('.step', $templates).clone(); stepElement.appendTo(currentSteps); populate(stepElement, step, 'step'); if (step.doc_string) { docString = $('.doc_string', $templates).clone(); docString.appendTo(stepElement); // TODO: use a syntax highlighter based on the content_type docString.text(step.doc_string.value); } if (step.rows) { dataTable = $('.data_table', $templates).clone(); dataTable.appendTo(stepElement); var tBody = dataTable.find('tbody'); $.each(step.rows, function(index, row) { var tr = $('
' + text + ''); }; this.before = function(before) { if(before.status != 'passed') { currentElement = featureElement({keyword: 'Before', name: '', description: ''}, 'before'); currentStepIndex = 1; populateStepError($('details', currentElement), before.error_message); } }; this.after = function(after) { if(after.status != 'passed') { currentElement = featureElement({keyword: 'After', name: '', description: ''}, 'after'); currentStepIndex++; populateStepError($('details', currentElement), after.error_message); } }; function featureElement(statement, itemtype) { var e = blockElement(currentFeature.children('details'), statement, itemtype); currentSteps = $('.steps', $templates).clone(); currentSteps.appendTo(e.children('details')); return e; } function blockElement(parent, statement, itemtype) { var e = $('.blockelement', $templates).clone(); e.appendTo(parent); return populate(e, statement, itemtype); } function populate(e, statement, itemtype) { populateTags(e, statement.tags); populateComments(e, statement.comments); e.find('.keyword').text(statement.keyword); e.find('.name').text(statement.name); e.find('.description').text(statement.description); e.attr('itemtype', 'http://cukes.info/microformat/' + itemtype); e.addClass(itemtype); return e; } function populateComments(e, comments) { if (comments !== undefined) { var commentsNode = $('.comments', $templates).clone().prependTo(e.find('.header')); $.each(comments, function(index, comment) { var commentNode = $('.comment', $templates).clone().appendTo(commentsNode); commentNode.text(comment.value); }); } } function populateTags(e, tags) { if (tags !== undefined) { var tagsNode = $('.tags', $templates).clone().prependTo(e.find('.header')); $.each(tags, function(index, tag) { var tagNode = $('.tag', $templates).clone().appendTo(tagsNode); tagNode.text(tag.name); }); } } function populateStepError(e, error) { if (error !== undefined) { errorNode = $('.error', $templates).clone().appendTo(e); errorNode.text(error); } } }; CucumberHTML.templates = '