UNPKG

viewson

Version:

This package is a view engine which supports JSON and BSON data

134 lines (113 loc) 5.45 kB
This is a view engine in which you can write the html in a **JSON** or ~~BSON~~ format. You can also input a normal js object or a JSON string but that is not recommended. # Index: [How to enter tags](#how-to-enter-tags) [How to add attributes](#we-can-also-add-attributes-like-this) [How to add dynamic content](#this-package-also-supports-dynamic-content) [What are the parameters of the render function](#parameters-of-the-render-function-this-is-the-function-for-json) [How can we enter a *JSON* string](#render-with-json) [How can we enter a *Javascript Object* as an input](#render-with-javascript-object) [Additional information](#additional-information) # How to enter tags: You can enter tags like this: ``` { "html5":{ "head":{ "title":{ "content":"Document" } } "body":{ "p":{ "content":"This is a paragraph" } } } } ``` Like this we can do nesting and add tags. # We can also add attributes like this: ``` { "html5":{ "head":{ "title":{ "content":"Document" } }, "body":{ "p":{ "content":"This is a paragraph", "attributes":[{"style":"{color:red;}"},{"class":"paragraph1"}] } } } } ``` There is one more way to do nesting: We can also make content a object and put tags in it. # This package also supports dynamic content. In the last parameter of the compile function we can add the dynamic content, specify the content like you do in the JSON file but it should be in a JS object. [Click here](#Parameters-of-the-render-function-(This-is-the-function-for-JSON)) to get more information about the parameters of the compile function. In the json or bson file write dynamic as a key instead of content and write the key in the content which you specified in the dynamic content parameter. ### For eg. this is the dynamic content we passed: ``` { yay: { content: "This is dynamic!", attributes: [{ class: "highlight" }] } } ``` ### And we can use it as this in our json file: ``` { "html5": { "head": { "title": { "content": "Test Page" } }, "body": { "h1": { "p":{ "content":"Nested" } }, "p":{ "dynamic":"yay" } } } } ``` # Parameters of the render function (This is the function for JSON file) How to use it: **render()** |Parameter name | Use | |---------------|------------------------------------------------------------------------------------------------| |filename |The filepath of the file where you have written your json. | |res |The response object. | |have |The basic dependencies the project uses like express. | |dynData |The dynamic data. For more information [click here](#this-package-also-supports-dynamic-content)| # render with JSON How to use it: __renderWithoutFilename()__ |Parameter name | Use | |---------------|------------------------------------------------------------------------------------------------| |filename |The _JSON string_. | |res |The response object. | |have |The basic dependencies the project uses like express. | |dynData |The dynamic data. For more information [click here](#this-package-also-supports-dynamic-content)| # render with Javascript Object How to use it:__renderObject()__ |Parameter name | Use | |---------------|------------------------------------------------------------------------------------------------| |filename |The _Javascript object_. | |res |The response object. | |have |The basic dependencies the project uses like express. | |dynData |The dynamic data. For more information [click here](#this-package-also-supports-dynamic-content)| # Additional information ## License This project is licensed under the [BSD 3-Clause License](./LICENCES/LICENSE.txt) © *2025 Aarav Garg*. All rights reserved ## Third-Party Dependencies This project makes use of the following open-source package: - **bson** — Licensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0) Please refer to each dependency’s repository and license for more information.