Add hyphenation and a generalized render_public_content function
This commit is contained in:
31
lib/outlook/hyphenation.ex
Normal file
31
lib/outlook/hyphenation.ex
Normal file
@ -0,0 +1,31 @@
|
||||
defmodule Outlook.Hyphenation do
|
||||
|
||||
def hyphenate(html, lang) do
|
||||
form = get_multipart_form(
|
||||
[
|
||||
{"api-token", System.get_env("HYPH_API_TOKEN")},
|
||||
{"hyph[lang]", String.downcase(lang)},
|
||||
{"hyph[text]", html},
|
||||
]
|
||||
)
|
||||
|
||||
response_raw = HTTPoison.request!(
|
||||
:post,
|
||||
System.get_env("HYPH_URL"),
|
||||
form,
|
||||
get_multipart_headers()
|
||||
)
|
||||
response_raw.body
|
||||
end
|
||||
|
||||
defp get_multipart_form fields do
|
||||
{:multipart, fields}
|
||||
end
|
||||
|
||||
defp get_multipart_headers() do
|
||||
[
|
||||
"Content-Type": "multipart/form-data",
|
||||
"Transfer-Encoding": "chunked",
|
||||
]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user