1.1.2 • Published 4 months ago

kiran-js v1.1.2

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

Welcome to Kiran Framework

Hi! Let's create a web application with the MVC concept using this minimalist framework.

Installation

npm install kiran

Kiran builder

Add this command into scripts object inside the package.json file

"scripts": {
  "kiran": "node node_modules/kiran-js/kiran"
}

And then run the added command

npm run kiran

Basic

Start the app

node kiran start

Reset the app

node kiran reset

Add routes

Add new route and then re-arrange routes order automatically

node kiran [method] [url]

Create

Creating model, view, and controller file easily using kiran builder

model

node kiran create model [model-name]

view

node kiran create view [view-name]

controller

node kiran create controller [controller-name]

model + view + controller

node kiran create mvc [mvc-name@method]

rollback

Rolling back create action

node kiran rollback

Main file

const { app, Kiran }    = require('kiran')
const [ port, status ] = [ 4120, 'App started!' ]

/*
* use kiran object if needed
* kiran class has some method that may usefull for you
* some of them are .pkg(), .logLeft(), .logRight()

* Do not remove start and end comment

*/

/* start */
/* define routes here (between start and end comments) */
/* end */

app.start(port, status)

Controller file

Just export a function that receive three parameter

/* -={name}=- controller */
module.exports = (req, res, Model) => {
	/*
	* model used : -={modelName}=-
	* code...
	*/

	function getMethodHandler () {
		/* get method handler */
		res.view('-={name}=-', { title : '-={name}=-', params : req.params })
	}

	function postMethodHandler () {
		/* Post method handler */
		console.log('Form data :', req.body)
	}

	switch ( req.method ) {
	case 'GET' : getMethodHandler(); 	break
	case 'POST': postMethodHandler(); break
	default    : res.end('Unknown method')
	}
}

Model file

Here we just need to define the type of data should be stored in this model

/* -={name}=- Schema */
const -={name}=-Schema = {
	id : Number, /* This field should be exists */
	/* other fields */
}

module.exports = -={name}=-Schema

View files

Before we can render the targeted view, we must have a master view.

master file

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel="stylesheet" href="/assets/css/style.css">
	<title>-={ data.title }=-</title>
</head>
<body>
	<!-- 
		-=( path, data )=- 	// including tag
		-={ data }=-				// printing tag
		-=[ script ]=-			// scripting tag
	-->
	-=(content, data)=-
	<script src="/assets/js/script.js"></script>
</body>
</html>
graph
A(Route) --> B((url))
A(Route) --> C(Controller) --> E{Model}
C(Controller) --> D(View) --> F(master)
F(Master) --> G((style))
F(Master) --> H((nav))
F(Master) --> I((content))
F(Master) --> J((footer))
F(Master) --> k((script))

KIRAN XD © kiran

1.1.2

4 months ago

1.1.1

4 months ago

1.1.0

4 months ago

1.0.0

4 months ago