Skip to content

Commit

Permalink
Guide, manifest and spine no longer get passed a reference to opf_xml
Browse files Browse the repository at this point in the history
  • Loading branch information
orangemug committed Jan 18, 2012
1 parent 8cc5b52 commit f80611a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
8 changes: 4 additions & 4 deletions lib/epub/file.rb
Expand Up @@ -107,19 +107,19 @@ def compress!(*filter)
# Part of the OPF
###
def manifest
Manifest.new opf_xml, self
Manifest.new self
end

def metadata
Metadata.new opf_xml, self
Metadata.new self
end

def guide
Guide.new opf_xml, self
Guide.new self
end

def spine
Spine.new opf_xml, self
Spine.new self
end

def toc
Expand Down
17 changes: 11 additions & 6 deletions lib/epub/guide.rb
Expand Up @@ -3,15 +3,20 @@ class Guide
OPF_XPATH = '//xmlns:guide'
OPF_ITEM_XPATH = '//xmlns:reference'

def initialize(rootdoc, epub)
def initialize(epub)
@epub = epub
@xmldoc = rootdoc.xpath(OPF_XPATH)
end


def xmldoc
@epub.opf_xml.xpath(OPF_XPATH)
end


def normalize!
doc = xmldoc
# TODO: Handle this better
return if @xmldoc.size < 1
return if doc.size < 1

items do |node|
href = CGI::unescape(node.attributes['href'].to_s)
Expand All @@ -20,18 +25,18 @@ def normalize!
node['href'] = item.normalized_hashed_path(:relative_to => @epub.opf_path)
end

@epub.save_opf!(@xmldoc, OPF_XPATH)
@epub.save_opf!(doc, OPF_XPATH)
end

def to_s
@xmldoc.to_s
xmldoc.to_s
end

private

# Iterate over each item in the guide
def items
@xmldoc.xpath(OPF_ITEM_XPATH).each do |item|
xmldoc.xpath(OPF_ITEM_XPATH).each do |item|
yield(item)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/epub/manifest.rb
Expand Up @@ -12,7 +12,7 @@ class Manifest
'xmlns' => 'http://www.idpf.org/2007/opf'
}

def initialize(rootdoc, epub)
def initialize(epub)
@epub = epub
reload_xmldoc
end
Expand Down
16 changes: 10 additions & 6 deletions lib/epub/spine.rb
Expand Up @@ -3,9 +3,13 @@ class Spine
OPF_XPATH = '//xmlns:spine'
OPF_ITEM_XPATH = '//xmlns:itemref'

def initialize(rootdoc, epub)
@epub = epub
@xmldoc = rootdoc.xpath(OPF_XPATH).first
def initialize(epub)
@epub = epub
end


def xmldoc
@epub.opf_xml.xpath(OPF_XPATH).first
end


Expand All @@ -28,18 +32,18 @@ def toc


def to_s
@xmldoc.to_s
xmldoc.to_s
end

def toc_manifest_id
toc_manifest_id = @xmldoc.attributes['toc']
toc_manifest_id = xmldoc.attributes['toc']
toc_manifest_id.to_s.strip
end

private

def nodes
@xmldoc.xpath(OPF_ITEM_XPATH).each do |node|
xmldoc.xpath(OPF_ITEM_XPATH).each do |node|
yield(node)
end
end
Expand Down

0 comments on commit f80611a

Please sign in to comment.