Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code review #87

Merged
merged 8 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@ updates:
- package-ecosystem: mix
directory: "/"
schedule:
interval: weekly
interval: monthly
time: "11:00"
open-pull-requests-limit: 10
open-pull-requests-limit: 3
reviewers:
- milmazz
assignees:
- milmazz
ignore:
- dependency-name: ex_doc
versions:
- 0.23.0
- 0.24.1
- dependency-name: earmark
versions:
- 1.4.13
- 1.4.14
versions: '>= 0.24'
- dependency-name: credo
versions:
- 1.5.4
versions: '>= 1.6'
- dependency-name: dialyxir
versions: '>= 1.0'
10 changes: 5 additions & 5 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Elixir
uses: erlef/setup-beam@988e02bfe678367a02564f65ca2e37726dc0268f
uses: erlef/setup-beam@v1
with:
elixir-version: '1.12.3' # Define the elixir version [required]
otp-version: '24.1' # Define the OTP version [required]
elixir-version: '1.17' # Define the elixir version [required]
otp-version: '27' # Define the OTP version [required]
- name: Restore dependencies cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
Expand Down
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.13.0-rc.1-otp-24
erlang 24.1.6
elixir 1.17.3-otp-27
erlang 27.1
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ First, add `:bupe` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:bupe, "~> MAJOR.MINOR"}
{:bupe, "~> 0.6"}
]
end
```

To find out the latest release available on Hex, you can run `mix hex.info
bupe` in your shell, or by going to the
To find out the latest release available on Hex, you can run `mix hex.info bupe` in your shell, or by going to the
[`bupe` page on Hex.pm](https://hex.pm/packages/bupe)

Then, update your dependencies:
Expand Down Expand Up @@ -235,7 +234,7 @@ See `BUPE.Parser` for more details.

## Copyright and License

Copyright 2016 Milton Mazzarri
Copyright 2024 Milton Mazzarri

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
44 changes: 28 additions & 16 deletions lib/bupe/builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,8 @@ defmodule BUPE.Builder do
defp transform_assets([]), do: []
defp transform_assets(assets), do: Enum.map(assets, &transform_asset/1)

defp transform_asset(%Item{} = asset) do
Item.normalize(asset)
end

defp transform_asset(asset) when is_binary(asset) do
Item.from_string(asset)
end
defp transform_asset(%Item{} = asset), do: Item.normalize(asset)
defp transform_asset(asset) when is_binary(asset), do: Item.from_string(asset)

# Package definition builder.
#
Expand All @@ -192,7 +187,7 @@ defmodule BUPE.Builder do
defp generate_package(config) do
content = Templates.content_template(config.details)

%{config | files: [{'OEBPS/content.opf', content} | config.files]}
%{config | files: [{~c"OEBPS/content.opf", content} | config.files]}
end

# Navigation Center eXtended definition
Expand All @@ -206,7 +201,7 @@ defmodule BUPE.Builder do
defp generate_ncx(config) do
content = Templates.ncx_template(config.details)

%{config | files: [{'OEBPS/toc.ncx', content} | config.files]}
%{config | files: [{~c"OEBPS/toc.ncx", content} | config.files]}
end

# Navigation Document Definition
Expand All @@ -221,7 +216,7 @@ defmodule BUPE.Builder do
if config.details.version == "3.0" do
content = Templates.nav_template(config.details)

%{config | files: [{'OEBPS/nav.xhtml', content} | config.files]}
%{config | files: [{~c"OEBPS/nav.xhtml", content} | config.files]}
else
config
end
Expand All @@ -231,7 +226,7 @@ defmodule BUPE.Builder do
defp generate_title(config) do
if config.details.cover do
content = Templates.title_template(config.details)
%{config | files: [{'OEBPS/title.xhtml', content} | config.files]}
%{config | files: [{~c"OEBPS/title.xhtml", content} | config.files]}
else
config
end
Expand All @@ -253,11 +248,23 @@ defmodule BUPE.Builder do
end

defp generate_epub(files, name, options) do
opts = [compress: ['.css', '.js', '.html', '.xhtml', '.ncx', '.opf', '.jpg', '.png', '.xml']]
opts = [
compress: [
~c".css",
~c".js",
~c".html",
~c".xhtml",
~c".ncx",
~c".opf",
~c".jpg",
~c".png",
~c".xml"
]
]

opts = if Enum.find(options, &(&1 == :memory)), do: [:memory | opts], else: opts

:zip.create(String.to_charlist(name), [{'mimetype', @mimetype} | files], opts)
:zip.create(String.to_charlist(name), [{~c"mimetype", @mimetype} | files], opts)
end

## Helpers
Expand All @@ -266,9 +273,14 @@ defmodule BUPE.Builder do
Map.put(config, :modified, dt)
end

# credo:disable-for-next-line Credo.Check.Design.TagTODO
# TODO: Check if format is compatible with ISO8601
defp modified_date(config), do: config
defp modified_date(%{modified: modified} = config) when is_binary(modified) do
case DateTime.from_iso8601(modified) do
{:ok, _, 0} -> config
_ -> raise BUPE.InvalidDate
end
end

defp modified_date(_config), do: raise(BUPE.InvalidDate)

defp check_identifier(%{identifier: nil} = config) do
identifier = "urn:uuid:#{Util.uuid4()}"
Expand Down
58 changes: 30 additions & 28 deletions lib/bupe/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,34 @@ defmodule BUPE.Config do
}

@enforce_keys [:title, :pages]
defstruct title: nil,
creator: nil,
contributor: nil,
date: nil,
identifier: nil,
language: "en",
version: "3.0",
unique_identifier: nil,
source: nil,
type: nil,
modified: nil,
description: nil,
format: nil,
coverage: nil,
publisher: nil,
relation: nil,
rights: nil,
subject: nil,
pages: [],
nav: [],
styles: [],
scripts: [],
images: [],
cover: true,
logo: nil,
audio: [],
fonts: [],
toc: []
defstruct [
:title,
:creator,
:contributor,
:date,
:identifier,
:unique_identifier,
:source,
:type,
:modified,
:description,
:format,
:coverage,
:publisher,
:relation,
:rights,
:subject,
:logo,
language: "en",
version: "3.0",
pages: [],
nav: [],
styles: [],
scripts: [],
images: [],
cover: true,
audio: [],
fonts: [],
toc: []
]
end
Loading
Loading