module RepositoryHelper def change_map(change_name) changed_type = { 'M' => 'Updated', 'A' => 'Added', 'D' => 'Deleted', 'CP'=> 'Copied', 'MV'=> 'Moved' } changed_type[change_name] end # returns and unordered list with clickable path parts def path_breadcrumbs(paths, last_element_clickable=false) out = "" end # Takes a unified diff as input and renders it as html def render_diff(udiff) return if udiff.blank? out = "\n" lines = udiff.split("\n") lines_that_differs = /@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@/ out << "\n" out << "\t\n" out << "\n" prev_counter = 0 cur_counter = 0 change_num = 0 lines[2..lines.length].each do |line| if line_nums = line.match(lines_that_differs) prev_line_numbers = line_nums[1].to_i...(line_nums[1].to_i + (line_nums[2]).to_i) cur_line_numbers = line_nums[3].to_i...(line_nums[3].to_i + (line_nums[4]).to_i) prev_counter = prev_line_numbers.first - 1 cur_counter = cur_line_numbers.first - 1 change_num += 1 end line = h(line) line.gsub!(/^(\+{1}(\s+|\t+)?(.*))/, '\2\3') line.gsub!(/^(-{1}(\s+|\t+)?(.*))/, '\2\3') line.gsub!('\ No newline at end of file', '') out << "\n" if line.match(/^(\s+|\t+)?/) out << "\t\n" out << "\t\n" prev_counter += 1 action_class = 'del' elsif line.match(/^(\s+|\t+)?/) out << "\t\n" out << "\t\n" cur_counter += 1 action_class = 'ins' else if line.match(lines_that_differs) line = '' if change_num > 1 out << "\t\n" out << "\t\n" action_class = 'cut-line' else out << "\t\n" out << "\t\n" action_class = 'unchanged' end else out << "\t\n" out << "\t\n" action_class = 'unchanged' end prev_counter += 1 cur_counter += 1 end out << "\t\n" end out << "\n
prev.current 
" + prev_counter.to_s + "  " + cur_counter.to_s + "......" + line + "
\n" end def highlight(content, mime_type) # prepare the hash of mime_types to tokenizer types # TODO: Create more Syntax defs, and/or fix the xml highlighter to be more forgiving mime_tokenizers = { 'text/xml' => 'xml', #'text/x-html+ruby' => 'xml', # .rhtml #'text/html' => 'xml', 'text/x-ruby' => 'ruby', 'text/x-yaml' => 'yaml', #'text/css' => 'yaml' } type = mime_tokenizers[mime_type] return make_line_nums(h(content)) unless Syntax::SYNTAX.has_key? type converted = Syntax::Convertors::HTML.for_syntax(type).convert(content,false) make_line_nums(converted, type) end def make_line_nums(contents, css_class="") line_num = 1 html = "\n" contents.each_line do |content| html << "\n" html << ' \n" html << ' \n" html << "\n" line_num += 1 end html << '
' + line_num.to_s + "' + content + "
' end end