View Source SayCheezEx.Graphs.Provider behaviour (say_cheez_ex v0.3.5)

The interface for a graph provider.

  • checks if a such a provider is available, given the providers' own configuration
  • renders a graph to some HTML that can be embedded

Link to this section Summary

Functions

Checks whether we have a file in our cache.

Generates a file name for a tuple (module, recipe).

We want to simplify the SVG that Graphviz generates so we can embed it in our HTML.

Formats the error message, if any.

Creates a file name for a temporary file.

Given a recipe recipe for a graph, first tries a cache and then call a "builder" function to create it.

Runs an external command.

Computes a printable SHA for a string.

The only significant advantage of this HTTP client is that it only uses things that are in Erlang itself.

Earmark says that "A HTML Block defined by a tag starting a line and the same tag starting a different line is parsed as one HTML AST node, marked with %{verbatim: true}" (see https://hexdocs.pm/earmark_parser/EarmarkParser.html )

Write a file to its right cache.

Link to this section Callbacks

@callback render(String.t()) :: {:ok, String.t()} | {:error, String.t()}
@callback render!(String.t()) :: String.t()

Link to this section Functions

Checks whether we have a file in our cache.

If we do, we return its contents.

Link to this function

cached_filename(module, recipe)

View Source

Generates a file name for a tuple (module, recipe).

We want to simplify the SVG that Graphviz generates so we can embed it in our HTML.

Formats the error message, if any.

@spec file(:cache | :temp, binary(), binary()) :: binary()

Creates a file name for a temporary file.

Ths may be a cache file or a proper temporary file.

If you need mode than one file, you should encode it in the extensions.

Link to this function

rebuild_if_needed(module, recipe, fnBuilder)

View Source

Given a recipe recipe for a graph, first tries a cache and then call a "builder" function to create it.

So if the SVG was already generated, we load it from disk - if not, we build it again.

builder

Builder

It returns {:ok, svg_text} or {:error, reason} that will be used to display a result.

Link to this function

run_cmd(cmd, parameters)

View Source

Runs an external command.

It returns a binary that captures STDOUT+STDERR if all went well, or a tuple {:error, e} if something went bonkers.

If it's trying to call a command that does not exist on your local environment, returns {:error, :cmd_not_found}.

Computes a printable SHA for a string.

Link to this function

trivial_http_get_client(url)

View Source

The only significant advantage of this HTTP client is that it only uses things that are in Erlang itself.

https://stackoverflow.com/questions/20108421/using-the-httpc-erlang-module-from-elixir

Link to this function

wrap_in_div_for_valid_markdown(s)

View Source

Earmark says that "A HTML Block defined by a tag starting a line and the same tag starting a different line is parsed as one HTML AST node, marked with %{verbatim: true}" (see https://hexdocs.pm/earmark_parser/EarmarkParser.html )

So we wrap everything in a DIV and call it a day.

Link to this function

write_to_cache(module, recipe, contents)

View Source

Write a file to its right cache.