From 8be45d70baac26a2396b81da07bbdf7f1650e6ad Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 6 Jun 2022 08:28:04 +0100 Subject: [PATCH 1/3] docs: update references to old point-of-view module --- README.md | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index be907e67..ee88d9e7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# point-of-view +# @fastify/point-of-view ![CI](https://github.com/fastify/point-of-view/workflows/CI/badge.svg) [![NPM version](https://img.shields.io/npm/v/point-of-view.svg?style=flat)](https://www.npmjs.com/package/point-of-view) @@ -6,7 +6,7 @@ Templates rendering plugin support for Fastify. -`point-of-view` decorates the reply interface with the `view` method for managing view engines, which can be used to render templates responses. +`@fastify/point-of-view` decorates the reply interface with the `view` method for managing view engines, which can be used to render templates responses. Currently supports the following templates engines: @@ -21,7 +21,7 @@ Currently supports the following templates engines: - [`doT`](https://github.com/olado/doT) - [`eta`](https://eta.js.org) -In `production` mode, `point-of-view` will heavily cache the templates file and functions, while in `development` will reload every time the template file and function. +In `production` mode, `@fastify/point-of-view` will heavily cache the templates file and functions, while in `development` will reload every time the template file and function. _Note: For **Fastify v3 support**, please use point-of-view `5.x` (npm i point-of-view@5)._ @@ -42,14 +42,14 @@ The data has been taken with: `autocannon -c 100 -d 5 -p 10 localhost:3000` ## Install ``` -npm install point-of-view --save +npm install @fastify/point-of-view ``` ## Quick start -`fastify.register` is used to register point-of-view. By default, It will decorate the `reply` object with a `view` method that takes at least two arguments: +`fastify.register` is used to register @fastify/point-of-view. By default, It will decorate the `reply` object with a `view` method that takes at least two arguments: - the template to be rendered - the data that should be available to the template during rendering @@ -59,7 +59,7 @@ This example will render the template and provide a variable `text` to be used i ```js const fastify = require("fastify")(); -fastify.register(require("point-of-view"), { +fastify.register(require("@fastify/point-of-view"), { engine: { ejs: require("ejs"), }, @@ -105,7 +105,7 @@ fastify.get("/", async (req, reply) => { Example: ```js -fastify.register(require("point-of-view"), { +fastify.register(require("@fastify/point-of-view"), { engine: { handlebars: require("handlebars"), }, @@ -140,13 +140,13 @@ fastify.view("/templates/index.ejs", { text: "text" }, (err, html) => { Registering multiple engines with different configurations is supported. They are dinguished via their `propertyName`: ```js -fastify.register(require("point-of-view"), { +fastify.register(require("@fastify/point-of-view"), { engine: { ejs: ejs }, layout: "./templates/layout-mobile.ejs", propertyName: "mobile", }); -fastify.register(require("point-of-view"), { +fastify.register(require("@fastify/point-of-view"), { engine: { ejs: ejs }, layout: "./templates/layout-desktop.ejs", propertyName: "desktop", @@ -165,7 +165,7 @@ fastify.get("/desktop", (req, reply) => { ## Providing a layout on render -Point-of-view supports layouts for **EJS**, **Handlebars**, **Eta** and **doT**. +@fastify/point-of-view supports layouts for **EJS**, **Handlebars**, **Eta** and **doT**. These engines also support providing a layout on render. **Please note:** Global layouts and provding layouts on render are mutually exclusive. They can not be mixed. @@ -248,7 +248,7 @@ const options = { pathsToExcludeHtmlMinifier: ['/test'] } -fastify.register(require("point-of-view"), { +fastify.register(require("@fastify/point-of-view"), { engine: { ejs: require('ejs') }, @@ -320,7 +320,7 @@ To use partials in handlebars you will need to pass the names and paths in the o To use layouts in handlebars you will need to pass the `layout` parameter: ```js -fastify.register(require("point-of-view"), { +fastify.register(require("@fastify/point-of-view"), { engine: { handlebars: require("handlebars"), }, @@ -337,7 +337,7 @@ fastify.get("/", (req, reply) => { You can load templates from multiple paths when using the nunjucks engine: ```js -fastify.register(require("point-of-view"), { +fastify.register(require("@fastify/point-of-view"), { engine: { nunjucks: require("nunjucks"), }, @@ -371,7 +371,7 @@ const engine = new Liquid({ extname: ".liquid", }); -fastify.register(require("point-of-view"), { +fastify.register(require("@fastify/point-of-view"), { engine: { liquid: engine, }, @@ -392,7 +392,7 @@ To make it possible it is necessary to provide a `root` or `templates` option wi ```js const path = require("path"); -fastify.register(require("point-of-view"), { +fastify.register(require("@fastify/point-of-view"), { engine: { dot: require("dot"), }, @@ -456,9 +456,9 @@ app.get("/data", (request, reply) => { ## Miscellaneous -### Using point-of-view as a dependency in a fastify-plugin +### Using @fastify/point-of-view as a dependency in a fastify-plugin -To require `point-of-view` as a dependency to a [fastify-plugin](https://github.com/fastify/fastify-plugin), add the name `point-of-view` to the dependencies array in the [plugin's opts](https://github.com/fastify/fastify-plugin#dependencies). +To require `@fastify/point-of-view` as a dependency to a [fastify-plugin](https://github.com/fastify/fastify-plugin), add the name `point-of-view` to the dependencies array in the [plugin's opts](https://github.com/fastify/fastify-plugin#dependencies). ```js fastify.register(myViewRendererPlugin, { From 88fb3ae4b0a8bffdd7f4f115bbb345a739cc22be Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Tue, 7 Jun 2022 18:57:54 +0100 Subject: [PATCH 2/3] docs(readme): update npm badge link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ee88d9e7..48b3442c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # @fastify/point-of-view ![CI](https://github.com/fastify/point-of-view/workflows/CI/badge.svg) -[![NPM version](https://img.shields.io/npm/v/point-of-view.svg?style=flat)](https://www.npmjs.com/package/point-of-view) +[![NPM version](https://img.shields.io/npm/v/@fastify/point-of-view.svg?style=flat)](https://www.npmjs.com/package/@fastify/point-of-view) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) Templates rendering plugin support for Fastify. From a5e5fc97a84a6014ce7d07f1dd40e4e128574f2f Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Tue, 7 Jun 2022 18:59:51 +0100 Subject: [PATCH 3/3] docs(readme): update name to @fastify/view --- README.md | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 48b3442c..f6c7b3b6 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# @fastify/point-of-view +# @fastify/view ![CI](https://github.com/fastify/point-of-view/workflows/CI/badge.svg) -[![NPM version](https://img.shields.io/npm/v/@fastify/point-of-view.svg?style=flat)](https://www.npmjs.com/package/@fastify/point-of-view) +[![NPM version](https://img.shields.io/npm/v/@fastify/view.svg?style=flat)](https://www.npmjs.com/package/@fastify/view) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) Templates rendering plugin support for Fastify. -`@fastify/point-of-view` decorates the reply interface with the `view` method for managing view engines, which can be used to render templates responses. +`@fastify/view` decorates the reply interface with the `view` method for managing view engines, which can be used to render templates responses. Currently supports the following templates engines: @@ -21,7 +21,7 @@ Currently supports the following templates engines: - [`doT`](https://github.com/olado/doT) - [`eta`](https://eta.js.org) -In `production` mode, `@fastify/point-of-view` will heavily cache the templates file and functions, while in `development` will reload every time the template file and function. +In `production` mode, `@fastify/view` will heavily cache the templates file and functions, while in `development` will reload every time the template file and function. _Note: For **Fastify v3 support**, please use point-of-view `5.x` (npm i point-of-view@5)._ @@ -42,14 +42,14 @@ The data has been taken with: `autocannon -c 100 -d 5 -p 10 localhost:3000` ## Install ``` -npm install @fastify/point-of-view +npm install @fastify/view ``` ## Quick start -`fastify.register` is used to register @fastify/point-of-view. By default, It will decorate the `reply` object with a `view` method that takes at least two arguments: +`fastify.register` is used to register @fastify/view. By default, It will decorate the `reply` object with a `view` method that takes at least two arguments: - the template to be rendered - the data that should be available to the template during rendering @@ -59,7 +59,7 @@ This example will render the template and provide a variable `text` to be used i ```js const fastify = require("fastify")(); -fastify.register(require("@fastify/point-of-view"), { +fastify.register(require("@fastify/view"), { engine: { ejs: require("ejs"), }, @@ -95,7 +95,7 @@ fastify.get("/", async (req, reply) => { ### Options - `engine`: The template engine object - pass in the return value of `require('')`. This option is mandatory. -- `layout`: Point-of-view supports layouts for **EJS**, **Handlebars**, **Eta** and **doT**. This option lets you specify a global layout file to be used when rendering your templates. Settings like `root` or `viewExt` apply as for any other template file. Example: `./templates/layouts/main.hbs` +- `layout`: @fastify/view supports layouts for **EJS**, **Handlebars**, **Eta** and **doT**. This option lets you specify a global layout file to be used when rendering your templates. Settings like `root` or `viewExt` apply as for any other template file. Example: `./templates/layouts/main.hbs` - `propertyName`: The property that should be used to decorate `reply` and `fastify` - E.g. `reply.view()` and `fastify.view()` where `"view"` is the property name. Default: `"view"`. - `root`: The root path of your templates folder. The template name or path passed to the render function will be resolved relative to this path. Default: `"./"`. - `includeViewExtension`: Setting this to `true` will automatically append the default extension for the used template engine **if ommited from the template name** . So instead of `template.hbs`, just `template` can be used. Default: `false`. @@ -105,7 +105,7 @@ fastify.get("/", async (req, reply) => { Example: ```js -fastify.register(require("@fastify/point-of-view"), { +fastify.register(require("@fastify/view"), { engine: { handlebars: require("handlebars"), }, @@ -140,13 +140,13 @@ fastify.view("/templates/index.ejs", { text: "text" }, (err, html) => { Registering multiple engines with different configurations is supported. They are dinguished via their `propertyName`: ```js -fastify.register(require("@fastify/point-of-view"), { +fastify.register(require("@fastify/view"), { engine: { ejs: ejs }, layout: "./templates/layout-mobile.ejs", propertyName: "mobile", }); -fastify.register(require("@fastify/point-of-view"), { +fastify.register(require("@fastify/view"), { engine: { ejs: ejs }, layout: "./templates/layout-desktop.ejs", propertyName: "desktop", @@ -165,7 +165,7 @@ fastify.get("/desktop", (req, reply) => { ## Providing a layout on render -@fastify/point-of-view supports layouts for **EJS**, **Handlebars**, **Eta** and **doT**. +@fastify/view supports layouts for **EJS**, **Handlebars**, **Eta** and **doT**. These engines also support providing a layout on render. **Please note:** Global layouts and provding layouts on render are mutually exclusive. They can not be mixed. @@ -248,7 +248,7 @@ const options = { pathsToExcludeHtmlMinifier: ['/test'] } -fastify.register(require("@fastify/point-of-view"), { +fastify.register(require("@fastify/view"), { engine: { ejs: require('ejs') }, @@ -320,7 +320,7 @@ To use partials in handlebars you will need to pass the names and paths in the o To use layouts in handlebars you will need to pass the `layout` parameter: ```js -fastify.register(require("@fastify/point-of-view"), { +fastify.register(require("@fastify/view"), { engine: { handlebars: require("handlebars"), }, @@ -337,7 +337,7 @@ fastify.get("/", (req, reply) => { You can load templates from multiple paths when using the nunjucks engine: ```js -fastify.register(require("@fastify/point-of-view"), { +fastify.register(require("@fastify/view"), { engine: { nunjucks: require("nunjucks"), }, @@ -371,7 +371,7 @@ const engine = new Liquid({ extname: ".liquid", }); -fastify.register(require("@fastify/point-of-view"), { +fastify.register(require("@fastify/view"), { engine: { liquid: engine, }, @@ -392,7 +392,7 @@ To make it possible it is necessary to provide a `root` or `templates` option wi ```js const path = require("path"); -fastify.register(require("@fastify/point-of-view"), { +fastify.register(require("@fastify/view"), { engine: { dot: require("dot"), }, @@ -456,13 +456,13 @@ app.get("/data", (request, reply) => { ## Miscellaneous -### Using @fastify/point-of-view as a dependency in a fastify-plugin +### Using @fastify/view as a dependency in a fastify-plugin -To require `@fastify/point-of-view` as a dependency to a [fastify-plugin](https://github.com/fastify/fastify-plugin), add the name `point-of-view` to the dependencies array in the [plugin's opts](https://github.com/fastify/fastify-plugin#dependencies). +To require `@fastify/view` as a dependency to a [fastify-plugin](https://github.com/fastify/fastify-plugin), add the name `@fastify/view` to the dependencies array in the [plugin's opts](https://github.com/fastify/fastify-plugin#dependencies). ```js fastify.register(myViewRendererPlugin, { - dependencies: ["point-of-view"], + dependencies: ["@fastify/view"], }); ```