seriesInfo = []
series = @store.load_series(@series_id)
- if nil != series
- seriesInfo.push(series.to_s)
+ if nil != series and nil != series.descr
+ seriesInfo.push(series.descr.to_s)
end
if nil != @volume
seriesInfo.push(@volume.to_s)
class Cover
def initialize(inputStream, path, mimeType)
- @data = inputStream.read
+ if nil != inputStream
+ @data = inputStream.read
+ else
+ @data = nil
+ end
@path = path
@mimeType = mimeType
end
+ def path
+ @path
+ end
+
def inspect
info = []
if nil != @data
puts 'Creating output...'
-counts = {}
+atoz_counts = {}
('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
+ atoz_counts[letter] = book_ids.length
page = Page.new(@store)
if 'A' != letter
- page.back = ['../output_' + (letter.ord - 1).chr + '/index.html', 'Prev']
+ page.back = ['../atoz/output_' + (letter.ord - 1).chr + '.html', 'Prev']
end
if 'Z' != letter
- page.forward = ['../output_' + (letter.ord + 1).chr + '/index.html', 'Next']
+ page.forward = ['../atoz/output_' + (letter.ord + 1).chr + '.html', 'Next']
end
- page.output_dir = 'output_' + letter
+ page.output_dir = 'atoz'
+ page.index_file = 'output_' + letter + '.html'
page.title = "Authors starting with '" + letter + "'"
- page.up = ['../output/index.html', 'Index']
+ 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 “' + series.descr + '” (' + 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="../output_' + letter + '/index.html">Starting with ' + letter + '</a></td><td>' + counts[letter].to_s + '</td></tr>'
+ 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 = 'output'
+page.output_dir = 'atoz'
page.special = content
page.write_html( [] )
def initialize(store)
@back = nil
@forward = nil
+ @index_file = 'index.html'
@output_dir = 'output'
@special = nil
@store = store
@forward = value
end
+ def index_file=(value)
+ @index_file = value
+ end
+
def navig_link(data)
if (nil == data)
return ''
book = @store.load_book(id)
image = nil
if nil != book.cover
- @imageCount += 1
- (path, mimeType) = book.cover.write_image(@output_dir, 'image' + @imageCount.to_s)
+ #@imageCount += 1
+ #(path, mimeType) = book.cover.write_image(@output_dir, 'image' + @imageCount.to_s)
+ #image = '<img class="cover-thumb" src="' + path + '"/>'
+ path = book.cover.path
image = '<img class="cover-thumb" src="' + path + '"/>'
else
image = '(No cover image)'
Dir.mkdir(@output_dir)
end
- open(@output_dir + '/index.html', 'w') do |fd|
+ open(@output_dir + '/' + @index_file, 'w') do |fd|
fd.puts '<html>'
fd.puts ' <head>'
fd.puts ' <meta charset="utf-8"/>'
require 'fileutils'
require 'pg'
+require 'series'
+
class Store
def initialize
@basepath = '/arc/quanlib' # TODO: FIXME: configure this in a sane way
(efspath, efsname) = construct_efs_path(id)
- File.open(@basepath + '/efs/' + efspath + '/' + efsname, 'rb') do |is|
- return Cover.new(is, efsname, mime_type)
- end
+ fullpath = @basepath + '/efs/' + efspath + '/' + efsname
- return nil
+ return Cover.new(nil, fullpath, mime_type)
+
+ #File.open(fullpath, 'rb') do |is|
+ # return Cover.new(is, fullpath, mime_type)
+ #end
+ #
+ #return nil
end
def store_cover(book)
end
def load_series(id)
- sql = "SELECT descr FROM Series WHERE id=$1;"
+ sql = "SELECT age,genre,grouping,code,descr FROM Series WHERE id=$1;"
args = [id]
@conn.exec_params(sql, args) do |rs|
if rs.ntuples > 0
- return rs[0]['descr']
+ row = rs[0]
+ series = Series.new(id)
+ series.age = row['age']
+ series.genre = row['genre']
+ series.grouping = row['grouping']
+ series.code = row['code']
+ series.descr = row['descr']
+ return series
end
end
return nil
end
return book_ids
end
+
+ def query_books_by_series_id(id)
+ sql =
+<<EOS
+ SELECT b.id FROM Books b
+ WHERE b.series = $1
+ ORDER BY b.volume,b.title
+EOS
+ book_ids = []
+ @conn.exec_params(sql, [id]) do |rs|
+ rs.each do |row|
+ book_ids.push(row['id'])
+ end
+ end
+ return book_ids
+ end
+
+ def query_series_by_age(pattern)
+ sql =
+<<EOS
+ SELECT s.id FROM Series s
+ WHERE s.age LIKE $1
+ ORDER BY s.descr
+EOS
+ series_ids = []
+ @conn.exec_params(sql, [pattern]) do |rs|
+ rs.each do |row|
+ series_ids.push(row['id'])
+ end
+ end
+ return series_ids
+ end
end