Giter VIP home page Giter VIP logo

saw-view's Introduction

SAW View

View module for Nodejs >= 6 that also support the lovely Blade templating syntax of Laravel framework.

Install

npm install https://github.com/zombielab/saw-view.git

Use

// The module is coded with ES6 features and makes the use of Promises.
import view from "saw-view";

// So now you can use async/await (ES7) like that:
var output = await view.render("user/profile", { name: "John Doe" });

// Or 
view.render("user/profile", { name: "John Doe" }).then((content) => {
	// whatever
})
.catch((error) => {
	throw error;
});

Setup

While the module has been designed to be a part of SAW Framework it will work perfectly separated. In that case you'll need to setup few things. The following code will do the initial setup, so put it anywhere you want in your project.

import factory from "saw-view";
import FileViewFinder from "saw-view/lib/finder/file-view-finder";
import ViewEngineResolver from "saw-view/lib/engines/view-engine-resolver";
import HtmlViewEngine from "saw-view/lib/engines/html-view-engine";
import CompilerViewEngine from "saw-view/lib/engines/compiler-view-engine";
import BladeViewCompiler from "saw-view/lib/compilers/blade-view-compiler";

var dir = __dirname + "/resources/views",
    compiled_dir = __dirname + "/resources/views-compiled";

// Registering the view finder and a directory path to look into
factory.finder = new FileViewFinder();
factory.finder.paths.push(dir);

// Adding file extensions.
factory.finder.extensions.push("html");
factory.finder.extensions.push("blade.html");

// And view engines.
// The module comes shipped with an Html and a Blade templating engine.
factory.engine_resolver = new ViewEngineResolver();
factory.engine_resolver.engines["html"] = new HtmlViewEngine();

// For the Blade engine you must also define a directory path where to store compiled views.
var compiler = new BladeViewCompiler(compiled_dir);
factory.engine_resolver.engines["blade"] = new CompilerViewEngine(factory, compiler);

// Associating file extensions with engines.
factory.extensions["html"] = "html";
factory.extensions["blade.html"] = "blade";

// And we're done 

saw-view's People

Contributors

zombielab avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.