namespace :noosfero do namespace :doc do input = Dir.glob('doc/noosfero/**/*.textile') topics_xhtml = input.map { |item| item.sub('.textile', '.en.xhtml') } sections = Dir.glob('doc/noosfero/*').select {|item| File.directory?(item) } toc_sections = sections.map {|item| File.join(item, 'toc.en.xhtml')} index_sections = sections.map {|item| File.join(item, 'index.en.xhtml')} def build_textile(input, output) begin File.open(output ,'w') do |output_file| output_file.write(RedCloth.new(File.read(input)).to_html) puts "#{input} -> #{output}" end rescue Exception => e rm_f output raise e end end topics_xhtml.each do |target| source = target.sub('.en.xhtml', '.textile') file target => source do |t| build_textile(source, target) end end toc_sections.each do |toc| section_topics = Dir.glob(File.dirname(toc) + '/*.textile').map {|item| item.sub('.textile', '.en.xhtml') }.reject {|item| ['index.en.xhtml', 'toc.en.xhtml' ].include?(File.basename(item))} file toc => section_topics do |t| begin File.open(toc, 'w') do |output_file| section = File.basename(File.dirname(toc)) output_file.puts "" output_file.puts "" puts "#{section_topics.join(', ')} -> #{toc}" end rescue Exception => e rm_rf toc raise e end end end top_level_toc = 'doc/noosfero/toc.en.xhtml' file top_level_toc => index_sections do begin File.open(top_level_toc, 'w') do |output_file| output_file.puts "" output_file.puts "" end rescue Exception => e rm_f top_level_toc raise e end end english_xhtml = (topics_xhtml + toc_sections + [top_level_toc]) task :english => english_xhtml po4a_conf = 'tmp/po4a.conf' file po4a_conf => english_xhtml do begin File.open(po4a_conf, 'w') do |file| file.puts "[po4a_langs] #{(Noosfero.locales.keys - ['en']).join(' ')}" file.puts "[po4a_paths] po/noosfero-doc.pot $lang:po/$lang/noosfero-doc.po" english_xhtml.each do |item| file.puts "[type: xhtml] #{item} $lang:#{item.sub(/\.en\.xhtml/, '.$lang.xhtml')}" end end rescue Exception => e rm_f po4a_conf raise e end end task :build => po4a_conf do sh "po4a #{po4a_conf}" end task :clean do sh 'rm -f doc/noosfero/*.xhtml' sh 'rm -f doc/noosfero/*/*.xhtml' rm_f po4a_conf end task :rebuild => [:clean, :build] end end