Refactors navigation page generation. Adds navigation by Series.
authorChris Jaekl <cejaekl@yahoo.com>
Sun, 11 Jun 2017 06:34:52 +0000 (15:34 +0900)
committerChris Jaekl <cejaekl@yahoo.com>
Sun, 11 Jun 2017 06:34:52 +0000 (15:34 +0900)
main.rb
page.rb
store.rb

diff --git a/main.rb b/main.rb
index f3371b7d44daf55b9d65c3bbaf488b213d0f091b..e1a52053b93f5c8c107d9178731d1169cfbd7388 100644 (file)
--- a/main.rb
+++ b/main.rb
@@ -1,3 +1,4 @@
+require 'navigator'
 require 'page'
 require 'store'
 require 'walkdir'
@@ -35,87 +36,9 @@ end
 
 puts 'Creating output...'
 
-atoz_counts = {}
+navigator = Navigator.new(@store)
+navigator.write_atoz_pages()
+navigator.write_series_listing()
 
-('A'..'Z').each do |letter| 
-  book_ids = @store.query_books_by_author(letter + '%')
-  puts 'Authors starting with "' + letter + '":  ' + book_ids.length.to_s() + ' books.'
-  atoz_counts[letter] = book_ids.length
-
-  page = Page.new(@store)
-  if 'A' != letter
-    page.back = ['../atoz/output_' + (letter.ord - 1).chr + '.html', 'Prev']
-  end
-  if 'Z' != letter
-    page.forward = ['../atoz/output_' + (letter.ord + 1).chr + '.html', 'Next']
-  end
-  page.output_dir = 'atoz'
-  page.index_file = 'output_' + letter + '.html'
-  page.title = "Authors starting with '" + letter + "'"
-  page.up = ['../atoz/index.html', 'Index']
-
-  page.write_html(book_ids)
-end
-
-
-ages = ['beginner', 'junior', 'ya', 'adult']
-
-series_infos = []
-
-ages.each do |age|
-  puts 'Series for "' + age + '" readers...'
-
-  series_ids = @store.query_series_by_age(age)
-
-  series_ids.each do |id|
-    series = @store.load_series(id)
-    book_ids = @store.query_books_by_series_id(id)
-    if nil != book_ids and book_ids.length > 0
-      series_infos.push( [series, book_ids] )
-    end
-  end
-
-  for idx in 0 .. (series_infos.length - 1) do 
-    #puts series.descr + ': ' + book_ids.length.to_s + ' books.'
-
-    back = nil
-    fwd = nil
-
-    if idx > 0
-      back = series_infos[idx-1]
-    end
-    if idx < (series_infos.length - 1)
-      fwd = series_infos[idx+1]
-    end
-
-    cur = series_infos[idx]
-    series = cur[0]
-    book_ids = cur[1]
-
-    page = Page.new(@store)
-    if nil != back
-      page.back = [back[0].key + '.html', 'Back']
-    end
-    if nil != fwd
-      page.forward = [fwd[0].key + '.html', 'Forward']
-    end
-    page.output_dir = 'series'
-    page.index_file = series.key + '.html'
-    page.title = 'Series &ldquo;' + series.descr + '&rdquo; (' + book_ids.length.to_s + ' books)'
-    page.up = ['../atoz/index.html', 'Index']
-  
-    page.write_html(book_ids)
-  end
-end
-
-content = '<table><tr><th>Author</th><th>Books</th></tr>'
-('A'..'Z').each do |letter|
-  content += '  <tr><td><a href="../atoz/output_' + letter + '.html">Starting with ' + letter + '</a></td><td>' + atoz_counts[letter].to_s + '</td></tr>'
-end
-page = Page.new(@store)
-page.output_dir = 'atoz'
-page.special = content
-page.write_html( [] )
-  
 @store.disconnect()
 
diff --git a/page.rb b/page.rb
index 1d83add369433cc331c3f1e8ed8099d4d22738c3..ac1c90738769d5032c5794f5eb4e4bd627c3be4f 100644 (file)
--- a/page.rb
+++ b/page.rb
@@ -1,3 +1,4 @@
+require 'fileutils'
 require 'store'
 
 
@@ -91,7 +92,7 @@ class Page
     @imageCount = 0
 
     if ! Dir.exist?(@output_dir)
-      Dir.mkdir(@output_dir)
+      FileUtils.mkdir_p(@output_dir)
     end
 
     open(@output_dir + '/' + @index_file, 'w') do |fd|
index 0ba3447e8807051c923b258cfcbf9f4270d398b3..05f44132d1609af54f4cbb3e47befc69161fbce3 100644 (file)
--- a/store.rb
+++ b/store.rb
@@ -393,9 +393,10 @@ EOS
   def query_series_by_age(pattern)
     sql = 
 <<EOS
-      SELECT s.id FROM Series s
+      SELECT s.id 
+      FROM Series s
       WHERE s.age LIKE $1
-      ORDER BY s.descr
+      ORDER BY s.grouping,s.descr
 EOS
     series_ids = []
     @conn.exec_params(sql, [pattern]) do |rs|