-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
83 lines (65 loc) · 2.79 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<link href='https://fonts.googleapis.com/css?family=Chivo:900' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen" />
<link rel="stylesheet" type="text/css" href="stylesheets/pygment_trac.css" media="screen" />
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<title>Invisible.js - Isomorphic web framework</title>
</head>
<body>
<div id="container">
<div class="inner">
<header>
<h1>Invisible.js</h1>
<h2>Reusable models in the client and the server</h2>
</header>
<a href="https://github.com/invisiblejs/invisible">
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub">
</a>
<hr>
<section id="main_content">
<p>Invisible.js works on top of your <a href="http://expressjs.com/">express</a> app leveraging <a href="https://github.com/substack/node-browserify">browserify</a> to allow your domain models to work seamlessly in the client and the server. </p>
<pre><code>Invisible = require("invisible");
crypto = require("crypto");
_s = require("underscore.string");
function Person(firstName, lastName, email){
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
}
Person.prototype.fullName = function(){
return this.firstName + ' ' + this.lastName;
}
Person.prototype.getAvatarUrl = function(){
cleanMail = _s.trim(this.email).toLowerCase();
hash = crypto.createHash("md5").update(cleanMail).digest("hex");
return "http://www.gravatar.com/avatar/" + hash;
}
module.exports = Invisible.createModel("Person", Person);
</code></pre>
<p>Require as usual in the server:</p>
<pre><code>Invisible = require("invisible")
john = new Invisible.Person("John", "Doe", "[email protected]");
john.fullName(); //John Doe
</code></pre>
<p>In the client, just add the invisible script:</p>
<pre><code><script src="invisible.js"></script>
<script>
jane = new Invisible.Person("Jane", "Doe", "[email protected]");
alert(jane.fullName()); //Jane Doe
</script>
</code></pre>
<p>Voilà! Restful API, MongoDB persistence, client and server validations and real-time events all come for free! See the <a href="https://github.com/invisiblejs/invisible/">github project</a> for a full reference.</p>
</section>
<footer>
</footer>
</div>
</div>
</body>
</html>