0.0.3 • Published 6 years ago

weekend-spa v0.0.3

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

Weekend-SPA

Wrapper for making single page applications with JsRender. See JsRender API for how to make html templates.

API

Renderer

Class for binding and rendering views. Create an instance of Renderer to persist the bindings, which causes any link with the class "pop" to trigger the rendering without reloading the page.

Kind: global class


renderer.bindView(view, url, contextData, callbackFn, selector)

Binds a view to a URL

Kind: instance method of Renderer

ParamTypeDescription
viewstringThe HTML file to render
urlstringThe path of the view
contextDataObject | functionObject containing tag data, which can be accessed in the html view with {{:key}} (see JSRender API), or a function. Providing the data as an array will render the template once for each item in the array. A provided function can execute any code and has access to the parameters Renderer and pathParams.
callbackFnfunction | stringa function with parameter (contextData) to run after the view is rendered.
selectorstringSupply a selector to bind with selector instead of only url

renderer.bindViewWithJSON(view, url, jsonUrl, dataName, callbackFn, additionalData, selector)

Binds a view to a URL (and optionally a selector), and fetches JSON data to use as tag arguments. For more complex operations than basic JSON fetching, please use the normal bindView with contextData supplied as a function.

Kind: instance method of Renderer

ParamTypeDefaultDescription
viewstringname of the html file with the template to render
urlstringURL to bind to
jsonUrlstring | Array.<string>URL(s) for JSON to fetch
dataNamestring | Array.<string>"data"name of the data as it is written in the html template file, for example: 'movie' results in the data being accessible with {{:movie}}. Pass one string for each JSON.
callbackFnfunctiona function to run each time the view is rendered.
additionalDataObject | stringAdditional data to be available in the template and callback. Must be a "true" object that can be Object.assign()ed onto the fetched data.
selectorstringOnly necessary if the selector does not have the class 'pop'

renderer.renderView(viewFile, contextData, callbackFn, selector, viewsFolder) ⇒ Promise

Renders a view

Kind: instance method of Renderer

ParamTypeDefaultDescription
viewFilestring | functionPass empty string to only call the callback function.
contextDataObjectObject containing tag data, which can be accessed in the html view with {{:key}} (see JSRender API), or a function. Providing the data as an array will render the template once for each item in the array.
callbackFnfunctiona function with parameter (contextData) to run after the view is rendered.
selectorstring"'#root'"Target selector to insert html in, default #root
viewsFolderstring"'/views/'"default /views/

Renderer.bindView(view, url, contextData, callbackFn, selector)

Binds a view to a URL

Kind: static method of Renderer

ParamTypeDescription
viewstringThe HTML file to render
urlstringThe path of the view
contextDataObject | functionObject containing tag data, which can be accessed in the html view with {{:key}} (see JSRender API), or a function. Providing the data as an array will render the template once for each item in the array. A provided function can execute any code and has access to the parameters Renderer and pathParams.
callbackFnfunction | stringa function with parameter (contextData) to run after the view is rendered.
selectorstringSupply a selector to bind with selector instead of only url

Renderer.bindViewToSelector(selector, view, url, contextData, callbackFn)

Binds a view to a selector and a URL

Kind: static method of Renderer

ParamTypeDefaultDescription
selectorstringSelector to bind to
viewstringThe HTML file to render
urlstringThe path of the view
contextDataObject | functionObject containing tag data, which can be accessed in the html view with {{:key}} (see JSRender API), or a function. Providing the data as an array will render the template once for each item in the array. A provided function can execute any code and has access to the parameters Renderer and pathParams.
callbackFnfunctiona function with parameter (contextData) to run each time the view is rendered.

Renderer.bindViewWithJSON(view, url, jsonUrl, dataName, callbackFn, additionalData, selector)

Binds a view to a URL (and optionally a selector), and fetches JSON data to use as tag arguments. For more complex operations than basic JSON fetching, please use the normal bindView with contextData supplied as a function.

Kind: static method of Renderer

ParamTypeDefaultDescription
viewstringname of the html file with the template to render
urlstringURL to bind to
jsonUrlstring | Array.<string>URL(s) for JSON to fetch
dataNamestring | Array.<string>"data"name of the data as it is written in the html template file, for example: 'movie' results in the data being accessible with {{:movie}}. Pass one string for each JSON.
callbackFnfunctiona function to run each time the view is rendered.
additionalDataObject | stringAdditional data to be available in the template and callback. Must be a "true" object that can be Object.assign()ed onto the fetched data.
selectorstringOnly necessary if the selector does not have the class 'pop'

Renderer.renderView(viewFile, contextData, callbackFn, selector, viewsFolder) ⇒ Promise

Renders a view

Kind: static method of Renderer

ParamTypeDefaultDescription
viewFilestring | functionPass empty string to only call the callback function.
contextDataObjectObject containing tag data, which can be accessed in the html view with {{:key}} (see JSRender API), or a function. Providing the data as an array will render the template once for each item in the array.
callbackFnfunctiona function with parameter (contextData) to run after the view is rendered.
selectorstring"'#root'"Target selector to insert html in, default #root
viewsFolderstring"'/views/'"default /views/

0.1.0-alpha.5

6 years ago

0.1.0-alpha.4

6 years ago

0.1.0-alpha.3

6 years ago

0.1.0-alpha.2

6 years ago

0.1.0-alpha.1

6 years ago

0.1.0-alpha.0

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.0

6 years ago