pirtleshell/baby-got-backend

Template/Wildcard Route Use Case

Opened this issue · 0 comments

templates & wildcard routes

When template is defined on the pageSpec, or, when the route is expressed with a wildcard parameter (such as /object/:id), we want the following behavior:

  • support pageSpec.template -> template should take precedence over filename for the file to be edited in the editor
  • the dataObject passed to render must change accordingly

We need to accept some definitions of how to get particular data objects to mock the rendering.

Maybe a function of the urlParams called getData that returns the dataObject to be passed to the data function.

different render funcs for filename vs text string rendering

a common use case is for render funcs to take a text string, or to take the filename. we should have options for both these cases.

  • render might better be called renderFromText, and is for use cases like markdown.render(text) or render(text, dataObject).
  • renderFromFilename is for use cases like pug.renderFilename(filenameOrTemplate, dataObject).

determining the dataObject

the dataObject defaults to the postSpec. if getData is defined, dataObject is whatever is returned by getData(urlParams). if the route has wildcards & there is no getData func defined, the urlParams should also be passed to render...

  • recognize wildcard routes
  • implement getData

default or mock-up data for rendering

  • provide a way to mock data for rendering

pageSpec.mockData for the default object used to render? or maybe mockUrlParams or defaultUrlParams?