Extractly (Extractly v0.4.1) View Source
Provide easy access to information inside the templates rendered by mix xtra
Link to this section Summary
Functions
Emits a comment including a message not to edit the created file, as it will be recreated from this template.
Returns docstring of a function (or nil) Ex
Returns docstring of a macro (or nil)
Returns docstring of a module (or nil) Ex
Returns the output of a mix task Ex
A convenience method to access this libraries version
Link to this section Functions
Emits a comment including a message not to edit the created file, as it will be recreated from this template.
It is a convenience to include this into your templates as follows
<%= xtra.do_not_edit_warning %>
or I18n'ed
<%= xtra.do_not_edit_warning, lang: :fr %>
If you are not generating html or markdown the comment can be parametrized
<%= xtra.do_not_edit_warning, comment_start: "-- ", comment_end: "" %>
If you want to include the name of the source template use template: template
option, so
a call may be as complex as:
<%= xtra.do_not_edit_warning, comment_start: "-- ", comment_end: "", template: template, lang: :it %>
Returns docstring of a function (or nil) Ex:
iex(0)> Extractly.functiondoc("Extractly.moduledoc/2")
...(0)> |> String.split("\n") |> Enum.take(3)
[" Returns docstring of a module (or nil)", " Ex:", ""]
We can also pass a list of functions to get their docs concatenated
iex(1)> out = Extractly.functiondoc(["Extractly.moduledoc/2", "Extactly.functiondoc/2"])
...(1)> String.split(out, "\n") |> Enum.take(5)
[ " Returns docstring of a module (or nil)",
" Ex:",
"",
" Extractly.moduledoc(\"Extractly\")",
""]
If all the functions are in the same module the following form can be used
iex(2)> out = Extractly.functiondoc(["moduledoc/2", "functiondoc/2"], module: "Extractly")
...(2)> String.split(out, "\n") |> hd()
" Returns docstring of a module (or nil)"
However it is convenient to add a markdown headline before each functiondoc, especially in these cases,
it can be done by indicating the headline: level
option
iex(3)> Extractly.functiondoc(["moduledoc/2", "functiondoc/2"], module: "Extractly", headline: 2)
...(3)> |> String.split("\n") |> Enum.take(3)
[ "## Extractly.moduledoc/2",
"",
" Returns docstring of a module (or nil)"]
Often times we are interested by all public functiondocs...
iex(4)> out = Extractly.functiondoc(:all, module: "Extractly", headline: 2)
...(4)> String.split(out, "\n") |> Enum.take(3)
[ "## Extractly.do_not_edit_warning/1",
"",
" Emits a comment including a message not to edit the created file, as it will be recreated from this template."]
We can specify a language to wrap indented code blocks into ```elixir\n...\n```
Here is an example
iex(0)> Extractly.functiondoc("Extractly.functiondoc/2", wrap_code_blocks: "elixir")
...(0)> |> String.split("\n") |> Enum.take(10)
[ " Returns docstring of a function (or nil)",
" Ex:",
"",
"```elixir",
" iex(0)> Extractly.functiondoc(\"Extractly.moduledoc/2\") ",
" ...(0)> |> String.split(\"\\n\") |> Enum.take(3)",
" [\" Returns docstring of a module (or nil)\", \" Ex:\", \"\"]",
"```",
"",
" We can also pass a list of functions to get their docs concatenated"]
Returns docstring of a macro (or nil)
Same naming convention for macros as for functions.
Returns docstring of a module (or nil) Ex:
Extractly.moduledoc("Extractly")
Returns the output of a mix task Ex:
iex(5)> Extractly.task("cmd", ~W[echo 42])
"42\n"
iex(0)> Extractly.task("xxx") |> String.split("\n")|> hd()
"***Error, the following output was produced wih error code 1"
A convenience method to access this libraries version