Refactors navigation page generation. Adds navigation by Series.
[quanlib.git] / walkdir.rb
index df73e4e9f393b0f9b9cf956bb50b0e87601fbb11..1dadd2e35b95974f81ad43366698c46b93dac7b9 100644 (file)
 # .../DorothyGilman/P06_On_the_China_Station.epub.
 
 require 'book'
+require 'store'
 
 class WalkDir
-  def initialize(root)
+  def initialize(store, root)
     @root = root
+    @store = store
     @files = walk(@root)
   end
 
   def books
     result = []
-    for file in @files
+    for file in @files.sort
       if Book.canHandle?(file)
-        book = Book.new(file)
-        result.push(book)
+        book = Book.new(@store)
+        book.loadFromFile(file)
+        id = @store.store_book(book)
+        result.push(id)
       end
     end
     return result
@@ -42,7 +46,7 @@ class WalkDir
     children = Dir.entries(path)
     for child in children
       fullName = (path.chomp("/")) + "/" + child
-      if (File.directory?(fullName)) and (child != ".") and (child != "..")
+      if (File.directory?(fullName)) and (child != ".") and (child != "..") and (!File.symlink?(fullName))
         sub = walk(fullName)
         if (sub != nil) and (sub.length > 0)
           result.concat(sub)
@@ -51,6 +55,7 @@ class WalkDir
         result.push(fullName)
       end
     end
+    #puts result
     return result
   end
 end