From 1527ca03e5d5e60a53b21de005ec5a8479f2c8a4 Mon Sep 17 00:00:00 2001 From: devalexqt Date: Wed, 10 Dec 2014 19:56:15 +0200 Subject: [PATCH] Added simple server and project structure was changed. --- README.md | 8 +++++--- server.js | 14 ++++++++------ www/css/style.less | 2 +- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e45bd63..3be8d17 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ - -PageManager it's Javascript page system management in browser. Simple but powerful script wath work in all modern desktop and mobile browser and allow to create page management in webview. This script will be ideal for mobile application that using HTML5 code. With PageManager You can create amazing mobile application just in seconds! In other word it's quick start to create cordova html 5 application! +#Description +PageManager it's Javascript page system management in browser. Simple but powerful script wath work in all modern desktop and mobile browser and allow to create page management in webview. This script will be ideal for mobile application that using HTML5 code. With PageManager You can create amazing mobile application just in seconds! In other word it's quick start to create **cordova** html 5 application! #Demo @@ -15,12 +15,14 @@ cd js-page-manager/ npm install ``` -* Run Node.js simple server wath using [less](http://lesscss.org/) pre-processor for css file and [swig](http://paularmstrong.github.io/swig/) html template engine. +* Run Node.js simple server that using [Less](http://lesscss.org/) as pre-processor for css file and [SWIG](http://paularmstrong.github.io/swig/) as html template engine. ``` node server.js ``` * Now visit to http://127.0.0.1/index.html +* **After You finishing development then You need to generate .css and .html file using Less and SWIG commands** + #Usage diff --git a/server.js b/server.js index d40ae55..8f10918 100644 --- a/server.js +++ b/server.js @@ -5,11 +5,13 @@ var url = require("url") var less = require('less')//css processor var swig = require('swig')// html templete processor +var rootpath="./www/" http.createServer(handler).listen(80) swig.setDefaults({ cache: false,allowErrors: true }); -console.log("==>Simple server for developing started on port 80. Now visit to http://127.0.0.1/ or http://127.0.0.1/index.html") +console.log("==>Simple server for developing started on port 80. Now visit to http://127.0.0.1/ or http://127.0.0.1/index.html \n Working directory: "+rootpath) + function handler(req,res){ console.log("==>New request: "+req.method+", "+req.url) var url_parts=url.parse(req.url,true) @@ -24,11 +26,11 @@ function handler(req,res){ //res.writeHead(200, headers); - var req_file="./www/"+url_parts.pathname - var extention=url_parts.pathname.split(".") - extention=extention[extention.length-1] + if(url_parts.pathname=="/"){url_parts.pathname="/index.html"} - if(req_file=="/"){req_file="/index.html"} + var req_file=rootpath+url_parts.pathname + var extention=req_file.split(".") + extention=extention[extention.length-1] if (extention=="css"&&fs.existsSync(req_file.replace(".css",".less"))) { req_file=req_file.replace(".css",".less") @@ -48,7 +50,7 @@ function handler(req,res){ sendPage(data,"text/javascript") }//if js else if(extention=="less"){ - less.render(data.toString(), function (err, data) { + less.render(data.toString(),{paths: rootpath}, function (err, data) { if (err){console.log("==>cant parse less file, err: "+err);res.statusCode=404;res.end(); return}; sendPage(data.css,"text/css")//[css,imports] })//less diff --git a/www/css/style.less b/www/css/style.less index 5ae1e53..bec33b5 100644 --- a/www/css/style.less +++ b/www/css/style.less @@ -1,5 +1,5 @@ //less -@import "/css/page-manager.less"; +@import (less) "css/page-manager.less"; //colors @color-green2: rgb(57,202,108); @color-metal:rgba(117, 149, 164,1.0);//background