Class: XdocletBuilder
Overview
Construction de la tache xdoclet (transformation du code Ruby en HMTL)
author: Vincent Dubois
date: 07 fevrier 2009
Instance Method Summary collapse
-
#build(project_name, auto_install, proxy_option) ⇒ Object
Implementation de la construction de la tache.
Methods included from Utils
build_name, erb_run, flog_caracteristics, flog_score_to_css_style, percent_to_css_style, run_command, verify_gem_presence
Instance Method Details
#build(project_name, auto_install, proxy_option) ⇒ Object
Implementation de la construction de la tache
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/xdoclet_builder.rb', line 10 def build(project_name, auto_install, proxy_option) # Vérification de la présence du gem syntax Utils.verify_gem_presence("syntax", auto_install, proxy_option) # Génération du rapport pour chaque fichier source ruby puts " Building xdoc source report..." FileUtils.mkdir("#{Continuous4r::WORK_DIR}/xdoclet") require 'syntax/convertors/html' files = Array.new files << Dir.glob("#{RAILS_ROOT}/app/**/*.rb") files << Dir.glob("#{RAILS_ROOT}/lib/**/*.rb") files << Dir.glob("#{RAILS_ROOT}/test/**/*.rb") files.flatten! convertor = Syntax::Convertors::HTML.for_syntax("ruby") files.each do |file| print "\nProcessing #{file.gsub(Regexp.new("#{RAILS_ROOT}/"),'')}..." ruby_code = File.read(file) html_code = convertor.convert(ruby_code) # Ajout des numéros de lignes html_code_with_lines = "" html_code_lines = html_code.split(/$/) html_code_lines.each_with_index do |line,index| if index == 0 html_code_with_lines = html_code_with_lines.concat("<pre><a name='#{(index + 1).to_s}'></a><span class='numline'>#{(index + 1).to_s.rjust(4)} </span>").concat(line.delete("\n").gsub(/<pre>/,'')).concat("\n") elsif index == html_code_lines.length - 1 print "OK" else html_code_with_lines = html_code_with_lines.concat("<span class='numline'>#{(index + 1).to_s.rjust(4)} </span><a name='#{(index + 2).to_s}'></a>").concat(line.delete("\n")).concat("\n") end end html_file = File.open("#{Continuous4r::WORK_DIR}/xdoclet/#{file.gsub(Regexp.new("#{RAILS_ROOT}/"),'').gsub(/\//,'_')}.html", "w") html_global_code = "<html><head><title>Source code for #{file.gsub(Regexp.new("#{RAILS_ROOT}/"),'')}</title>" html_global_code = html_global_code + "<style>#{File.read("#{File.dirname(__FILE__)}/site/syntax_highlighting.css")}</style>" html_global_code = html_global_code + "<body><h2>Source code for #{file.gsub(Regexp.new("#{RAILS_ROOT}/"),'')}</h2><br/>#{html_code_with_lines}</body></html>" html_file.write(html_global_code) html_file.close end end |