Code Monkey home page Code Monkey logo

epub's Introduction

Epub Builder

Convert html text, and images into Epub files, that can be viewed on most modern operating systems, and uploaded to amazon kindle devices.

In Rails

Add this to your gem file

gem 'epub'

Usage

All actions on the epub should be done inside an open block, much like the use of File

Attributes (and defaults)

  • author_name = ''
  • isbn = '000-0-000000-0'
  • book_title = ''
  • publisher = ''
  • publication_date = Time.now.to_s
  • table_of_contents_title = 'Table Of Contents'
  • cover_file_name = ''
  • styles = ''
  • subject_classification = 'NON000000 NON-CLASSIFIABLE'
  • other_data = ''
    • Other data is something I've added, should there come a time you'd want to reverse the process. I've personally used the data to import an exported epub.
    • This data gets persisted in a file name 'other_data' in the META-INF folder.

Methods

  • Start the block
    Epub::Builder.open(file_name) { |service| ... }

  • Find the path of the produced file
    service.path

  • Add A Chapter
    service.add_chapter(id, title, text)

  • Add An Image
    All images that you use in your html based chapters, or as the cover page, get added through this method.
    The order added is not important

    service.add_image(intenal_file_name, source_file_name)

Non Chapter Magic

  • Why? Apple treat some "node" ids in a special way. It's an ever changing way. It's courage that they don't tell devs.
  • The List Of Options
    • index
    • glossary
    • acknowledgements
    • bibliography
    • colophon
    • copyright-page
    • dedication
    • epigraph
    • foreword
    • notes
    • preface
    • loi # List of images
    • lot # List of tables

EXAMPLES

  • Create a simple 1 chapter epub, with no cover

      Dir.chdir(Dir.tmpdir) do
        Epub::Builder.open('1_chapter.epub') do |service|
          service.author_name = "David Rawk"
          service.book_title = "Dave's Grand Tour"
          service.add_chapter('chap_1', "Chapter 1", "<h2>Hello</h2>From <b>the</b> <i>over<s>world</s></i>.")
        end
      end
    
  • Create a simple 2 chapter Epub with a cover image, some 'other_data' and an extended style

      Dir.chdir(Dir.tmpdir) do
        Epub::Builder.open('1_chapter.epub') do |service|
          service.author_name = "David Rawk"
          service.book_title = "I Love Puppies"
          service.add_chapter('chap_1', "Chapter 1", "Puppies are the best!")
          service.add_chapter('chap_2', "Chapter 2", "They all need love")
    
          # Add a cover image
          service.add_image('puppers.png', 'epub/lib/epub/puppers.png')
          service.cover_file_name = 'puppers.png'
    
          # Add "other_data" to the epub
          service.other_data = {user_id: 123, user_status: :awesome }.to_json
    
          # Extend the style a bit.
          service.style = "h2{color: red;}"
          service.style << "h2{background-color: blue;}"
        end
      end
    

epub's People

Watchers

BAASH_05 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.