Skip to content

Commit 1093e1c

Browse files
committed
move from '#' to '.' for object key matching
1 parent 5a25ac6 commit 1093e1c

File tree

12 files changed

+71
-53
lines changed

12 files changed

+71
-53
lines changed

site/css/style.css

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ div.content {
6363
.json {
6464
background-color: #333;
6565
padding: .5em 1em .5em 1em;
66+
border: 3px solid #444;
67+
border-radius: 1em;
68+
-moz-border-radius: 1em;
69+
-webkit-border-radius: 1em;
6670
}
6771

6872
#splash .sample {
6973
width: 250px;
7074
float: right;
7175
margin-left: 1em;
7276
margin-top: 3em;
73-
border: 3px solid #444;
74-
border-radius: 1em;
75-
-moz-border-radius: 1em;
76-
-webkit-border-radius: 1em;
7777
font-size: 90%;
7878
}
7979

@@ -132,10 +132,6 @@ pre.doc {
132132
float: right;
133133
padding: 1em 3em 1em 3em;
134134
padding-right: 160px;
135-
border: 3px solid #444;
136-
border-radius: 1em;
137-
-moz-border-radius: 1em;
138-
-webkit-border-radius: 1em;
139135
font-size: 90%;
140136
}
141137

@@ -170,4 +166,10 @@ pre.doc {
170166
color: #9f9;
171167
font-size: 90%;
172168
width: 300px;
173-
}
169+
}
170+
171+
#cred {
172+
padding-top: 2em;
173+
}
174+
175+
#cred > pre {

site/index.html

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<div id="header">
1010
<div class="content">
1111
<div class="title">json<b>:</b>select<b>()</b></div>
12-
<div class="nav"> <a href="#overview">Overview</a> | <a href="#tryit">Try It!</a> | <a href="#docs">Docs</a> | <a href="https://github.com/lloyd/JSONSelect">Code</a> | <a href="mailto:jsonselect@librelist.com">Contact</a> </div>
12+
<div class="nav"> <a href="#overview">Overview</a> | <a href="#tryit">Try It!</a> | <a href="#docs">Docs</a> | <a href="https://github.com/lloyd/JSONSelect">Code</a> | <a href="mailto:jsonselect@librelist.com">Contact</a> | <a href="#cred">Credit</a> </div>
1313
<div class="subtitle">CSS-like selectors for JSON.</div>
1414
</div>
1515
</div>
@@ -33,10 +33,10 @@
3333
"license": "<a href="http://creativecommons.org/licenses/by-sa/3.0/us/">(cc) BY-SA</a>"
3434
}</pre></div>
3535
<div class="pitch">
36-
<p>JSONSelect is a selector language for JSON.</p>
36+
<p>JSONSelect is an <i>experimental</i> selector language for JSON.</p>
37+
<p>It makes it easy to access data in complex JSON documents.</p>
3738
<p>It <i>feels like</i> CSS.</p>
38-
<p>It's easy to learn.</p>
39-
<p>You should <a href="#">give it a try</a>.
39+
<p>Why not <a href="#tryit">give it a try</a>?
4040
</div>
4141
</div>
4242
<div id="tryit" style="display: none" class="content">
@@ -67,23 +67,24 @@
6767
"aisle"
6868
],
6969
"drinkPreference": [
70-
"beer",
7170
"whiskey",
71+
"beer",
7272
"wine"
7373
],
7474
"weight": 172
7575
}
7676
</pre>
7777
<div class="selectors">
7878
<div class="title"> Choose A Selector... </div>
79-
<div class="selector">#languagesSpoken #language</div>
80-
<div class="selector">#drinkPreference :first-child</div>
79+
<div class="selector">.languagesSpoken .language</div>
80+
<div class="selector">.drinkPreference :first-child</div>
81+
<div class="selector">.name > *</div>
82+
<div class="selector">.seatingPreference :nth-child(1)</div>
8183
<div class="selector">string:first-child</div>
82-
<div class="selector">#name > #first, #name > #last</div>
83-
<div class="selector">#language</div>
84-
<div class="selector">#"weight"</div>
85-
<div class="selector">#favoriteColor</div>
86-
<div class="selector">string#favoriteColor</div>
84+
<div class="selector">."weight"</div>
85+
<div class="selector">.language</div>
86+
<div class="selector">.favoriteColor</div>
87+
<div class="selector">string.favoriteColor</div>
8788
<div class="selector">string:last-child</div>
8889
<div class="selector">string:nth-child(-n+2)</div>
8990
<div class="selector">string:nth-child(odd)</div>
@@ -94,6 +95,18 @@
9495
<div class="selector">string</div>
9596
</div>
9697
</div>
98+
<div style="display: none" id="cred" class="content">
99+
<p>JSONSelect is dedicated to sad code everywhere that looks like this:</p>
100+
<pre class="json">if (foo && foo.bar && foo.bar.baz && foo.bar.baz.length > 2)
101+
return foo.bar.baz[2];
102+
return undefined;</pre>
103+
<p>It was created by <a href="http://trickyco.de/">Lloyd Hilaiel</a>.</p>
104+
<p><a href="http://blog.mozilla.com/dherman/">Dave Herman</a> provided the name, and lots of encouragement.</p>
105+
<p><a href="http://open-mike.org/">Mike Hanson</a> gave deep feedback and ideas.</p>
106+
<p><a href="http://ejohn.org/">John Resig</a> unwittingly contributed his <a href="http://ejohn.org/blog/selectors-that-people-actually-use/">design thoughts</a>.</p>
107+
<p><a href="http://json.org/">JSON</a> and <a href="http://www.w3.org/TR/css3-selectors/">CSS3 Selectors</a> are the prerequisites to JSONSelect's existence, so thanks to you guys too.</p>
108+
<p></p>
109+
</div>
97110
</div>
98111

99112
<a href="https://github.com/lloyd/JSONSelect"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://d3nwyuy0nl342s.cloudfront.net/img/4c7dc970b89fd04b81c8e221ba88ff99a06c6b61/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f77686974655f6666666666662e706e67" alt="Fork me on GitHub"></a>

site/js/nav.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ $(document).ready(function() {
66
if (location.hash === "#tryit") {
77
$("#tryit input").val("").keyup();
88
$("#tryit").fadeIn(400, function() {
9-
$("#tryit input").val("#drinkPreference :first-child").keyup();
9+
$("#tryit input").val(".languagesSpoken .language").keyup();
1010
});
11+
} else if (location.hash === "#cred") {
12+
$("#main > .content").hide();
13+
$("#cred").fadeIn(400);
1114
} else {
1215
$("#splash").fadeIn(400);
1316
}
1417
});
1518

1619
// Trigger the event (useful on page load).
17-
$(window).hashchange();
20+
$(window).hashchange();
1821
});

src/jsonselect.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"nmi": "multiple ids not allowed",
1818
"pcny": "psuedo class functions not yet supported",
1919
"se": "selector expected",
20-
"sra": "string required after '#'",
20+
"sra": "string required after '.'",
2121
"uc": "unrecognized char",
2222
"ujs": "unclosed json string",
2323
"upc": "unrecognized psuedo class"
@@ -35,7 +35,7 @@
3535
str: 4, // string
3636
};
3737

38-
var pat = /^(?:([\r\n\t\ ]+)|([*#,>])|(string|boolean|null|array|object|number)|(:(?:root|first-child|last-child|only-child))|(:(?:nth-child|nth-last-child))|(:\w+)|(\"(?:[^\\]|\\[^\"])*\")|(\")|((?:[_a-zA-Z]|[^\0-\0177]|\\[^\r\n\f0-9a-fA-F])(?:[_a-zA-Z0-9-]|[^\u0000-\u0177]|(?:\\[^\r\n\f0-9a-fA-F]))*))/;
38+
var pat = /^(?:([\r\n\t\ ]+)|([*.,>])|(string|boolean|null|array|object|number)|(:(?:root|first-child|last-child|only-child))|(:(?:nth-child|nth-last-child))|(:\w+)|(\"(?:[^\\]|\\[^\"])*\")|(\")|((?:[_a-zA-Z]|[^\0-\0177]|\\[^\r\n\f0-9a-fA-F])(?:[_a-zA-Z0-9-]|[^\u0000-\u0177]|(?:\\[^\r\n\f0-9a-fA-F]))*))/;
3939
var exprPat = /^\s*\(\s*(?:([+-]?)([0-9]*)n\s*(?:([+-])\s*([0-9]))?|(odd|even)|([+-]?[0-9]+))\s*\)/;
4040
var lex = function (str, off) {
4141
if (!off) off = 0;
@@ -99,7 +99,7 @@
9999
while (true) {
100100
if (l === undefined) {
101101
break;
102-
} else if (l[1] === '#') {
102+
} else if (l[1] === '.') {
103103
l = lex(str, (off = l[0]));
104104
if (!l || l[1] !== toks.str) te("sra");
105105
if (s.id) te("nmi");

src/test/lex_test.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ <h2> Tests of the JSONSelect lexer </h2>
2424
[1, "*"]
2525
$ JSONSelect._lex(",");
2626
[1, ","]
27-
$ JSONSelect._lex("#");
28-
[1, "#"]
27+
$ JSONSelect._lex(".");
28+
[1, "."]
2929
</pre>
3030
</div>
3131

@@ -99,7 +99,7 @@ <h2> Tests of the JSONSelect lexer </h2>
9999
</div>
100100

101101
<div class="test">
102-
identifiers (like after '#')
102+
identifiers (like after '.')
103103
<pre class="doctest">
104104
$ JSONSelect._lex("foo");
105105
[3, 4, "foo"]

src/test/match_test.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ <h2> Tests of the JSONSelect matcher </h2>
3636
<div class="test">
3737
IDs
3838
<pre class="doctest">
39-
$ JSONSelect.match("#foo", {foo: "aMatch", bar: [ { foo: "anotherMatch" } ] });
39+
$ JSONSelect.match(".foo", {foo: "aMatch", bar: [ { foo: "anotherMatch" } ] });
4040
["aMatch", "anotherMatch"]
4141
</pre>
4242
</div>
4343

4444
<div class="test">
4545
Descendants
4646
<pre class="doctest">
47-
$ JSONSelect.match("#foo #bar", {foo: { baz: 1, bar: 2 }, bar: 3});
47+
$ JSONSelect.match(".foo .bar", {foo: { baz: 1, bar: 2 }, bar: 3});
4848
[2]
49-
$ JSONSelect.match("#foo > #bar", {foo: { baz: 1, bar: 2 }, bar: 3});
49+
$ JSONSelect.match(".foo > .bar", {foo: { baz: 1, bar: 2 }, bar: 3});
5050
[2]
51-
$ JSONSelect.match("#foo > #bar", {foo: { baz: { bar: 4 }, bar: 2 }, bar: 3});
51+
$ JSONSelect.match(".foo > .bar", {foo: { baz: { bar: 4 }, bar: 2 }, bar: 3});
5252
[2]
53-
$ JSONSelect.match("#foo #bar", {foo: { baz: { bar: 4 }, bar: 2 }, bar: 3});
53+
$ JSONSelect.match(".foo .bar", {foo: { baz: { bar: 4 }, bar: 2 }, bar: 3});
5454
[4, 2]
5555
</pre>
5656
</div>

src/test/parse_test.html

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ <h2> Tests of the JSONSelect parser </h2>
1818
<div class="test">
1919
Selectors
2020
<pre class="doctest">
21-
$ JSONSelect._parse("#foo");
21+
$ JSONSelect._parse(".foo");
2222
[{id: "foo"}]
23-
$ JSONSelect._parse('#" foo "');
23+
$ JSONSelect._parse('." foo "');
2424
[{id: " foo "}]
25-
$ JSONSelect._parse("string#foo:last-child");
25+
$ JSONSelect._parse("string.foo:last-child");
2626
[{a: 0, b: 1, id: "foo", pf: ":nth-last-child", type: "string"}]
27-
$ JSONSelect._parse("string#foo#bar");
27+
$ JSONSelect._parse("string.foo.bar");
2828
Error: multiple ids not allowed
29-
$ JSONSelect._parse("string#foo:first-child#bar");
29+
$ JSONSelect._parse("string.foo:first-child.bar");
3030
Error: multiple ids not allowed
31-
$ JSONSelect._parse("string:last-child#foo:first-child#bar");
31+
$ JSONSelect._parse("string:last-child.foo:first-child.bar");
3232
Error: multiple pseudo classes (:xxx) not allowed
33-
$ JSONSelect._parse("string#");
34-
Error: string required after '#'
33+
$ JSONSelect._parse("string.");
34+
Error: string required after '.'
3535
$ JSONSelect._parse("string:bogus");
3636
Error: unrecognized psuedo class
37-
$ JSONSelect._parse("string#xxx\\@yyy");
37+
$ JSONSelect._parse("string.xxx\\@yyy");
3838
[{id: "xxx@yyy", type: "string"}]
3939
$ JSONSelect._parse(" ");
4040
Error: selector expected
@@ -46,15 +46,15 @@ <h2> Tests of the JSONSelect parser </h2>
4646
<div class="test">
4747
Combinators
4848
<pre class="doctest">
49-
$ JSONSelect._parse("#foo #bar");
49+
$ JSONSelect._parse(".foo .bar");
5050
[{id: "foo"}, {id: "bar"}]
51-
$ JSONSelect._parse("string#foo , number#foo");
51+
$ JSONSelect._parse("string.foo , number.foo");
5252
[",", [{id: "foo", type: "string"}], [{id: "foo", type: "number"}]]
53-
$ JSONSelect._parse("string > #foo number#bar");
53+
$ JSONSelect._parse("string > .foo number.bar");
5454
[{type: "string"}, ">", {id: "foo"}, {id: "bar", type: "number"}]
55-
$ JSONSelect._parse("string > #foo number#bar, object");
55+
$ JSONSelect._parse("string > .foo number.bar, object");
5656
[",", [{type: "string"}, ">", {id: "foo"}, {id: "bar", type: "number"}], [{type: "object"}]]
57-
$ JSONSelect._parse("string > #foo number#bar, object, string, #\"baz bing\", :root");
57+
$ JSONSelect._parse("string > .foo number.bar, object, string, .\"baz bing\", :root");
5858
[
5959
",",
6060
[{type: "string"}, ">", {id: "foo"}, {id: "bar", type: "number"}],

tests/basic_grouping.selector

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
string#level,number
1+
string.level,number

tests/basic_id.selector

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#favoriteColor
1+
.favoriteColor

tests/basic_id_multiple.selector

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#language
1+
.language

0 commit comments

Comments
 (0)