Class: MagicShelf::EpubGenerator
- Inherits:
-
Object
- Object
- MagicShelf::EpubGenerator
- Defined in:
- lib/magicshelf/epubgenerator.rb
Overview
create a epub file with the file under the current directory
Instance Attribute Summary collapse
-
#book_type ⇒ Object
Returns the value of attribute book_type.
-
#creator ⇒ Object
Returns the value of attribute creator.
-
#creator_en ⇒ Object
Returns the value of attribute creator_en.
-
#identifier_url ⇒ Object
Returns the value of attribute identifier_url.
-
#language ⇒ Object
Returns the value of attribute language.
-
#outputfile ⇒ Object
Returns the value of attribute outputfile.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
Instance Attribute Details
#book_type ⇒ Object
Returns the value of attribute book_type.
11 12 13 |
# File 'lib/magicshelf/epubgenerator.rb', line 11 def book_type @book_type end |
#creator ⇒ Object
Returns the value of attribute creator.
11 12 13 |
# File 'lib/magicshelf/epubgenerator.rb', line 11 def creator @creator end |
#creator_en ⇒ Object
Returns the value of attribute creator_en.
11 12 13 |
# File 'lib/magicshelf/epubgenerator.rb', line 11 def creator_en @creator_en end |
#identifier_url ⇒ Object
Returns the value of attribute identifier_url.
11 12 13 |
# File 'lib/magicshelf/epubgenerator.rb', line 11 def identifier_url @identifier_url end |
#language ⇒ Object
Returns the value of attribute language.
11 12 13 |
# File 'lib/magicshelf/epubgenerator.rb', line 11 def language @language end |
#outputfile ⇒ Object
Returns the value of attribute outputfile.
11 12 13 |
# File 'lib/magicshelf/epubgenerator.rb', line 11 def outputfile @outputfile end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/magicshelf/epubgenerator.rb', line 11 def title @title end |
Instance Method Details
#enter ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/magicshelf/epubgenerator.rb', line 13 def enter() MagicShelf.logger.debug('enter EpubGenerator') # check parameters raise MagicShelf::EpubGeneratorError.new("@title is not set") if @title == nil raise MagicShelf::EpubGeneratorError.new("@outputfile is not set") if @outputfile == nil # default parameters @book_type ||= 'comic' @language ||= 'ja' @identifier_url ||= 'http:/example.jp/bookid_in_url' yield end |
#process ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/magicshelf/epubgenerator.rb', line 26 def process() epubname = @outputfile book = GEPUB::Book.new book.unique_identifier @identifier_url book.identifier @identifier_url book.language = @language book.add_title(@title, nil, GEPUB::TITLE_TYPE::MAIN) { |title| title.lang = @language title.file_as = Shellwords.escape(@title) title.display_seq = 1 } if @creator book.add_creator(@creator) { |creator| creator.display_seq = 1 creator.add_alternates('en' => @creator_en) if @creator_en } end if @book_type == "comic" book.page_progression_direction = 'rtl' = book.instance_eval{@package}.instance_eval{@metadata} = .('meta', '') ['name'] = 'book-type' ['content'] = 'comic' = .('meta', '') ['name'] = 'fixed-layout' ['content'] = 'true' elsif @book_type == "novelimage" book.page_progression_direction = 'rtl' = book.instance_eval{@package}.instance_eval{@metadata} = .('meta', '') ['name'] = 'fixed-layout' ['content'] = 'true' elsif @book_type == "novel" book.page_progression_direction = 'rtl' #nothing to do elsif @book_type == "ltr" book.page_progression_direction = 'ltr' end # within ordered block, add_item will be added to spine. book.ordered { # to add nav file: #navpath = 'nav.xhtml' #book.add_item(navpath).add_content(File.open(navpath)).add_property('nav') Naturally.sort(Dir.glob('**/*.{jpg,png}')).each_with_index do |filepath,index| MagicShelf.logger.info("append image #{filepath}, index: #{index}") item = book.add_item(filepath) item.add_content(File.open(filepath)).toc_text(index.to_s) item.cover_image if index == 0 end } book.generate_epub(epubname) end |