SEO. JSONLD. Actions
(SEO v0.3.0-rc.0)
View Source
Helpers for Schema.org Action payloads — specifically the hyphenated
<property>-input / <property>-output property-constraint syntax
documented at https://schema.org/docs/actions.html (Part 4).
Schema.org's Action types (e.g. SEO.JSONLD.SearchAction,
SEO.JSONLD.SolveMathAction, SEO.JSONLD.ReviewAction,
SEO.JSONLD.WatchAction) annotate required inputs with a hyphenated
key whose value is a space-separated HTML-like attribute string:
"query-input": "required maxlength=100 name=q"These hyphenated keys aren't expressible as Elixir atoms, so this module provides composable primitives:
input_spec/1builds the shorthand value for a single annotation.inputs/1/outputs/1expand a list of property/constraint pairs into the full%{"<property>-input" => "<spec>"}map ready to merge into your Actionbuild/1attrs.
See SEO.JSONLD.EntryPoint when you need the richer target form
(urlTemplate + httpMethod + contentType).
Example
SEO.JSONLD.SolveMathAction.build(
Map.merge(
%{
target: "https://example.com/solve?q={math_expression_string}",
edu_question_type: ["Polynomial Equation"]
},
SEO.JSONLD.Actions.inputs(
math_expression: [required: true, name: "math_expression_string"]
)
)
)This module is hand-written and preserved by the generator.
Summary
Functions
Build the shorthand value string for a single property-constraint annotation. Accepts a keyword list of constraints
Expand a keyword list of property/constraint pairs into a map of
hyphenated <property>-input keys. Each property key is camelCased
(:math_expression becomes mathExpression-input).
Like inputs/1 but for <property>-output annotations, used by
Actions that describe the shape of their result (e.g. ReviewAction
declaring required output fields on the produced Review).
Functions
Build the shorthand value string for a single property-constraint annotation. Accepts a keyword list of constraints:
:required(boolean) — whether the input must be supplied:name— placeholder name referenced intargetURL templates (e.g.name: "q"maps to{q}in the target):max_length/:min_length— length bounds (integers):value_max/:value_min— numeric value bounds:pattern— regex pattern constraint:multiple_values(boolean) — whether multiple values are allowed
Options with a nil or false value are omitted. Unknown options fall
back to a camelCased key=value pair.
iex> SEO.JSONLD.Actions.input_spec(required: true, max_length: 100, name: "q")
"required maxlength=100 name=q"
iex> SEO.JSONLD.Actions.input_spec(required: true, multiple_values: true, name: "tag")
"required multipleValues name=tag"
Expand a keyword list of property/constraint pairs into a map of
hyphenated <property>-input keys. Each property key is camelCased
(:math_expression becomes mathExpression-input).
iex> SEO.JSONLD.Actions.inputs(
...> query: [required: true, name: "q"],
...> math_expression: [required: true, name: "expr"]
...> )
%{
"mathExpression-input" => "required name=expr",
"query-input" => "required name=q"
}
Like inputs/1 but for <property>-output annotations, used by
Actions that describe the shape of their result (e.g. ReviewAction
declaring required output fields on the produced Review).