BUPE v0.4.0 BUPE.Builder View Source

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)>   %{href: file, id: get_id.(file), description: file |> get_id.() |> String.capitalize()}
...(3)> end)
[
  %{
    description: "Bacon",
    href: "/Users/dev/book/bacon.xhtml",
    id: "bacon"
  },
  %{
    description: "Egg",
    href: "/Users/dev/book/egg.xhtml",
    id: "egg"
  },
  %{
    description: "Ham",
    href: "/Users/dev/book/ham.xhtml",
    id: "ham"
  }
]
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: nil,
  pages: [
    %{
      description: "Bacon",
      href: "/Users/dev/book/bacon.xhtml",
      id: "bacon"
    },
    %{
      description: "Egg",
      href: "/Users/dev/book/egg.xhtml",
      id: "egg"
    },
    %{
      description: "Ham"
      href: "/Users/dev/book/ham.xhtml",
      id: "ham"
    }
  ],
  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'}

Link to this section Summary

Functions

Generates an EPUB v3 document

Link to this section Functions

Link to this function

run(config, name, options \\ []) View Source
run(BUPE.Config.t(), Path.t(), Keyword.t()) ::
  {:ok, String.t()} | {:error, String.t()}

Generates an EPUB v3 document