Module: EPUB
Instance Method Summary collapse
-
#gen_nav_file(html_file, sections, options = {}) ⇒ Object
生成EPUB3导航文件.
- #gen_nav_file_content(html_file, sections, options = {}) ⇒ Object
-
#write_epub(epub_file, options = {}) ⇒ Object
write_epub parameters:
epub_file
指定生成的epub文件options
可选参数 :files 指定打包到epub中的文件集合 :title epub标题 :author epub作者.
Methods included from Utils
#breaklines, #clean_text, #detect_sections_from_html, #detect_utf8, #end_mark?, #escape_html, #extract_keywords_from_path, #extract_text_from_file, #fixed_page_break, #guess_content_line_length, #line_closed?, #make_destination_dir, #merge_para_part, #scan_file_from_dir, #source_exists?, #text_similarity, #text_to_array, #timer, #to_utf8, #walk_dir, #wrapper_html, #write_file
Instance Method Details
#gen_nav_file(html_file, sections, options = {}) ⇒ Object
生成EPUB3导航文件
42 43 44 45 46 47 48 |
# File 'lib/epub.rb', line 42 def gen_nav_file(html_file,sections,={}) temp_dir = [:dir] || File.dirname(html_file) nav_html = File.join(temp_dir,'nav.html') html_content = gen_nav_file_content(html_file,sections,={}) Utils.write_file(html_content,nav_html) nav_html end |
#gen_nav_file_content(html_file, sections, options = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/epub.rb', line 50 def gen_nav_file_content(html_file,sections,={}) opts = {:title => 'Table Of Contents'}.merge() html_content =<<-EOS <?xml version="1.0" encoding="utf-8"?> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"> <head> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"/> </head> <body> <nav epub:type="toc" id="toc"> <h1>#{opts[:title]}</h1> <ol> #{gen_nav_items("",html_file,sections)} </ol> </nav> </body> </html> EOS html_content end |
#write_epub(epub_file, options = {}) ⇒ Object
write_epub parameters:
+epub_file+ 指定生成的epub文件
+options+ 可选参数
:files 指定打包到epub中的文件集合
:title epub标题
:author epub作者
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/epub.rb', line 16 def write_epub(epub_file,={}) files = [:files] || [] nav,files = extract_nav_from_files(files) book = GEPUB::Book.new book.set_main_id UUID.generate, {} book.add_title [:title] book.version = '3.0' book.instance_variable_get('@package').epub_backward_compat = false book.add_creator [:author] book.publisher='www.nonobo.com' book.add_item(File.basename(nav),nav,'nav').add_property('nav') files.each do |file| if File.extname(file) == '.html' || File.extname(file) == ".htm" book.ordered{ book.add_item(File.basename(file),file) } else book.add_item(File.basename(file),file) end end Utils.make_destination_dir(epub_file) book.generate_epub(epub_file) end |