This repository has been archived on 2023-08-07. You can view files and clone it, but cannot push or open issues or pull requests.
temple/lib/mix/tasks/update_mdn_docs.ex
Mitchell Hanberg d210d3bff5 Extract safe result from hidden fields within inputs_for/4
Also switches to using `with` instead of `lexical_scoping` because it is
more idiomatic.
2019-07-07 22:26:32 -04:00

34 lines
871 B
Elixir

defmodule Mix.Tasks.UpdateMdnDocs do
use Mix.Task
@baseurl "https://developer.mozilla.org/en-US/docs/Web/HTML/Element/"
@params "?summary&raw"
@shortdoc "Update the MDN documentation"
def run(_) do
IO.puts("Downloading MDN documentation")
(Temple.Tags.nonvoid_elements() ++ Temple.Tags.void_elements())
|> Enum.map(fn el ->
Task.async(fn ->
el = to_string(el)
page =
if Enum.any?(["h1", "h2", "h3", "h4", "h5", "h6"], &(&1 == el)) do
"Heading_Elements"
else
el
end
{doc, 0} = System.cmd("curl", ["--silent", @baseurl <> page <> @params])
File.mkdir_p!("./tmp/docs/")
path = "./tmp/docs/" <> el <> ".txt"
doc = HtmlSanitizeEx.strip_tags(doc)
File.write!(path, doc)
end)
end)
|> Enum.each(&Task.await/1)
end
end