Sha256: 7932a2d7b4468f2290c1cfea72f9dfacfcf5bcfa41a1d86b2db743404be9b1e4

Contents?: true

Size: 1.93 KB

Versions: 25

Compression:

Stored size: 1.93 KB

Contents

module EeePub
  class NCX < ContainerItem
    attr_accessor :uid,
                  :depth,
                  :total_page_count,
                  :max_page_number,
                  :doc_title,
                  :nav_map

    attr_alias :title, :doc_title
    attr_alias :nav, :nav_map

    default_value :depth, 1
    default_value :total_page_count, 0
    default_value :max_page_number, 0
    default_value :doc_title, 'Untitled'

    def build_xml(builder)
      builder.declare! :DOCTYPE, :ncx, :PUBLIC, "-//NISO//DTD ncx 2005-1//EN", "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd"
      builder.ncx :xmlns => "http://www.daisy.org/z3986/2005/ncx/", :version => "2005-1" do
        build_head(builder)
        builder.docTitle { builder.text doc_title }
        build_nav_map(builder)
      end
    end

    def build_head(builder)
      builder.head do
        {
          :uid => uid,
          :depth => depth,
          :totalPageCount => total_page_count,
          :maxPageNumber => max_page_number
        }.each do |k, v|
          builder.meta :name => "dtb:#{k}", :content => v
        end
      end
    end

    def build_nav_map(builder)
      builder.navMap do
        builder_nav_point(builder, nav_map)
      end
    end

    def builder_nav_point(builder, nav_point, play_order = 1)
      case nav_point
      when Array
        nav_point.each do |point|
          play_order = builder_nav_point(builder, point, play_order)
        end
      when Hash
        id = nav_point[:id] || "navPoint-#{play_order}"
        builder.navPoint :id => id, :playOrder => play_order do
          builder.navLabel { builder.text nav_point[:label] }
          builder.content :src => nav_point[:content]
          play_order += 1
          if nav_point[:nav]
            play_order = builder_nav_point(builder, nav_point[:nav], play_order)
          end
        end
      else
        raise "nav_point must be Array or Hash"
      end
      play_order
    end
  end
end

Version data entries

25 entries across 25 versions & 6 rubygems

Version Path
eeepub_ext-0.8.4 lib/eeepub/ncx.rb
eeepub_ext-0.8.3 lib/eeepub/ncx.rb
eeepub_ext-0.8.2 lib/eeepub/ncx.rb
eeepub-with-cover-support-0.8.8 lib/eeepub/ncx.rb
eeepub-0.8.1 lib/eeepub/ncx.rb
eeepub-with-cover-support-0.8.7 lib/eeepub/ncx.rb
eeepub-with-cover-support-0.8.6 lib/eeepub/ncx.rb
eeepub-0.8.0 lib/eeepub/ncx.rb
eeepub-0.7.1 lib/eeepub/ncx.rb
eeepub-0.7.0 lib/eeepub/ncx.rb
walterdavis-eeepub-0.6.3 lib/eeepub/ncx.rb
walterdavis-eeepub-0.6.2 lib/eeepub/ncx.rb
sudothinker-eeepub-0.6.1 lib/eeepub/ncx.rb
lyrics-ebook-0.1 lib/eeepub/lib/eeepub/ncx.rb
eeepub-0.6.1 lib/eeepub/ncx.rb
eeepub-0.6.0 lib/eeepub/ncx.rb
eeepub-0.5.1 lib/eeepub/ncx.rb
eeepub-0.5.0 lib/eeepub/ncx.rb
eeepub-0.4.2 lib/eeepub/ncx.rb
eeepub-0.4.1 lib/eeepub/ncx.rb