From fb4b565926e8805ed763c986cf3e956bcf9414e4 Mon Sep 17 00:00:00 2001 From: Gioele Barabucci Date: Sat, 30 Mar 2013 03:40:34 +0100 Subject: [PATCH 1/2] Simplify ID generation --- lib/eeepub/opf.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/eeepub/opf.rb b/lib/eeepub/opf.rb index 237ad45..ea02885 100644 --- a/lib/eeepub/opf.rb +++ b/lib/eeepub/opf.rb @@ -137,14 +137,12 @@ def complete_manifest def create_unique_item_id(filename, id_cache) basename = File.basename(filename) - unless id_cache[basename] - id_cache[basename] = 0 - name = basename - else - name = "#{basename}-#{id_cache[basename]}" - end + id_cache[basename] ||= 0 + name = "#{basename}-#{id_cache[basename]}" + id_cache[basename] += 1 - name + + return name end end end From 0bc113f212e5d975e9686eb0fb2e141d6ac82fc4 Mon Sep 17 00:00:00 2001 From: Gioele Barabucci Date: Sat, 30 Mar 2013 03:49:29 +0100 Subject: [PATCH 2/2] Make sure that generated IDs are XML-compatible --- lib/eeepub/opf.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/eeepub/opf.rb b/lib/eeepub/opf.rb index ea02885..3beb00a 100644 --- a/lib/eeepub/opf.rb +++ b/lib/eeepub/opf.rb @@ -138,7 +138,7 @@ def complete_manifest def create_unique_item_id(filename, id_cache) basename = File.basename(filename) id_cache[basename] ||= 0 - name = "#{basename}-#{id_cache[basename]}" + name = "id-#{basename}-#{id_cache[basename]}".gsub(/[^a-zA-Z0-9\-.]/, '-') id_cache[basename] += 1