Skip to content

Instantly share code, notes, and snippets.

@takahashim
Created March 11, 2012 07:21
Show Gist options
  • Save takahashim/2015412 to your computer and use it in GitHub Desktop.
Save takahashim/2015412 to your computer and use it in GitHub Desktop.
ad hoc patch for gepub
diff --git a/lib/gepub/book.rb b/lib/gepub/book.rb
index eaf2838..56434a1 100644
--- a/lib/gepub/book.rb
+++ b/lib/gepub/book.rb
@@ -242,6 +242,14 @@ module GEPUB
epub.put_next_entry('META-INF/container.xml')
epub << container_xml.force_to_bin
+ ## support com.apple.ibooks.display-options.xml
+ disp_opt_file = "com.apple.ibooks.display-options.xml"
+ if File.exists? disp_opt_file
+ display_options = File.read(disp_opt_file)
+ epub.put_next_entry('META-INF/'+disp_opt_file)
+ epub << display_options.force_to_bin
+ end
+
epub.put_next_entry(@package.path)
epub << opf_xml.force_to_bin
diff --git a/lib/gepub/item.rb b/lib/gepub/item.rb
index e3b8567..6c78c6d 100644
--- a/lib/gepub/item.rb
+++ b/lib/gepub/item.rb
@@ -1,6 +1,7 @@
module GEPUB
class Item
attr_accessor :content
+ attr_accessor :title
def self.create(parent, attributes = {})
Item.new(attributes['id'], attributes['href'], attributes['media-type'], parent,
attributes.reject { |k,v| ['id','href','media-type'].member?(k) })
@@ -15,6 +16,7 @@ module GEPUB
@parent = parent
@parent.register_item(self) unless @parent.nil?
@content_callback = []
+ @title = nil
self
end
@@ -82,6 +84,7 @@ module GEPUB
if videos.size > 0 || audios.size > 0
self.add_property('remote-resources')
end
+ @title = parsed.xpath("//#{prefix}h1").text
end
self
end
book = GEPUB::Book.new
## (略)
book.add_item('img/cover.jpg','img/cover.jpg').cover_image
book.add_item("PinyonScript-Regular.ttf","PinyonScript-Regular.ttf")
book.add_item('main.css','main.css')
## (略)
book.ordered do
book.add_item('_cover.html','_cover.html')
## (略)
book.add_item("0002-hajimeni.html", "book/0002-hajimeni.html").toc_text("はじめに")
book.add_item("nav.html", "nav.html").toc_text("目次")
Dir.glob("#{dir}/???-*.html") do |filename|
item = book.add_item(filename.sub(/#{dir}\//,""),filename)
if item.title
item.toc_text(item.title)
else
raise 'no title'
end
end
## (略)
book.add_item("1002-okuduke.html", "book/1002-okuduke.html").toc_text("奥付")
end
epubname = File.join(File.dirname(__FILE__), 'book.epub')
book.generate_epub(epubname)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment