module BlobsHelper include RepositoriesHelper include TreesHelper def line_numbers_for(data, code_theme_class = nil) out = [] #yield.split("\n").each_with_index{ |s,i| out << "#{i+1}: #{s}" } out << %Q{} data.to_s.split("\n").each_with_index do |line, count| lineno = count + 1 out << %Q{} out << %Q{} code_classes = "code" code_classes << " #{code_theme_class}" if code_theme_class out << %Q{} out << "" end out << "
#{lineno}#{line}
" out.join("\n") end def render_highlighted(text, filename, theme = "idle") syntax_name = Uv.syntax_names_for_data(filename, text).first #TODO: render a choice select box if > 1 begin highlighted = Uv.parse(text, "xhtml", syntax_name, false, theme) rescue => e if e.to_s =~ /Oniguruma Error/ highlighted = text else raise e end end line_numbers_for(highlighted, theme) end def too_big_to_render?(size) size > 150.kilobytes end end