# coding: UTF-8 module Daddy module Cucumber module Diff def git_diff(file, options = {}) git = Daddy::Git.new a = File.read(file).gsub(/[<>]/, '<' => '<', '>' => '>') b = git.show_previous(file, true).gsub(/[<>]/, '<' => '<', '>' => '>') diff = format_diff(Differ.diff(a, b)) show_filename(file, options) puts "
#{diff}" end def git_diff_name(*includes) git = Daddy::Git.new puts '
' + git.git_diff_name(*includes) + '' end def diff(file_a, file_b) a = File.read(file_a) b = File.read(file_b) diff = format_diff(Differ.diff(a, b)) puts file_a puts "
#{diff}" end def show(file, options = {}) show_filename(file, options) puts "
#{File.read(file).gsub(/[<>]/, '<' => '<', '>' => '>')}" end private def show_filename(filename, options = {}) if options[:as] == 'new' puts "[新規作成] #{filename}" else puts filename end end def format_diff(diff) lines = [] diff_lines = diff.to_s.split("\n") diff_lines.each_with_index do |line, i| if line.index('') split = line.split('') lines << split[0] if split[1].start_with?('"') lines << '"' lines << split[1][1..-1] else lines << '' + split[1] end else lines << line end end lines.join("\n") end end end end World(Daddy::Cucumber::Diff)