View Source BUPE.Builder (BUPE v0.6.1)

Elixir EPUB generator

Example

iex(1)> files = "~/book/*.xhtml" |> Path.expand() |> Path.wildcard()
["/Users/dev/book/bacon.xhtml", "/Users/dev/book/egg.xhtml", "/Users/dev/book/ham.xhtml"]
iex(2)> get_id = fn file -> Path.basename(file, ".xhtml") end
#Function<6.99386804/1 in :erl_eval.expr/5>
iex(3)> pages = Enum.map(files, fn file ->
...(3)>   %BUPE.Item{href: file, id: get_id.(file), description: file |> get_id.() |> String.capitalize()}
...(3)> end)
[
  %BUPE.Item{
    description: "Bacon",
    duration: nil,
    fallback: nil,
    href: "/Users/dev/book/bacon.xhtml",
    id: "bacon",
    media_overlay: nil,
    media_type: nil,
    properties: nil
  },
  %BUPE.Item{
    description: "Egg",
    duration: nil,
    fallback: nil,
    href: "/Users/dev/book/egg.xhtml",
    id: "egg",
    media_overlay: nil,
    media_type: nil,
    properties: nil
  },
  %BUPE.Item{
    description: "Ham",
    duration: nil,
    fallback: nil,
    href: "/Users/dev/book/ham.xhtml",
    id: "ham",
    media_overlay: nil,
    media_type: nil,
    properties: nil
  }
]
iex(4)> config = %BUPE.Config{
...(4)>  title: "Sample",
...(4)>  language: "en",
...(4)>  creator: "John Doe",
...(4)>  publisher: "Sample",
...(4)>  date: "2016-06-23T06:00:00Z",
...(4)>  unique_identifier: "EXAMPLE",
...(4)>  identifier: "http://example.com/book/jdoe/1",
...(4)>  pages: pages
...(4)> }
%BUPE.Config{
  audio: [],
  contributor: nil,
  cover: true,
  coverage: nil,
  creator: "John Doe",
  date: "2016-06-23T06:00:00Z",
  description: nil,
  fonts: [],
  format: nil,
  identifier: "http://example.com/book/jdoe/1",
  images: [],
  language: "en",
  logo: nil,
  modified: nil,
  nav: [],
  pages: [
    %BUPE.Item{
      description: "Bacon",
      duration: nil,
      fallback: nil,
      href: "/Users/dev/book/bacon.xhtml",
      id: "bacon",
      media_overlay: nil,
      media_type: nil,
      properties: nil
    },
    %BUPE.Item{
      description: "Egg",
      duration: nil,
      fallback: nil,
      href: "/Users/dev/book/egg.xhtml",
      id: "egg",
      media_overlay: nil,
      media_type: nil,
      properties: nil
    },
    %BUPE.Item{
      description: "Ham",
      duration: nil,
      fallback: nil,
      href: "/Users/dev/book/ham.xhtml",
      id: "ham",
      media_overlay: nil,
      media_type: nil,
      properties: nil
    }
  ],
  publisher: "Sample",
  relation: nil,
  rights: nil,
  scripts: [],
  source: nil,
  styles: [],
  subject: nil,
  title: "Sample",
  type: nil,
  unique_identifier: "EXAMPLE",
  version: "3.0"
}
iex(6)> BUPE.Builder.run(config, "example.epub")
{:ok, '/Users/dev/example.epub'}

Summary

Functions

Generates an EPUB v3 document

Functions

Link to this function

run(config, name, options \\ [])

View Source
@spec run(BUPE.Config.t(), Path.t(), Keyword.t()) ::
  {:ok, String.t()} | {:error, String.t()}

Generates an EPUB v3 document