# File lib/cucumber/formatter/pdf.rb, line 26 26: def initialize(step_mother, path_or_io, options) 27: @step_mother = step_mother 28: @file = ensure_file(path_or_io, "pdf") 29: 30: if(options[:dry_run]) 31: @status_colors = { :passed => BLACK, :skipped => BLACK, :undefined => BLACK, :failed => BLACK, :announced => GREY} 32: else 33: @status_colors = { :passed => '055902', :skipped => GREY, :undefined => 'F27405', :failed => '730202', :announced => GREY} 34: end 35: 36: @pdf = Prawn::Document.new 37: @scrap = Prawn::Document.new 38: @doc = @scrap 39: @options = options 40: @exceptions = [] 41: @indent = 0 42: @buffer = [] 43: load_cover_page_image 44: @pdf.text "\n\n\nCucumber features", :align => :center, :size => 32 45: @pdf.draw_text "Generated: #{Time.now.strftime("%Y-%m-%d %H:%M")}", :size => 10, :at => [0, 24] 46: @pdf.draw_text "$ cucumber #{ARGV.join(" ")}", :size => 10, :at => [0,10] 47: unless options[:dry_run] 48: @pdf.bounding_box [450,100] , :width => 100 do 49: @pdf.text 'Legend', :size => 10 50: @status_colors.each do |k,v| 51: @pdf.fill_color v 52: @pdf.text k.to_s, :size => 10 53: @pdf.fill_color BLACK 54: end 55: end 56: end 57: end
# File lib/cucumber/formatter/pdf.rb, line 153 153: def after_background(background) 154: @in_background = nil 155: end
# File lib/cucumber/formatter/pdf.rb, line 108 108: def after_feature(feature) 109: flush 110: end
# File lib/cucumber/formatter/pdf.rb, line 104 104: def after_feature_element(feature_element) 105: flush 106: end
# File lib/cucumber/formatter/pdf.rb, line 81 81: def after_features(features) 82: @pdf.render_file(@file.path) 83: puts "\ndone" 84: end
# File lib/cucumber/formatter/pdf.rb, line 74 74: def announce(announcement) 75: @pdf.fill_color(@status_colors[:announced]) 76: @pdf.text announcement, :size => 10 77: @pdf.fill_color BLACK 78: end
# File lib/cucumber/formatter/pdf.rb, line 190 190: def background_name(keyword, name, file_colon_line, source_indent) 191: feature_element_name(keyword, name) 192: end
# File lib/cucumber/formatter/pdf.rb, line 149 149: def before_background(background) 150: @in_background = true 151: end
# File lib/cucumber/formatter/pdf.rb, line 157 157: def before_multiline_arg(table) 158: return if @hide_this_step 159: if(table.kind_of? Cucumber::Ast::Table) 160: keep_with do 161: print_table(table, ['ffffff', 'f0f0f0']) 162: end 163: end 164: end
using row_color hack to highlight each row correctly
# File lib/cucumber/formatter/pdf.rb, line 167 167: def before_outline_table(table) 168: return if @hide_this_step 169: row_colors = table.example_rows.map { |r| @status_colors[r.status] unless r.status == :skipped} 170: keep_with do 171: print_table(table, row_colors) 172: end 173: end
# File lib/cucumber/formatter/pdf.rb, line 175 175: def before_py_string(string) 176: return if @hide_this_step 177: s = %{"""\n#{string}\n"""}.indent(10) 178: s = s.split("\n").map{|l| l =~ /^\s+$/ ? '' : l} 179: s.each do |line| 180: keep_with { @doc.text(line, :size => 8) } 181: end 182: end
# File lib/cucumber/formatter/pdf.rb, line 194 194: def examples_name(keyword, name) 195: feature_element_name(keyword, name) 196: end
# File lib/cucumber/formatter/pdf.rb, line 112 112: def feature_element_name(keyword, name) 113: names = name.empty? ? [name] : name.split("\n") 114: print "." 115: STDOUT.flush 116: 117: keep_with do 118: @doc.move_down(20) 119: @doc.fill_color GREY 120: @doc.text("#{keyword}", :size => 8) 121: @doc.fill_color BLACK 122: @doc.text("#{names[0]}", :size => 16) 123: names[1..1].each { |s| @doc.text(s, :size => 12) } 124: @doc.text("\n") 125: end 126: end
# File lib/cucumber/formatter/pdf.rb, line 86 86: def feature_name(keyword, name) 87: @pdf.start_new_page 88: names = name.split("\n") 89: @pdf.fill_color GREY 90: @pdf.text(keyword, :align => :center) 91: @pdf.fill_color BLACK 92: names.each_with_index do |nameline, i| 93: case i 94: when 0 95: @pdf.text(nameline.strip, :size => 30, :align => :center ) 96: @pdf.text("\n") 97: else 98: @pdf.text(nameline.strip, :size => 12) 99: end 100: end 101: @pdf.move_down(30) 102: end
# File lib/cucumber/formatter/pdf.rb, line 59 59: def load_cover_page_image() 60: if (!load_image("features/support/logo.png")) 61: load_image("features/support/logo.jpg") 62: end 63: end
# File lib/cucumber/formatter/pdf.rb, line 65 65: def load_image(image_path) 66: begin 67: @pdf.image open(image_path, "rb"), :position => :center, :width => 500 68: true 69: rescue Errno::ENOENT 70: false 71: end 72: end
# File lib/cucumber/formatter/pdf.rb, line 198 198: def scenario_name(keyword, name, file_colon_line, source_indent) 199: feature_element_name(keyword, name) 200: end
# File lib/cucumber/formatter/pdf.rb, line 143 143: def step_name(keyword, step_match, status, source_indent, background) 144: return if @hide_this_step 145: line = "#{keyword} #{step_match.format_args("%s")}" 146: colorize(line, status) 147: end
# File lib/cucumber/formatter/pdf.rb, line 128 128: def step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) 129: @hide_this_step = false 130: if exception 131: if @exceptions.include?(exception) 132: @hide_this_step = true 133: return 134: end 135: @exceptions << exception 136: end 137: if status != :failed && @in_background ^ background 138: @hide_this_step = true 139: return 140: end 141: end
# File lib/cucumber/formatter/pdf.rb, line 184 184: def tag_name(tag_name) 185: return if @hide_this_step 186: tag = format_string(tag_name, :tag).indent(@indent) 187: # TODO should we render tags at all? skipped for now. difficult to place due to page breaks 188: end
# File lib/cucumber/formatter/pdf.rb, line 204 204: def colorize(text, status) 205: keep_with do 206: @doc.fill_color(@status_colors[status] || BLACK) 207: @doc.text(text) 208: @doc.fill_color(BLACK) 209: end 210: end
This method does a ‘test’ rendering on a blank page, to see the rendered height of the buffer if that too high for the space left on the age in the real document, we do a page break. This obviously doesn’t work if a scenario is longer than a whole page (God forbid)
# File lib/cucumber/formatter/pdf.rb, line 226 226: def flush 227: @scrap.start_new_page 228: oldy = @scrap.y 229: render @scrap 230: height = (oldy - @scrap.y) + 36 # whops magic number 231: if ((@pdf.y - height) < @pdf.bounds.bottom) 232: @pdf.start_new_page 233: end 234: render @pdf 235: @pdf.move_down(20) 236: @buffer = [] 237: end
# File lib/cucumber/formatter/pdf.rb, line 212 212: def keep_with(&block) 213: @buffer << block 214: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.