X-Git-Url: http://jaekl.net/gitweb/?p=quanlib.git;a=blobdiff_plain;f=navigator.rb;fp=navigator.rb;h=16da65269054c1ab40c7ef9eac98fa71e0585671;hp=0000000000000000000000000000000000000000;hb=fcaeedd4d1c128ff84371c0a7db5d0af6751492a;hpb=dfbc8c62ee2ee6e188609fc44e1a5ac4df40acf4
diff --git a/navigator.rb b/navigator.rb
new file mode 100644
index 0000000..16da652
--- /dev/null
+++ b/navigator.rb
@@ -0,0 +1,142 @@
+require 'page'
+require 'store'
+
+class Navigator
+ def initialize(store)
+ @store = store
+ end
+
+ def write_atoz_pages
+ atoz_counts = {}
+
+ ('A'..'Z').each do |letter|
+ atoz_counts[letter] = write_authors_starting_with(letter)
+ end
+
+ content = '
Author | Books |
'
+ ('A'..'Z').each do |letter|
+ content += ' Starting with ' + letter + ' | ' + atoz_counts[letter].to_s + ' |
'
+ end
+ page = Page.new(@store)
+ page.output_dir = 'atoz'
+ page.special = content
+ page.up = ['../output/index.html', 'Up']
+
+ page.write_html( [] )
+ end
+
+ def write_authors_starting_with(letter)
+ book_ids = @store.query_books_by_author(letter + '%')
+ puts 'Authors starting with "' + letter + '": ' + book_ids.length.to_s() + ' books.'
+
+ 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', 'Up']
+
+ page.write_html(book_ids)
+ return book_ids.length
+ end
+
+ def write_series_for_age(age)
+ series_infos = []
+
+ 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 + 1) < series_infos.length
+ 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/series_' + age
+ page.index_file = series.key + '.html'
+ page.title = 'Series “' + series.descr + '” (' + book_ids.length.to_s + ' books)'
+ page.up = ['index.html', 'Up']
+
+ page.write_html(book_ids)
+ end
+
+ content = '“' + age + '” Series
'
+ content += 'Author | Series | Genre | Books |
'
+ series_infos.each do |cur|
+ series = cur[0]
+ book_ids = cur[1]
+
+ author = series.grouping
+ letter = author[0]
+
+ content += ' '
+ content += '' + author + ' | '
+ content += '' + series.descr + ' | '
+ content += '' + series.genre + ' | '
+ content += '' + book_ids.length.to_s + ' | '
+ content += '
'
+ end
+ content += '
'
+ page = Page.new(@store)
+ page.output_dir = 'series/series_' + age
+ page.special = content
+ page.up = ['../index.html', 'Up']
+ page.write_html( [] )
+
+ return series_infos.length
+ end
+
+ def write_series_listing
+ ages = ['beginner', 'junior', 'ya', 'adult']
+ series_counts = {}
+
+ ages.each do |age|
+ puts 'Series for "' + age + '" readers...'
+
+ series_counts[age] = write_series_for_age(age)
+ end
+
+ content = 'Browse Books By Series
'
+ content += ''
+ content += '
Age | Number of Series |
'
+ ages.each do |age|
+ content += '' + age + ' | ' + series_counts[age].to_s + ' |
'
+ end
+ content += '
'
+ page = Page.new(@store)
+ page.output_dir = 'series'
+ page.special = content
+ page.up = ['../output/index.html', 'Up']
+ page.write_html( [] )
+ end
+end