Update Elixir version and deps.
This commit is contained in:
parent
735ee0a8cc
commit
ae82239c34
8 changed files with 95 additions and 45 deletions
3
.formatter.exs
Normal file
3
.formatter.exs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[
|
||||||
|
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
|
||||||
|
]
|
29
.gitlab-ci.yml
Normal file
29
.gitlab-ci.yml
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
image: elixir:latest
|
||||||
|
|
||||||
|
cache:
|
||||||
|
key: "$CI_JOB_NAME"
|
||||||
|
paths:
|
||||||
|
- deps
|
||||||
|
- _build
|
||||||
|
- /root/.mix
|
||||||
|
|
||||||
|
variables:
|
||||||
|
MIX_ENV: "test"
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- mix local.hex --force
|
||||||
|
- mix local.rebar --force
|
||||||
|
- mix deps.get --only test
|
||||||
|
|
||||||
|
test:
|
||||||
|
script:
|
||||||
|
- mix test
|
||||||
|
|
||||||
|
credo:
|
||||||
|
script:
|
||||||
|
- mix credo --strict
|
||||||
|
|
||||||
|
# inch:
|
||||||
|
# script:
|
||||||
|
# - mix inch --pedantic
|
||||||
|
|
|
@ -8,7 +8,7 @@ defimpl Vivid.PNG, for: Vivid.Buffer do
|
||||||
@doc """
|
@doc """
|
||||||
Convert a Vivid buffer into a PNG file.
|
Convert a Vivid buffer into a PNG file.
|
||||||
"""
|
"""
|
||||||
@spec to_png(Buffer.t, Path.t) :: :ok | {:error, any}
|
@spec to_png(Buffer.t(), Path.t()) :: :ok | {:error, any}
|
||||||
def to_png(buffer, path) do
|
def to_png(buffer, path) do
|
||||||
with {:ok, file} <- File.open(path, [:write]),
|
with {:ok, file} <- File.open(path, [:write]),
|
||||||
png <- create_png(buffer, file),
|
png <- create_png(buffer, file),
|
||||||
|
@ -21,21 +21,22 @@ defimpl Vivid.PNG, for: Vivid.Buffer do
|
||||||
%{
|
%{
|
||||||
size: {width, height},
|
size: {width, height},
|
||||||
mode: {:rgba, 8},
|
mode: {:rgba, 8},
|
||||||
file: file,
|
file: file
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp create_png(%Buffer{columns: width} = buffer, file) do
|
defp create_png(%Buffer{columns: width} = buffer, file) do
|
||||||
png = buffer
|
png =
|
||||||
|
buffer
|
||||||
|> config(file)
|
|> config(file)
|
||||||
|> :png.create
|
|> :png.create()
|
||||||
|
|
||||||
buffer
|
buffer
|
||||||
|> Stream.map(&colour_to_binary(&1))
|
|> Stream.map(&colour_to_binary(&1))
|
||||||
|> Stream.chunk(width)
|
|> Stream.chunk(width)
|
||||||
|> Stream.map(&Enum.join(&1))
|
|> Stream.map(&Enum.join(&1))
|
||||||
|> Enum.reverse
|
|> Enum.reverse()
|
||||||
|> Enum.reduce(png, &(:png.append(&2, {:row, &1})))
|
|> Enum.reduce(png, &:png.append(&2, {:row, &1}))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp colour_to_binary(%RGBA{red: r, green: g, blue: b, alpha: a}) do
|
defp colour_to_binary(%RGBA{red: r, green: g, blue: b, alpha: a}) do
|
||||||
|
|
|
@ -8,7 +8,7 @@ defimpl Vivid.PNG, for: Vivid.Frame do
|
||||||
@doc """
|
@doc """
|
||||||
Convert a Vivid frame into a PNG file.
|
Convert a Vivid frame into a PNG file.
|
||||||
"""
|
"""
|
||||||
@spec to_png(Frame.t, Path.t) :: :ok | {:error, any}
|
@spec to_png(Frame.t(), Path.t()) :: :ok | {:error, any}
|
||||||
def to_png(frame, file) do
|
def to_png(frame, file) do
|
||||||
frame
|
frame
|
||||||
|> Frame.buffer(:horizontal)
|
|> Frame.buffer(:horizontal)
|
||||||
|
|
|
@ -1,29 +1,31 @@
|
||||||
defmodule Vivid.PNG.ShapeToPng do
|
defmodule Vivid.PNG.ShapeToPng do
|
||||||
alias Vivid.{PNG, Shape, Bounds, Transform, Frame}
|
alias Vivid.{Bounds, Frame, PNG, Shape, Transform}
|
||||||
|
|
||||||
@moduledoc false
|
@moduledoc false
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec to_png(Shape.t, Path.t) :: :ok | {:error, any}
|
@spec to_png(Shape.t(), Path.t()) :: :ok | {:error, any}
|
||||||
def to_png(shape, file) do
|
def to_png(shape, file) do
|
||||||
bounds = Bounds.bounds(shape)
|
bounds = Bounds.bounds(shape)
|
||||||
width = bounds |> Bounds.width |> round |> Kernel.+(3)
|
width = bounds |> Bounds.width() |> round |> Kernel.+(3)
|
||||||
height = bounds |> Bounds.height |> round |> Kernel.+(3)
|
height = bounds |> Bounds.height() |> round |> Kernel.+(3)
|
||||||
|
|
||||||
frame = Frame.init(width, height)
|
frame = Frame.init(width, height)
|
||||||
|
|
||||||
shape = shape
|
shape =
|
||||||
|
shape
|
||||||
|> Transform.center(frame)
|
|> Transform.center(frame)
|
||||||
|> Transform.apply
|
|> Transform.apply()
|
||||||
|
|
||||||
frame
|
frame
|
||||||
|> Frame.push(shape, RGBA.black)
|
|> Frame.push(shape, RGBA.black())
|
||||||
|> PNG.to_png(file)
|
|> PNG.to_png(file)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Enum.each(~w(Arc Box Circle Group Line Path Polygon), fn mod ->
|
Enum.each(~w(Arc Box Circle Group Line Path Polygon), fn mod ->
|
||||||
mod = Module.concat(Vivid, mod)
|
mod = Module.concat(Vivid, mod)
|
||||||
|
|
||||||
defimpl Vivid.PNG, for: mod do
|
defimpl Vivid.PNG, for: mod do
|
||||||
def to_png(shape, file), do: Vivid.PNG.ShapeToPng.to_png(shape, file)
|
def to_png(shape, file), do: Vivid.PNG.ShapeToPng.to_png(shape, file)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
defprotocol Vivid.PNG do
|
defprotocol Vivid.PNG do
|
||||||
alias Vivid.{Shape, Frame, Buffer}
|
alias Vivid.{Shape, Frame, Buffer}
|
||||||
|
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Turn a Vivid frame or shape into a PNG
|
Turn a Vivid frame or shape into a PNG
|
||||||
"""
|
"""
|
||||||
|
@ -7,6 +8,6 @@ defprotocol Vivid.PNG do
|
||||||
@doc """
|
@doc """
|
||||||
Turn a frame or shape into a PNG file.
|
Turn a frame or shape into a PNG file.
|
||||||
"""
|
"""
|
||||||
@spec to_png(Shape.t | Frame.t | Buffer.t, Path.t) :: :ok | {:error, any}
|
@spec to_png(Shape.t() | Frame.t() | Buffer.t(), Path.t()) :: :ok | {:error, any}
|
||||||
def to_png(shape, file)
|
def to_png(shape, file)
|
||||||
end
|
end
|
||||||
|
|
24
mix.exs
24
mix.exs
|
@ -2,14 +2,16 @@ defmodule Vivid.PNG.Mixfile do
|
||||||
use Mix.Project
|
use Mix.Project
|
||||||
|
|
||||||
def project do
|
def project do
|
||||||
[app: :vivid_png,
|
[
|
||||||
version: "0.1.0",
|
app: :vivid_png,
|
||||||
description: description,
|
version: "0.2.0",
|
||||||
|
description: description(),
|
||||||
elixir: "~> 1.3",
|
elixir: "~> 1.3",
|
||||||
build_embedded: Mix.env == :prod,
|
build_embedded: Mix.env() == :prod,
|
||||||
start_permanent: Mix.env == :prod,
|
start_permanent: Mix.env() == :prod,
|
||||||
package: package,
|
package: package(),
|
||||||
deps: deps()]
|
deps: deps()
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def application do
|
def application do
|
||||||
|
@ -27,7 +29,7 @@ defmodule Vivid.PNG.Mixfile do
|
||||||
maintainers: ["James Harton <james@automat.nz>"],
|
maintainers: ["James Harton <james@automat.nz>"],
|
||||||
licenses: ["MIT"],
|
licenses: ["MIT"],
|
||||||
links: %{
|
links: %{
|
||||||
"Source" => "https://github.com/jamesotron/vivid_png.ex"
|
"Source" => "https://gitlab.com/jimsy/vivid_png.ex"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
@ -35,8 +37,10 @@ defmodule Vivid.PNG.Mixfile do
|
||||||
defp deps do
|
defp deps do
|
||||||
[
|
[
|
||||||
{:ex_doc, ">= 0.0.0", only: :dev},
|
{:ex_doc, ">= 0.0.0", only: :dev},
|
||||||
{:png, "~> 0.1.1"},
|
{:credo, "~> 0.10", only: ~w(dev test)a, runtime: false},
|
||||||
{:vivid, ">= 0.3.0"}
|
{:inch_ex, "~> 1.0", only: ~w(dev test)a, runtime: false},
|
||||||
|
{:png, "~> 0.1"},
|
||||||
|
{:vivid, "~> 0.4"}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
18
mix.lock
18
mix.lock
|
@ -1,4 +1,14 @@
|
||||||
%{"earmark": {:hex, :earmark, "1.0.3", "89bdbaf2aca8bbb5c97d8b3b55c5dd0cff517ecc78d417e87f1d0982e514557b", [:mix], []},
|
%{
|
||||||
"ex_doc": {:hex, :ex_doc, "0.14.5", "c0433c8117e948404d93ca69411dd575ec6be39b47802e81ca8d91017a0cf83c", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
|
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
|
||||||
"png": {:hex, :png, "0.1.1", "57eeab907d4c2b78d4c3803bc355af025248db9ebd612e4275c3cab65b809171", [:rebar], []},
|
"credo": {:hex, :credo, "0.10.0", "66234a95effaf9067edb19fc5d0cd5c6b461ad841baac42467afed96c78e5e9e", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
"vivid": {:hex, :vivid, "0.3.0", "98c6203e6c4f2e791530645529d7a767387a7d949f05be282d06de85b5dec898", [:mix], []}}
|
"earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm"},
|
||||||
|
"ex_doc": {:hex, :ex_doc, "0.19.1", "519bb9c19526ca51d326c060cb1778d4a9056b190086a8c6c115828eaccea6cf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.7", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
|
"inch_ex": {:hex, :inch_ex, "1.0.0", "18496a900ca4b7542a1ff1159e7f8be6c2012b74ca55ac70de5e805f14cdf939", [:mix], [{:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
|
"jason": {:hex, :jason, "1.1.1", "d3ccb840dfb06f2f90a6d335b536dd074db748b3e7f5b11ab61d239506585eb2", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
|
||||||
|
"makeup": {:hex, :makeup, "0.5.1", "966c5c2296da272d42f1de178c1d135e432662eca795d6dc12e5e8787514edf7", [:mix], [{:nimble_parsec, "~> 0.2.2", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
|
"makeup_elixir": {:hex, :makeup_elixir, "0.8.0", "1204a2f5b4f181775a0e456154830524cf2207cf4f9112215c05e0b76e4eca8b", [:mix], [{:makeup, "~> 0.5.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 0.2.2", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
|
||||||
|
"nimble_parsec": {:hex, :nimble_parsec, "0.2.2", "d526b23bdceb04c7ad15b33c57c4526bf5f50aaa70c7c141b4b4624555c68259", [:mix], [], "hexpm"},
|
||||||
|
"png": {:hex, :png, "0.1.1", "57eeab907d4c2b78d4c3803bc355af025248db9ebd612e4275c3cab65b809171", [:rebar], [], "hexpm"},
|
||||||
|
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
|
||||||
|
"vivid": {:hex, :vivid, "0.4.3", "ea0abddb41a1ac778392c05f11c70118a5d36d71f0dee9e4b10bcb757a54f1c2", [:mix], [], "hexpm"},
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue