lib/daddy/cucumber/diff.rb in daddy-0.1.12 vs lib/daddy/cucumber/diff.rb in daddy-0.1.13

- old
+ new

@@ -4,20 +4,20 @@ module Cucumber module Diff def git_diff(file, options = {}) options[:as] ||= 'edit' - + git = Daddy::Git.new a = File.read(file).gsub(/[<>]/, '<' => '&lt;', '>' => '&gt;') b = git.show_previous(file, true).gsub(/[<>]/, '<' => '&lt;', '>' => '&gt;') diff = format_diff(Differ.diff(a, b), options) show_filename(file, options) puts "<pre>#{diff}</pre>" end - + def git_diff_name(*includes) git = Daddy::Git.new puts '<pre>' + git.git_diff_name(*includes) + '</pre>' end @@ -30,11 +30,28 @@ puts "<pre>#{diff}</pre>" end def show(file, options = {}) show_filename(file, options) - puts "<pre>#{File.read(file).gsub(/[<>]/, '<' => '&lt;', '>' => '&gt;')}</pre>" + + lines = File.readlines(file) + + if options[:from] and options[:to] + from = options[:from] - 1 + to = options[:to] - 1 + lines = lines[from..to] + elsif options[:from] + from = options[:from] - 1 + lines = lines[from..-1] + elsif options[:to] + to = options[:to] - 1 + lines = lines[0..to] + end + + lines = lines.join.gsub(/[<>]/, '<' => '&lt;', '>' => '&gt;') + puts "<pre>#{lines}</pre>" + end private def show_filename(filename, options = {}) @@ -62,12 +79,10 @@ puts html end def format_diff(diff, options = {}) - lines = [] - diff_lines = diff.to_s.split("\n") if options[:from] and options[:to] from = options[:from] - 1 to = options[:to] - 1 @@ -78,25 +93,10 @@ elsif options[:to] to = options[:to] - 1 diff_lines = diff_lines[0..to] end - diff_lines.each_with_index do |line, i| - if line.index('</del><ins class="differ">') - split = line.split('</del><ins class="differ">') - lines << split[0] - if split[1].start_with?('"') - lines << '</del><ins class="differ">"' - lines << split[1][1..-1] - else - lines << '</del><ins class="differ">' + split[1] - end - else - lines << line - end - end - - lines.join("\n") + diff_lines.join("\n") end end end end