neerajdotname-javascript_lab 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +3 -0
- data/README.markdown +1 -0
- data/lib/javascript_lab/app.rb +4 -0
- data/lib/javascript_lab.rb +1 -1
- data/public/javascripts/app.js +13 -0
- data/public/javascripts/jquery.json-1.3.js +156 -0
- data/views/layout.erb +19 -1
- metadata +2 -1
data/History.txt
CHANGED
data/README.markdown
CHANGED
data/lib/javascript_lab/app.rb
CHANGED
data/lib/javascript_lab.rb
CHANGED
data/public/javascripts/app.js
CHANGED
|
@@ -31,3 +31,16 @@ var processForm = function(){
|
|
|
31
31
|
|
|
32
32
|
return false;
|
|
33
33
|
};
|
|
34
|
+
|
|
35
|
+
var verifyJsonForm = function(){
|
|
36
|
+
clear_log();
|
|
37
|
+
try {
|
|
38
|
+
var json_input = document.lab.json_input.value.javascript_lab_trim();
|
|
39
|
+
var json_encoded = $.evalJSON(json_input);
|
|
40
|
+
error_log('Valid JSON');
|
|
41
|
+
}catch(e){
|
|
42
|
+
var error_text = 'Error: ' + e.name + ' ' + e.message;
|
|
43
|
+
error_log(error_text);
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* jQuery JSON Plugin
|
|
3
|
+
* version: 1.0 (2008-04-17)
|
|
4
|
+
*
|
|
5
|
+
* This document is licensed as free software under the terms of the
|
|
6
|
+
* MIT License: http://www.opensource.org/licenses/mit-license.php
|
|
7
|
+
*
|
|
8
|
+
* Brantley Harris technically wrote this plugin, but it is based somewhat
|
|
9
|
+
* on the JSON.org website's http://www.json.org/json2.js, which proclaims:
|
|
10
|
+
* "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that
|
|
11
|
+
* I uphold. I really just cleaned it up.
|
|
12
|
+
*
|
|
13
|
+
* It is also based heavily on MochiKit's serializeJSON, which is
|
|
14
|
+
* copywrited 2005 by Bob Ippolito.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
(function($) {
|
|
18
|
+
function toIntegersAtLease(n)
|
|
19
|
+
// Format integers to have at least two digits.
|
|
20
|
+
{
|
|
21
|
+
return n < 10 ? '0' + n : n;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
Date.prototype.toJSON = function(date)
|
|
25
|
+
// Yes, it polutes the Date namespace, but we'll allow it here, as
|
|
26
|
+
// it's damned usefull.
|
|
27
|
+
{
|
|
28
|
+
return this.getUTCFullYear() + '-' +
|
|
29
|
+
toIntegersAtLease(this.getUTCMonth()) + '-' +
|
|
30
|
+
toIntegersAtLease(this.getUTCDate());
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g;
|
|
34
|
+
var meta = { // table of character substitutions
|
|
35
|
+
'\b': '\\b',
|
|
36
|
+
'\t': '\\t',
|
|
37
|
+
'\n': '\\n',
|
|
38
|
+
'\f': '\\f',
|
|
39
|
+
'\r': '\\r',
|
|
40
|
+
'"' : '\\"',
|
|
41
|
+
'\\': '\\\\'
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
$.quoteString = function(string)
|
|
45
|
+
// Places quotes around a string, inteligently.
|
|
46
|
+
// If the string contains no control characters, no quote characters, and no
|
|
47
|
+
// backslash characters, then we can safely slap some quotes around it.
|
|
48
|
+
// Otherwise we must also replace the offending characters with safe escape
|
|
49
|
+
// sequences.
|
|
50
|
+
{
|
|
51
|
+
if (escapeable.test(string))
|
|
52
|
+
{
|
|
53
|
+
return '"' + string.replace(escapeable, function (a)
|
|
54
|
+
{
|
|
55
|
+
var c = meta[a];
|
|
56
|
+
if (typeof c === 'string') {
|
|
57
|
+
return c;
|
|
58
|
+
}
|
|
59
|
+
c = a.charCodeAt();
|
|
60
|
+
return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
|
|
61
|
+
}) + '"';
|
|
62
|
+
}
|
|
63
|
+
return '"' + string + '"';
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
$.toJSON = function(o, compact)
|
|
67
|
+
{
|
|
68
|
+
var type = typeof(o);
|
|
69
|
+
|
|
70
|
+
if (type == "undefined")
|
|
71
|
+
return "undefined";
|
|
72
|
+
else if (type == "number" || type == "boolean")
|
|
73
|
+
return o + "";
|
|
74
|
+
else if (o === null)
|
|
75
|
+
return "null";
|
|
76
|
+
|
|
77
|
+
// Is it a string?
|
|
78
|
+
if (type == "string")
|
|
79
|
+
{
|
|
80
|
+
return $.quoteString(o);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Does it have a .toJSON function?
|
|
84
|
+
if (type == "object" && typeof o.toJSON == "function")
|
|
85
|
+
return o.toJSON(compact);
|
|
86
|
+
|
|
87
|
+
// Is it an array?
|
|
88
|
+
if (type != "function" && typeof(o.length) == "number")
|
|
89
|
+
{
|
|
90
|
+
var ret = [];
|
|
91
|
+
for (var i = 0; i < o.length; i++) {
|
|
92
|
+
ret.push( $.toJSON(o[i], compact) );
|
|
93
|
+
}
|
|
94
|
+
if (compact)
|
|
95
|
+
return "[" + ret.join(",") + "]";
|
|
96
|
+
else
|
|
97
|
+
return "[" + ret.join(", ") + "]";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// If it's a function, we have to warn somebody!
|
|
101
|
+
if (type == "function") {
|
|
102
|
+
throw new TypeError("Unable to convert object of type 'function' to json.");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// It's probably an object, then.
|
|
106
|
+
var ret = [];
|
|
107
|
+
for (var k in o) {
|
|
108
|
+
var name;
|
|
109
|
+
type = typeof(k);
|
|
110
|
+
|
|
111
|
+
if (type == "number")
|
|
112
|
+
name = '"' + k + '"';
|
|
113
|
+
else if (type == "string")
|
|
114
|
+
name = $.quoteString(k);
|
|
115
|
+
else
|
|
116
|
+
continue; //skip non-string or number keys
|
|
117
|
+
|
|
118
|
+
var val = $.toJSON(o[k], compact);
|
|
119
|
+
if (typeof(val) != "string") {
|
|
120
|
+
// skip non-serializable values
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (compact)
|
|
125
|
+
ret.push(name + ":" + val);
|
|
126
|
+
else
|
|
127
|
+
ret.push(name + ": " + val);
|
|
128
|
+
}
|
|
129
|
+
return "{" + ret.join(", ") + "}";
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
$.compactJSON = function(o)
|
|
133
|
+
{
|
|
134
|
+
return $.toJSON(o, true);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
$.evalJSON = function(src)
|
|
138
|
+
// Evals JSON that we know to be safe.
|
|
139
|
+
{
|
|
140
|
+
return eval("(" + src + ")");
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
$.secureEvalJSON = function(src)
|
|
144
|
+
// Evals JSON in a way that is *more* secure.
|
|
145
|
+
{
|
|
146
|
+
var filtered = src;
|
|
147
|
+
filtered = filtered.replace(/\\["\\\/bfnrtu]/g, '@');
|
|
148
|
+
filtered = filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']');
|
|
149
|
+
filtered = filtered.replace(/(?:^|:|,)(?:\s*\[)+/g, '');
|
|
150
|
+
|
|
151
|
+
if (/^[\],:{}\s]*$/.test(filtered))
|
|
152
|
+
return eval("(" + src + ")");
|
|
153
|
+
else
|
|
154
|
+
throw new SyntaxError("Error parsing JSON, source is not valid.");
|
|
155
|
+
};
|
|
156
|
+
})(jQuery);
|
data/views/layout.erb
CHANGED
|
@@ -3,10 +3,18 @@
|
|
|
3
3
|
<meta content='text/html; charset=utf-8' http-equiv='Content-Type' />
|
|
4
4
|
<title>javascript_lab - a javascript editor and tester tool</title>
|
|
5
5
|
<link href='/stylesheets/style.css' media='screen' rel='stylesheet' type='text/css' />
|
|
6
|
+
|
|
7
|
+
<% if request.fullpath == '/validate_json' %>
|
|
8
|
+
<script src='/javascripts/jquery-1.3.2.js' type='text/javascript'></script>
|
|
9
|
+
<script src='/javascripts/jquery.json-1.3.js' type='text/javascript'></script>
|
|
10
|
+
<% end %>
|
|
11
|
+
|
|
6
12
|
<script src='/javascripts/app.js' type='text/javascript'></script>
|
|
13
|
+
|
|
7
14
|
<% if params[:j] %>
|
|
8
15
|
<script src='/javascripts/<%=params[:j]%>.js' type='text/javascript'></script>
|
|
9
16
|
<% end %>
|
|
17
|
+
|
|
10
18
|
</head>
|
|
11
19
|
<body>
|
|
12
20
|
<div id='container'>
|
|
@@ -19,12 +27,22 @@
|
|
|
19
27
|
<ul class='nav'>
|
|
20
28
|
<li><a href="http://neeraj.name">Gem author</a></li>
|
|
21
29
|
<li><a href="http://github.com/neerajdotname/javascript_lab">source code</a></li>
|
|
22
|
-
|
|
30
|
+
</ul>
|
|
23
31
|
</div>
|
|
24
32
|
<div style='clear:both;'></div>
|
|
25
33
|
</div>
|
|
26
34
|
|
|
27
35
|
<div id='main'>
|
|
36
|
+
<div>
|
|
37
|
+
<div style='float:right;'>
|
|
38
|
+
<% if request.fullpath == '/validate_json' %>
|
|
39
|
+
<a href='/'>Home</a>
|
|
40
|
+
<% else %>
|
|
41
|
+
<a href='/validate_json'>validate JSON</a>
|
|
42
|
+
<% end %>
|
|
43
|
+
</p>
|
|
44
|
+
<div style='clear:both;'></div>
|
|
45
|
+
</div>
|
|
28
46
|
<%= yield %>
|
|
29
47
|
</div>
|
|
30
48
|
</div>
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: neerajdotname-javascript_lab
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Neeraj Singh
|
|
@@ -80,6 +80,7 @@ files:
|
|
|
80
80
|
- public/javascripts/prototype-1.5.1.js
|
|
81
81
|
- public/javascripts/prototype-1.5.js
|
|
82
82
|
- public/javascripts/app.js
|
|
83
|
+
- public/javascripts/jquery.json-1.3.js
|
|
83
84
|
- views/style.sass
|
|
84
85
|
- views/index.erb
|
|
85
86
|
- views/layout.erb
|