Stores book metadata to PostgreSQL database.
[quanlib.git] / main.rb
diff --git a/main.rb b/main.rb
index 4e73b07c0b490eca6eef199f504055406bfb907d..bc175fbf51ae33205a37735d1390872a3ea630e1 100644 (file)
--- a/main.rb
+++ b/main.rb
@@ -1,3 +1,4 @@
+require 'store'
 require 'walkdir'
 
 outputDir = 'output'
@@ -5,32 +6,82 @@ outputDir = 'output'
 books = []
 imageCount = 0
 
+def handleArg(arg)
+  if "--purge" == arg
+    puts 'Purging database...'
+    @store.dropSchema()
+  elsif arg.start_with?("--")
+    abort('ERROR:  Unrecognized option "' + arg + '".')
+  end
+end
+
+@store = Store.new()
+@store.connect()
+
 for arg in ARGV
-  w = WalkDir.new(arg)
-  books += (w.books)
+  handleArg(arg)
 end
 
+@store.init_db()
+
+for arg in ARGV
+  if ! arg.start_with?("--")
+    puts 'Scanning directory "' + arg + '"...'
+    w = WalkDir.new(@store, arg)
+    books += (w.books)
+  end
+end
+
+puts 'Creating output...'
+
 if ! Dir.exist?(outputDir)
   Dir.mkdir(outputDir)
 end
 
 open(outputDir + '/index.html', 'w') do |fd|
-  fd.puts "<html>"
-  fd.puts "  <head><title>Books</title></head>"
-  fd.puts "  <body>"
-  fd.puts "    <table>"
+  fd.puts '<html>'
+  fd.puts '  <head>'
+  fd.puts '    <meta charset="utf-8"/>'
+  fd.puts '    <title>Books</title>'
+  fd.puts '    <style>'
+  fd.puts 'div { '
+  fd.puts '  display: inline-block;'
+  fd.puts '  width: 400px;'
+  fd.puts '  margin: 10px;'
+  fd.puts '  border 3px solid #73ad21;'
+  fd.puts '}'
+  fd.puts 'span.popup {  }'
+  fd.puts 'span.popup:hover {text-decoration: none; background: #cfffff; z-index: 6; }'
+  fd.puts 'span.popup span {display: none; position: absolute; '
+  fd.puts '  margin: 4px 0 0 0px; padding: 3px 3px 3px 3px;'
+  fd.puts '  border-style:solid; border-color:black; border-width:1px;}'
+  fd.puts 'span.popup:hover span {display: block; margin: 20px 0 0 0px; background: #ffffaf; z-index:6;}'
+  fd.puts '    </style>'
+  fd.puts '  </head>'
+  fd.puts '  <body>'
   
   for book in books
     image = nil
     if nil != book.cover
       imageCount += 1
       (path, mimeType) = book.cover.writeImage(outputDir, 'image' + imageCount.to_s)
-      image = '<img src="' + path + '"/>'
+      image = '<img height="200px" src="' + path + '"/>'
     else
       image = '(No cover image)'
     end
 
-    fd.puts "      <tr><td>" + image + "</td><td>" + book.describe() + "</td></tr>"
+    fd.puts '    <div><table>'
+    fd.puts '      <tr><td><a href="' + book.path + '">' + image + '</a></td>'
+
+    heading = book.heading()
+    description = book.description()
+    if nil != description
+      fd.puts '          <td><span class="popup">' + heading + '<span><p>' + heading + '</p><p>' + description + '</p></span></span></td></tr>'
+    else
+      fd.puts '          <td>' + heading + '</td></tr>'
+    end
+      
+    fd.puts '    </table></div>'
   end
   
   fd.puts "    </table>"
@@ -38,3 +89,4 @@ open(outputDir + '/index.html', 'w') do |fd|
   fd.puts "</html>"
 end
 
+@store.disconnect()