Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added $.readFile, updated README and bumped version to 0.1.0

  • Loading branch information...
commit 37e2b82a49896d797d00a5a6aa560b36b8e98076 1 parent 1cc51de
Pradeek authored

Showing 4 changed files with 48 additions and 23 deletions. Show diff stats Hide diff stats

  1. +29 15 README.md
  2. +1 1  examples/app.js
  3. +17 6 lib/jqNode.js
  4. +1 1  package.json
44 README.md
Source Rendered
@@ -8,18 +8,32 @@ INSTALLATION :
8 8
9 9 USAGE :
10 10 =======
11   - var $ = require("jqNode").$;
  11 + var $ = require("../lib/jqNode").$;
12 12
13   - $("/").get(function(request, response, data) {
  13 + $("/").get(function(request, response) {
14 14 $.writeFile("index.html");
15 15 });
16 16
17   - $("/data").post(function(request, response, data) {
18   - // data.param === value
  17 +
  18 + $("/test").get(function(request, response, data) {
  19 + $.write(data['q']);
  20 + });
  21 +
  22 + $("/test").post(function(request, response, data) {
19 23 console.log(data);
20 24 });
21 25
22   - $.start();
  26 + $("/test/:id/sample/:val").get(function(request, response, data) {
  27 + $.write(data['id'] + " | " + data['val']);
  28 + });
  29 +
  30 + $("/sample/:id").get(function(request, response, data) {
  31 + $.write(data['id']);
  32 + });
  33 +
  34 + $.start({
  35 + port: 8080
  36 + });
23 37
24 38
25 39 METHODS AVAILABLE :
@@ -32,18 +46,18 @@ METHODS AVAILABLE :
32 46 .delete(function(request, response) {})
33 47 .head(function(request, response) {});
34 48
35   - $.start(port, debugMode); // Starts and returns the server. Port defaults to 8888, debugMode defaults to false.
  49 + $.start({
  50 + port: 8888,
  51 + debugMode : true
  52 + }); // Starts and returns the server.
36 53
37 54 $.write(data, contentType); // Writes to the current response. contentType defaults to text/html
38 55
39 56 $.writeFile(fileName, contentType); // Reads a file and writes it to the current stream.
40 57
41   -TODO :
42   -======
43   - - Sinatra-like routing
44   - - Remove favicon (Done)
45   - - $.redirect (Done)
46   - - $.start({
47   - port: 80,
48   - debugMode: false,
49   - })
  58 + $.redirect(url); // Redirects to url
  59 +
  60 + $.extend(destination, source, overwrite); // Similar to jQuery.extend
  61 +
  62 + $.readFile(fileName, callback, callbackArgs); // callback -> function(data, callbackArgs) where data -> contents of the file
  63 +
2  examples/app.js
... ... @@ -1,7 +1,7 @@
1 1 var $ = require("../lib/jqNode").$;
2 2
3 3 $("/").get(function(request, response) {
4   - $.writeFile("index.html");
  4 + $.writeFile("index.html")
5 5 });
6 6
7 7
23 lib/jqNode.js
@@ -170,6 +170,19 @@ $.start = function(options) {
170 170 return server;
171 171 }
172 172
  173 +$.readFile = function(fileName, callback, callbackArgs) {
  174 + fs.readFile(fileName, function(error, data) {
  175 + if(error) {
  176 + return "";
  177 + if(_debug) {
  178 + console.log(fileName + " not found");
  179 + }
  180 + } else {
  181 + callback(data, callbackArgs);
  182 + }
  183 + });
  184 +}
  185 +
173 186 $.write = function(data, contentType) {
174 187 if(!contentType) {
175 188 contentType = "text/html";
@@ -183,16 +196,14 @@ $.writeFile = function(fileName, contentType) {
183 196 contentType = "text/html";
184 197 }
185 198 _response.writeHead(200, {'Content-Type' : contentType});
186   - fs.readFile(fileName, function(error, data) {
187   - if(error) {
  199 +
  200 + $.readFile(fileName, function(data, args) {
  201 + if(data == "") {
188 202 _response.end("<h1>Unable to load page. File not found</h1>");
189   - if(_debug) {
190   - console.log(fileName + " not found");
191   - }
192 203 } else {
193 204 _response.end(data);
194 205 }
195 206 });
196 207 }
197 208
198   -exports.$ = $;
  209 +exports.$ = $;
2  package.json
... ... @@ -1,7 +1,7 @@
1 1 {
2 2 "name": "jqNode",
3 3 "description": "An easy to use jQuery-esque library for NodeJS",
4   - "version": "0.0.2",
  4 + "version": "0.1.0",
5 5 "author": "Pradeek <jpradeek@gmail.com>",
6 6 "keywords": ["framework", "jquery", "web"],
7 7 "repository": "git://github.com/pradeek/jqNode",

0 comments on commit 37e2b82

Please sign in to comment.
Something went wrong with that request. Please try again.