View Source Gluttony.Handler behaviour (gluttony v0.3.0)

This module defines the behaviour for handlers.

Both handle_element/2, handle_content/2 and handle_cached/2 should return on of the following result tuples:

  • {:entry, chars_or_attrs} - To indicate that a new entry should be created.
  • {:entry, :key, value} - To indicate that a entry should be updated with the given key and value.
  • {:feed, :key, value} - To indicate that the feed should be updated with the given key and value.
  • {:cache, :key} - To indicate that the given key should be cached. Because successive calls with the same key will clean the previous value, this should only be called on handle_element. This will guarantee that the cache will live through the tag lifecycle, instead of being cleaned on whenever new content is found.
  • {:cache, :key, value} - To indicate that the given key should be cached with the given value.
  • {:cont, chars_or_attrs} - To indicate that the current element should be ignored.

If the value is a list, it will be appended to the existing value. Otherwise, it will replace the current value. Its also possible to pass a list as the path to create a nested structure (all intermidiate values will be created).

Summary

Callbacks

This callback is called when and element is about to finish.

This callback is called when a content of a element is encountered.

This callback is called when a start element is encountered.

Types

@type attrs() :: [{binary(), term()}]
@type chars() :: binary() | [binary()]
@type path() :: atom() | [atom()]
@type result() ::
  {:entry, term()}
  | {:entry, path(), term()}
  | {:feed, path(), term()}
  | {:cache, atom()}
  | {:cache, path(), term()}
  | {:cont, term()}
@type stack() :: [binary()]

Callbacks

Link to this callback

handle_cached(cached, stack)

View Source
@callback handle_cached(cached :: term(), stack :: stack()) :: result()

This callback is called when and element is about to finish.

Link to this callback

handle_content(chars, stack)

View Source
@callback handle_content(chars :: chars(), stack :: stack()) :: result()

This callback is called when a content of a element is encountered.

Link to this callback

handle_element(attrs, stack)

View Source
@callback handle_element(attrs :: attrs(), stack :: stack()) :: result()

This callback is called when a start element is encountered.