2.0.0 • Published 8 years ago

statico v2.0.0

Weekly downloads
5
License
ISC
Repository
github
Last release
8 years ago

Statico

This small tool can read any static file and make it dynamic.specially made to make html static files into dynamic.

alt tag

##What's New? -- Now "Statico" can automatically link external CSS and Javascript files to the HTML page

statico.setup(req, res); // This method gives the access of HTTP Request and Response to Statico Module

#####Note

You must validate req.url correctly. (i have explained a '/' route) if you don't, it will break the code

##Usage

require statico module
var statico = require('statico');
use statico .use method to read file
var data = statico.use('filename.html');
data.then(function (data)) {
  console.log(data);
}
use statico .use to change content dynamically and return the changed data
var data = statico.use('filename.html', { "title" : "My title", "text" : "this is the text" });
data.then(function (data)) {
  console.log(data);
}

OR

statico.use('filename.html', { "title" : "My title", "text" : "this is the text" }, function (data) {
  console.log(data);
});
filename.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title : ${title}</title>
  <link rel="stylesheet" href="css/style.css">
</head>
<body>

  <h1>Text : <span style="color: #333;">${text}</span></h1>

  <a id="click" href="#">Click me</a>
  <a href="me.html">Me</a>

<script type="text/javascript">
  console.log("loged");
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript" src="js/file.js"></script>
<script type="text/javascript" src="js/file2.js"></script>
</body>
</html>
use statico with http web server
var http = require("http");
var statico = require('statico');

var file = statico.use("filename.html", { "title" : "My title", "text" : "This is text" });

http.createServer(function (req, res) {
  statico.setup(req, res);
  if (req.url === '/') {
    file.then(function (data) {
        res.writeHead(200, { "Content-Type" : "text/html" });
        res.write(data);
        res.end();
    });
  } else if (req.url === '/me') {
    var d = statico.use('me.html');
      d.then(function (data) {
        res.writeHead(200, { "Content-Type" : "text/html" });
        res.write(data);
        res.end();
      });
  }
}).listen(8000);
2.0.0

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0-c

8 years ago

1.0.0-b

8 years ago

1.0.0-a

8 years ago

1.0.0

8 years ago