Current section
5 Versions
Jump to
Current section
5 Versions
Compare versions
6
files changed
+41
additions
-54
deletions
| @@ -150,7 +150,7 @@ and the following to the layout | |
| 150 150 | you can cleanup old webp assets by invoking |
| 151 151 | |
| 152 152 | ```elixir |
| 153 | - mix webp.delete |
| 153 | + mix webp.clean |
| 154 154 | ``` |
| 155 155 | ## Acknowledgements |
| @@ -1,29 +1,29 @@ | |
| 1 | - {<<"app">>,<<"webp">>}. |
| 2 | - {<<"build_tools">>,[<<"mix">>]}. |
| 1 | + {<<"links">>,[{<<"GitHub">>,<<"https://github.com/mithereal/ex_webp">>}]}. |
| 2 | + {<<"name">>,<<"webp">>}. |
| 3 | + {<<"version">>,<<"1.1.1">>}. |
| 3 4 | {<<"description">>, |
| 4 5 | <<"Mix tasks and library for converting jpeg, png, etc images to webp">>}. |
| 5 6 | {<<"elixir">>,<<"~> 1.13">>}. |
| 7 | + {<<"app">>,<<"webp">>}. |
| 6 8 | {<<"files">>, |
| 7 9 | [<<"lib">>,<<"lib/tasks">>,<<"lib/tasks/webp.clean.ex">>, |
| 8 10 | <<"lib/tasks/webp.ex">>,<<"lib/priv">>,<<"lib/priv/webp.bash">>, |
| 9 11 | <<"lib/compresser.ex">>,<<"lib/webp.ex">>,<<"mix.exs">>,<<"README.md">>]}. |
| 10 12 | {<<"licenses">>,[<<"MIT">>]}. |
| 11 | - {<<"links">>,[{<<"GitHub">>,<<"https://github.com/mithereal/ex_webp">>}]}. |
| 12 | - {<<"name">>,<<"webp">>}. |
| 13 13 | {<<"requirements">>, |
| 14 | - [[{<<"app">>,<<"eimp">>}, |
| 15 | - {<<"name">>,<<"eimp">>}, |
| 14 | + [[{<<"name">>,<<"eimp">>}, |
| 15 | + {<<"app">>,<<"eimp">>}, |
| 16 | + {<<"optional">>,true}, |
| 17 | + {<<"requirement">>,<<"~> 1.0">>}, |
| 18 | + {<<"repository">>,<<"hexpm">>}], |
| 19 | + [{<<"name">>,<<"phoenix">>}, |
| 20 | + {<<"app">>,<<"phoenix">>}, |
| 16 21 | {<<"optional">>,false}, |
| 17 | - {<<"repository">>,<<"hexpm">>}, |
| 18 | - {<<"requirement">>,<<"~> 1.0">>}], |
| 19 | - [{<<"app">>,<<"phoenix">>}, |
| 20 | - {<<"name">>,<<"phoenix">>}, |
| 22 | + {<<"requirement">>,<<">= 0.0.0">>}, |
| 23 | + {<<"repository">>,<<"hexpm">>}], |
| 24 | + [{<<"name">>,<<"jason">>}, |
| 25 | + {<<"app">>,<<"jason">>}, |
| 21 26 | {<<"optional">>,false}, |
| 22 | - {<<"repository">>,<<"hexpm">>}, |
| 23 | - {<<"requirement">>,<<">= 0.0.0">>}], |
| 24 | - [{<<"app">>,<<"jason">>}, |
| 25 | - {<<"name">>,<<"jason">>}, |
| 26 | - {<<"optional">>,false}, |
| 27 | - {<<"repository">>,<<"hexpm">>}, |
| 28 | - {<<"requirement">>,<<"~> 1.0">>}]]}. |
| 29 | - {<<"version">>,<<"1.1.0">>}. |
| 27 | + {<<"requirement">>,<<"~> 1.0">>}, |
| 28 | + {<<"repository">>,<<"hexpm">>}]]}. |
| 29 | + {<<"build_tools">>,[<<"mix">>]}. |
| @@ -14,14 +14,7 @@ defmodule Webp.Compressor do | |
| 14 14 | case valid_extension do |
| 15 15 | true -> |
| 16 16 | compressed_content = |
| 17 | - if :eimp.is_supported(:webp) do |
| 18 | - convert(content, :webp) |
| 19 | - else |
| 20 | - location = Application.get_env(:webp, :destination) |
| 21 | - params = %{location: location} |
| 22 | - Webp.convert(file_path, params) |
| 23 | - :error |
| 24 | - end |
| 17 | + convert(content, :webp, file_path) |
| 25 18 | |
| 26 19 | case compressed_content do |
| 27 20 | {:ok, data} -> |
| @@ -40,16 +33,15 @@ defmodule Webp.Compressor do | |
| 40 33 | [".webp"] |
| 41 34 | end |
| 42 35 | |
| 43 | - defp convert(content, options) do |
| 36 | + defp convert(content, options, file_path) do |
| 44 37 | cond do |
| 45 38 | Code.ensure_loaded?(:eimp) and function_exported?(:eimp, :convert, 2) -> |
| 46 39 | :eimp.convert(content, options) |
| 47 40 | |
| 48 41 | false -> |
| 49 | - if Mix.env() in [:dev, :test] do |
| 50 | - Logger.error(":eimp Not Found") |
| 51 | - end |
| 52 | - |
| 42 | + location = Application.get_env(:webp, :destination) |
| 43 | + params = %{location: location} |
| 44 | + Webp.convert(file_path, params) |
| 53 45 | :error |
| 54 46 | end |
| 55 47 | end |
| @@ -24,15 +24,14 @@ defmodule Mix.Tasks.Webp.Clean do | |
| 24 24 | Application.get_env(:webp, :location, default_path) |
| 25 25 | end |
| 26 26 | |
| 27 | - images_path = images_path <> "/*webp" |
| 28 | - System.cmd("rm", [images_path], []) |
| 29 | - end |
| 27 | + opts = [ |
| 28 | + cd: images_path || File.cwd!(), |
| 29 | + env: %{}, |
| 30 | + into: IO.stream(:stdio, :line), |
| 31 | + stderr_to_stdout: true |
| 32 | + ] |
| 30 33 | |
| 31 | - def run(path, opts) do |
| 32 | - default_phx_path = Path.expand("../#{path}", __DIR__) |
| 33 | - images_path = Application.get_env(:webp, :location, default_phx_path) |
| 34 | - |
| 35 | - glob = "#{images_path}/*.webp" |
| 36 | - System.cmd("rm", [glob], opts) |
| 34 | + images_path = "*.webp" |
| 35 | + System.cmd("rm", [images_path], opts) |
| 37 36 | end |
| 38 37 | end |
| @@ -59,10 +59,6 @@ defmodule Webp do | |
| 59 59 | Path.join(:code.priv_dir(:webp), "webp.bash") |
| 60 60 | end |
| 61 61 | |
| 62 | - defp cmd(path, args) do |
| 63 | - cmd(path, args, []) |
| 64 | - end |
| 65 | - |
| 66 62 | defp cmd(command, args, opts) do |
| 67 63 | System.cmd(command, args, opts) |
| 68 64 | end |
| @@ -97,7 +93,7 @@ defmodule Webp do | |
| 97 93 | files = Path.wildcard(glob) |
| 98 94 | |
| 99 95 | for source <- files do |
| 100 | - path = Application.get_env(:webp, :path, "/usr/bin/cwebp") |
| 96 | + path = bin_path() |
| 101 97 | |
| 102 98 | valid_extension = |
| 103 99 | Path.extname(source) in Application.get_env(:webp, :image_extensions, [ |
| @@ -139,11 +135,7 @@ defmodule Webp do | |
| 139 135 | The executable may not be available if it was not yet installed. |
| 140 136 | """ |
| 141 137 | def bin_path do |
| 142 | - Application.get_env(:cwebp, :path) |
| 143 | - end |
| 144 | - |
| 145 | - defp path_exists?(path) do |
| 146 | - Enum.all?(path, &File.exists?/1) |
| 138 | + Application.get_env(:webp, :path, "/usr/bin/cwebp") |
| 147 139 | end |
| 148 140 | |
| 149 141 | @doc """ |
| @@ -158,7 +150,11 @@ defmodule Webp do | |
| 158 150 | stderr_to_stdout: true |
| 159 151 | ] |
| 160 152 | |
| 161 | - path = Application.get_env(:webp, :path, "/usr/bin/cwebp") |
| 153 | + path = bin_path() |
| 154 | + |
| 155 | + unless File.exists?(path) do |
| 156 | + raise "#{} Not Found please set path to the cwebp location" |
| 157 | + end |
| 162 158 | |
| 163 159 | valid_extension = |
| 164 160 | Path.extname(source) in Application.get_env(:webp, :image_extensions, [ |
Loading more files…