Context is built at runtime by combining other pieces of data stored in assemble
Config is the entire configuration object that is passed into assemble. This configuration object gets normalized through
normalize-config
to ensure a common data structure.
Options are a property on the configuration object after normalization. Options are normally used to pass information to 3rd party modules and for customizing assemble middleware and helpers.
Data refers to the data property on options and will be read and normalized through
plasma
. This gives users the ability to pass in plain old JavaScript objects or glob patterns pointing to data files.
Local context will be an object that is set just before calling render. This local context will usually refer to the page front matter and will be merged in last to ensure overwritting less specific contexts. To update local context in middlewares, update the corresponding
page.data
object. Helpers will be able to use the local context either directly (assemble.localContext
) or through getting the global context with the local context extended (assemble.context()
)
The
context()
method combines the other data structures into one by using lodashextend
. Additional arguments may be passed tocontext
for additional extensions (These would normally come from page or partial front matter).
If a helper or middleware needs to update values on the assemble context, it should do so through the base object that is used to build the context. For instance, when needing to update a configuration property, update
assemble.config
directly. If a middleware needs to update specific page front matter, update it on thepage.data
object directly so it's merged in properly during render time.
Thinking about some of these base data objects...
We could always wrap them in some sort of class like
Cache
that has theget
andset
methods on them and when doing aget
we could get the entire context and run the returned object throughexpander
like: