diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index e07c5a8..7465856 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,4 +13,5 @@ //= require jquery //= require jquery_ujs //= require turbolinks +//= require bootstrap-sprockets //= require_tree . diff --git a/app/assets/javascripts/data.coffee b/app/assets/javascripts/data.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/data.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/data.scss b/app/assets/stylesheets/data.scss new file mode 100644 index 0000000..36909b2 --- /dev/null +++ b/app/assets/stylesheets/data.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the data controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 6a4cb72..888f9c9 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -1,5 +1,6 @@ class BooksController < ApplicationController include PreferencesHelper + include ERB::Util before_action :preferences, only: :index @@ -18,4 +19,9 @@ class BooksController < ApplicationController end end + def cover + @book = Book.find(params[:id]) + redirect_to "/calibre/#{url_encode(@book.path)}/cover.jpg" + end + end diff --git a/app/controllers/data_controller.rb b/app/controllers/data_controller.rb new file mode 100644 index 0000000..74de2d6 --- /dev/null +++ b/app/controllers/data_controller.rb @@ -0,0 +1,9 @@ +class DataController < ApplicationController + include ERB::Util + + def show + d = BookDataLink.find_by(book: params[:id], format: params[:data_format]) + redirect_to "/calibre/#{url_encode(d.book.path)}/#{url_encode(d.name)}.#{d.format.downcase}" + end + +end diff --git a/app/helpers/data_helper.rb b/app/helpers/data_helper.rb new file mode 100644 index 0000000..e68f25e --- /dev/null +++ b/app/helpers/data_helper.rb @@ -0,0 +1,2 @@ +module DataHelper +end diff --git a/app/models/book.rb b/app/models/book.rb index d6868ea..7130beb 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -20,6 +20,8 @@ class Book < ActiveRecord::Base has_one :book_serie_link, foreign_key: "book" has_one :serie, through: :book_serie_link + has_many :data, class_name: "BookDataLink", foreign_key: "book" + def has_cover? has_cover == 1 end diff --git a/app/models/book_data_link.rb b/app/models/book_data_link.rb new file mode 100644 index 0000000..a32c94f --- /dev/null +++ b/app/models/book_data_link.rb @@ -0,0 +1,7 @@ +class BookDataLink < ActiveRecord::Base + establish_connection Rails.configuration.database_configuration["calibre"] + + self.table_name = "data" + + belongs_to :book, foreign_key: "book" +end diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb index be4b63f..45e24cc 100644 --- a/app/views/books/show.html.erb +++ b/app/views/books/show.html.erb @@ -1,8 +1,13 @@