commit b8c449d9c98ff7cf5bcec96ad3d86eaa3fad58d6 Author: Christoffer Müller Madsen Date: Sun Oct 22 23:38:57 2017 +0200 initial commit, it works diff --git a/index.html.erb b/index.html.erb new file mode 100644 index 0000000..b4c5a20 --- /dev/null +++ b/index.html.erb @@ -0,0 +1,27 @@ + + + + + The Secret Book Lending Site + + + + + + + + + + + <% books.each do |f, b| %> + + + + + + <% end %> +
TitleAuthorLink
<%= b.title.content %><%= b.creator.content %>EPUB
+ + + + diff --git a/index.rb b/index.rb new file mode 100644 index 0000000..eb93c1b --- /dev/null +++ b/index.rb @@ -0,0 +1,39 @@ +require 'gepub' +require 'erb' + +# Parse epubs + +books = Dir["books/*.epub"].map do |f| + [f, GEPUB::Book.parse(File.new f)] +end + +books = books.to_h + + +# Collection of sort_by procs + +author_surname_sort_by = proc { |filename, book| + book.creator.content.split(" ")[-1] +} + +title_sort_by = proc { |filename, book| + book.title.content +} + + +# Sort books by one of the above + +books = books.sort_by &title_sort_by + + +# Generate 'index.html' from template + +bind = binding +bind.local_variable_set(:books, books) + +template = File.read 'index.html.erb' + +result = ERB.new(template).result(bind) +File.open "index.html", "w+" do |f| + f << result +end