Skip to content
Browse files

support for custom templates + fixed cover image meta tag

  • Loading branch information...
1 parent 782b537 commit df145bea969d892e61a363191328111183100062 @herval committed Sep 25, 2012
Showing with 21 additions and 9 deletions.
  1. 0 bin/kindlerb
  2. +18 −7 lib/kindlerb.rb
  3. +3 −2 templates/opf.mustache
View
0 bin/kindlerb 100644 → 100755
File mode changed.
View
25 lib/kindlerb.rb
@@ -21,18 +21,29 @@ def shorten(max)
module Kindlerb
- VERSION = '0.0.8'
+ VERSION = '0.0.9'
+
+ # allows overriding the default mustaches with ones specified under the templates folder
+ def self.custom_or_default_template(target_dir, name)
+ custom = File.join(target_dir, "templates", "#{name}.mustache")
+ if File.exist?(custom)
+ puts "Using custom template for #{name}.mustache"
+ File.read(custom)
+ else
+ File.read(File.join(File.dirname(__FILE__), '..', "templates", "#{name}.mustache"))
+ end
+ end
def self.run
target_dir = Pathname.new(ARGV.first || '.')
- opf_template = File.read(File.join(File.dirname(__FILE__), '..', "templates/opf.mustache"))
- ncx_template = File.read(File.join(File.dirname(__FILE__), '..', "templates/ncx.mustache"))
- contents_template = File.read(File.join(File.dirname(__FILE__), '..', "templates/contents.mustache"))
- section_template = File.read(File.join(File.dirname(__FILE__), '..', "templates/section.mustache"))
- masthead_gif = File.join(File.dirname(__FILE__), '..', "templates/masthead.gif")
- cover_gif = File.join(File.dirname(__FILE__), '..', "templates/cover-image.gif")
+ opf_template = custom_or_default_template(target_dir, "opf")
+ ncx_template = custom_or_default_template(target_dir, "ncx")
+ contents_template = custom_or_default_template(target_dir, "contents")
+ section_template = custom_or_default_template(target_dir, "section")
+ # masthead_gif = File.join(File.dirname(__FILE__), '..', "templates/masthead.gif")
+ # cover_gif = File.join(File.dirname(__FILE__), '..', "templates/cover-image.gif")
Dir.chdir target_dir do
playorder = 1
View
5 templates/opf.mustache
@@ -1,10 +1,11 @@
<?xml version='1.0' encoding='utf-8'?>
<package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="{{doc_uuid}}">
<metadata>
+ <meta content="cover-image" name="cover"/>
+
<dc-metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title>{{title}}</dc:title>
<dc:language>en-gb</dc:language>
- <meta content="cover-image" name="cover"/>
<dc:creator>{{author}}</dc:creator>
<dc:publisher>{{publisher}}</dc:publisher>
<dc:subject>{{subject}}</dc:subject>
@@ -21,7 +22,7 @@
<manifest>
<item href="contents.html" media-type="application/xhtml+xml" id="contents"/>
<item href="nav-contents.ncx" media-type="application/x-dtbncx+xml" id="nav-contents"/>
- <item href="{{cover}}" media-type="image/gif" id="cover-image"/>
+ <item href="{{cover}}" media-type="image/jpg" id="cover-image"/>
<item href="{{masthead}}" media-type="image/gif" id="masthead"/>
{{#manifest_items}}
<item href="{{href}}" media-type="{{media}}" id="{{idref}}"/>

0 comments on commit df145be

Please sign in to comment.
Something went wrong with that request. Please try again.