Navigation.markdown 1.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
{file:docs/Home.markdown} > **{file:docs/Navigation.markdown}**

Traversing
==========

Example to show tree of Table of Contents:

    nav = book.manifest.navs.first.content_document # => EPUB::ContentDocument::Navigation
    toc = nav.toc # => EPUB::ContentDocument::Navigation::Navigation
    toc_tree = ''
    toc.traverse do |item, depth|
12 13
      item # => EPUB::ContentDocument::Navigation::Item
      depth # => Integer
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
      toc_tree << "#{' ' * depth * 2}#{item.text}\n"
    end
    puts toc_tree
    THE CONTENTS
      SECTION IV FAIRY STORIES—MODERN FANTASTIC TALES
        BIBLIOGRAPHY
        INTRODUCTORY
        Abram S. Isaacs
          190 A FOUR-LEAVED CLOVER
            
    												I. The Rabbi and the Diadem
    											
            
    												II. Friendship
    											
            
    												III. True Charity
    											
            
    												IV. An Eastern Garden
    											
        Samuel Taylor Coleridge
          191 THE LORD HELPETH MAN AND BEAST
        Hans Christian Andersen
          192 THE REAL PRINCESS
          193 THE EMPEROR'S NEW CLOTHES
          194 THE NIGHTINGALE
          195 THE FIR TREE
          196 THE TINDER-BOX
          197 THE HARDY TIN SOLDIER
          198 THE UGLY DUCKLING
        Frances Browne
          199 THE STORY OF FAIRYFOOT
        Oscar Wilde
          200 THE HAPPY PRINCE
        Raymond MacDonald Alden
          201 THE KNIGHTS OF THE SILVER SHIELD
        Jean Ingelow
          202 THE PRINCE'S DREAM
        Frank R. Stockton
          203 OLD PIPES AND THE DRYAD
        John Ruskin
          204 THE KING OF THE GOLDEN RIVER OR THE BLACK BROTHERS
57 58

**NOTE**: This API is not stable.