X-Git-Url: http://jaekl.net/gitweb/?p=quanlib.git;a=blobdiff_plain;f=main.rb;h=d193c22360fab18aa2850cbc5a2b6d132c2aa843;hp=596e11ff526fec0f09227bda8bcad927ab163180;hb=b31122c5ed23e2e77b527c0979b6355e9e3dda1f;hpb=4b53af822cda819dd82d0d3e7ed066c2966ae4bf diff --git a/main.rb b/main.rb index 596e11f..d193c22 100644 --- a/main.rb +++ b/main.rb @@ -1,9 +1,10 @@ +require 'page' require 'store' require 'walkdir' outputDir = 'output' -books = [] +book_ids = [] imageCount = 0 def handleArg(arg) @@ -28,65 +29,41 @@ for arg in ARGV if ! arg.start_with?("--") puts 'Scanning directory "' + arg + '"...' w = WalkDir.new(@store, arg) - books += (w.books) + book_ids += (w.books) end end puts 'Creating output...' -if ! Dir.exist?(outputDir) - Dir.mkdir(outputDir) -end - -open(outputDir + '/index.html', 'w') do |fd| - fd.puts '' - fd.puts ' ' - fd.puts ' ' - fd.puts ' Books' - fd.puts ' ' - fd.puts ' ' - fd.puts ' ' - - for book in books - image = nil - if nil != book.cover - imageCount += 1 - (path, mimeType) = book.cover.write_image(outputDir, 'image' + imageCount.to_s) - image = '' - else - image = '(No cover image)' - end +counts = {} - fd.puts '
' - fd.puts ' ' +('A'..'Z').each do |letter| + book_ids = @store.query_books_by_author(letter + '%') + puts 'Authors starting with "' + letter + '": ' + book_ids.length.to_s() + ' books.' + counts[letter] = book_ids.length - heading = book.heading() - description = book.description() - if nil != description - fd.puts ' ' - else - fd.puts ' ' - end - - fd.puts '
' + image + '' + heading + '

' + heading + '

' + description + '

' + heading + '
' + page = Page.new(@store) + if 'A' != letter + page.back = ['../output_' + (letter.ord - 1).chr + '/index.html', 'Prev'] end - - fd.puts " " - fd.puts " " - fd.puts "" + if 'Z' != letter + page.forward = ['../output_' + (letter.ord + 1).chr + '/index.html', 'Next'] + end + page.output_dir = 'output_' + letter + page.title = "Authors starting with '" + letter + "'" + page.up = ['../output/index.html', 'Index'] + + page.write_html(book_ids) end +content = '' +('A'..'Z').each do |letter| + content += ' ' +end +page = Page.new(@store) +page.output_dir = 'output' +page.special = content +page.write_html( [] ) + @store.disconnect() +
AuthorBooks
Starting with ' + letter + '' + counts[letter].to_s + '