jsont 0.1.0 → 0.1.1
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 +7 -3
- data/Rakefile +2 -4
- data/lib/jsont.rb +4 -7
- data/test/test_jsont.rb +49 -7
- metadata +7 -7
data/History.txt
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
== 0.
|
1
|
+
== 0.1.1 2008-11-27
|
2
2
|
|
3
|
-
*
|
4
|
-
|
3
|
+
* Removed JSON dependency. You'll have to parse the rules and input before you send it in.
|
4
|
+
* Fixed mixed case replacement expressions
|
5
|
+
|
6
|
+
== 0.1.0 2008-11-25
|
7
|
+
|
8
|
+
* Initial release
|
data/Rakefile
CHANGED
@@ -8,11 +8,9 @@ $hoe = Hoe.new('jsont', Jsont::VERSION) do |p|
|
|
8
8
|
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
9
|
p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
10
10
|
p.rubyforge_name = p.name # TODO this is default value
|
11
|
-
p.extra_deps = [
|
12
|
-
['json'],
|
13
|
-
]
|
14
11
|
p.extra_dev_deps = [
|
15
|
-
['newgem', ">= #{::Newgem::VERSION}"]
|
12
|
+
['newgem', ">= #{::Newgem::VERSION}"],
|
13
|
+
['json']
|
16
14
|
]
|
17
15
|
|
18
16
|
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
data/lib/jsont.rb
CHANGED
@@ -1,14 +1,11 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
|
-
require 'rubygems'
|
5
|
-
require 'json'
|
6
|
-
|
7
4
|
class Jsont
|
8
|
-
VERSION = '0.1.
|
5
|
+
VERSION = '0.1.1'
|
9
6
|
|
10
7
|
def initialize(rules)
|
11
|
-
@rules = rules
|
8
|
+
@rules = rules
|
12
9
|
@rules.each do |r,v|
|
13
10
|
if r[0,4] != 'self'
|
14
11
|
@rules["self.#{r}"] = @rules.delete(r)
|
@@ -17,7 +14,7 @@ class Jsont
|
|
17
14
|
end
|
18
15
|
|
19
16
|
def transform(target)
|
20
|
-
@parent = target
|
17
|
+
@parent = target
|
21
18
|
apply!('self',@parent)
|
22
19
|
end
|
23
20
|
|
@@ -34,7 +31,7 @@ class Jsont
|
|
34
31
|
end
|
35
32
|
|
36
33
|
if (rule = @rules[target_path])
|
37
|
-
rule.gsub(/\{([a-z0-9\$\.]+)\}/) do |match|
|
34
|
+
rule.gsub(/\{([a-z0-9\$\.]+)\}/i) do |match|
|
38
35
|
path = match[1,match.size - 2]
|
39
36
|
n = case path[0]
|
40
37
|
when ?$
|
data/test/test_jsont.rb
CHANGED
@@ -1,30 +1,72 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
2
|
+
require 'json'
|
3
3
|
class TestJsont < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def setup
|
6
6
|
end
|
7
7
|
|
8
8
|
def test_expressions
|
9
|
-
assert_equal(Jsont.new('{ "self": "<table>{pnt}</table>", "pnt": "<tr><td>{pnt.x}</td><td>{pnt.y}</td></tr>" }').transform('{"pnt": { "x":2, "y":3 }}'), '<table><tr><td>2</td><td>3</td></tr></table>')
|
9
|
+
assert_equal(Jsont.new(JSON.parse('{ "self": "<table>{pnt}</table>", "pnt": "<tr><td>{pnt.x}</td><td>{pnt.y}</td></tr>" }')).transform(JSON.parse('{"pnt": { "x":2, "y":3 }}')), '<table><tr><td>2</td><td>3</td></tr></table>')
|
10
10
|
|
11
|
-
assert_equal(Jsont.new('{ "self": "<table><tr>{$}</tr></table>","self[*]": "<td>{$}</td>" }').transform('[1,2]'), '<table><tr><td>1</td><td>2</td></tr></table>')
|
11
|
+
assert_equal(Jsont.new(JSON.parse('{ "self": "<table><tr>{$}</tr></table>","self[*]": "<td>{$}</td>" }')).transform(JSON.parse('[1,2]')), '<table><tr><td>1</td><td>2</td></tr></table>')
|
12
12
|
|
13
|
-
assert_equal(Jsont.new('{ "self": "<table>\n{$}\n</table>",
|
13
|
+
assert_equal(Jsont.new(JSON.parse('{ "self": "<table>\n{$}\n</table>",
|
14
14
|
"self[*]": "<tr>{$}</tr>\n",
|
15
|
-
"self[*][*]": "<td>{$}</td>" }').transform('[[1,2],[3,4]]'), '<table>
|
15
|
+
"self[*][*]": "<td>{$}</td>" }')).transform(JSON.parse('[[1,2],[3,4]]')), '<table>
|
16
16
|
<tr><td>1</td><td>2</td></tr>
|
17
17
|
<tr><td>3</td><td>4</td></tr>
|
18
18
|
|
19
19
|
</table>')
|
20
20
|
|
21
|
-
assert_equal(Jsont.new('{"self": "<div>\n{p}\n</div>", "p": "<table><tr>{$}</tr></table>\n", "p[*]": "<td>{$.x}</td><td>{$.y}</td>"}').transform('{"a":"hello", "p":[{"x":1, "y":2},{"x":3, "y":4}]}'),'<div>
|
21
|
+
assert_equal(Jsont.new(JSON.parse('{"self": "<div>\n{p}\n</div>", "p": "<table><tr>{$}</tr></table>\n", "p[*]": "<td>{$.x}</td><td>{$.y}</td>"}')).transform(JSON.parse('{"a":"hello", "p":[{"x":1, "y":2},{"x":3, "y":4}]}')),'<div>
|
22
22
|
<table><tr><td>1</td><td>2</td><td>3</td><td>4</td></tr></table>
|
23
23
|
|
24
24
|
</div>')
|
25
25
|
|
26
|
-
assert_equal(Jsont.new('{ "self": "<a href=\"{uri}\" title=\'{title}\'>{$.title}</a>" }').transform('{ "uri":"http://somewhere.org", "title":"somewhere homepage" }'), '<a href="http://somewhere.org" title=\'somewhere homepage\'>somewhere homepage</a>')
|
26
|
+
assert_equal(Jsont.new(JSON.parse('{ "self": "<a href=\"{uri}\" title=\'{title}\'>{$.title}</a>" }')).transform(JSON.parse('{ "uri":"http://somewhere.org", "title":"somewhere homepage" }')), '<a href="http://somewhere.org" title=\'somewhere homepage\'>somewhere homepage</a>')
|
27
27
|
|
28
28
|
assert_equal(Jsont.new({'self' => '<div>{$.test}</div>', 'test' => '<p>{$.x} {$.y}</p>'}).transform({'test' => {'x' => 1, 'y' => 2}}), '<div><p>1 2</p></div>')
|
29
|
+
|
30
|
+
assert_equal(Jsont.new({
|
31
|
+
"self" => "<div id=\"topNav\">{$.mainNav}{$.subNav}</div>",
|
32
|
+
"mainNav" => "<ul id=\"mainNav\">{$.menus}</ul>",
|
33
|
+
"mainNav.menus[*]" => "<li class=\"dropdown {$.class}\"><a class=\"navLabel\" href=\"{$.url}\">{$.label}</a>\n<ul class=\"clearfix\">{$.items}</ul></li>",
|
34
|
+
"mainNav.menus[*].items[*]" => "<li class=\"dropDownItem\"><a href=\"{$.url}\">{$.label}</a></li>",
|
35
|
+
"subNav" => "<ul id=\"subNav\">{$.menus}</ul>",
|
36
|
+
"subNav.menus[*]" => "<div class=\"{$.class}\">{$.items}</div>",
|
37
|
+
"subNav.menus[*].items[*]" => "<li><a class=\"{$.class}\" href=\"{$.url}\">{$.label}</a></li>"
|
38
|
+
}).transform({
|
39
|
+
"mainNav"=> {
|
40
|
+
"menus"=> [
|
41
|
+
{ "label"=> "Research", "url"=> "http://localhost/research/databases.php", "class"=> "research", "items"=> [
|
42
|
+
{"url"=> "http://localhost/research/databases.php", "label"=> "Databases"},
|
43
|
+
{"url"=> "http://localhost/research/homework-help.php", "label"=> "Homework Help"},
|
44
|
+
{"url"=> "http://localhost/research/government.php", "label"=> "Government"},
|
45
|
+
{"url"=> "http://localhost/research/local-history.php", "label"=> "Local/Family History"},
|
46
|
+
{"url"=> "http://localhost/research/teacher-resources.php", "label"=> "Teacher Resources"},
|
47
|
+
{"url"=> "http://localhost/research/business.php", "label"=> "Business"},
|
48
|
+
{"url"=> "http://localhost/research/investing.php", "label"=> "Investing"},
|
49
|
+
{"url"=> "http://localhost/research/careers.php", "label"=> "Careers"}
|
50
|
+
] }
|
51
|
+
] },
|
52
|
+
"subNav"=> {
|
53
|
+
"menus"=> [
|
54
|
+
{ "class"=> "research", "items"=> [
|
55
|
+
{"url"=> "http://localhost/research/databases.php", "label"=> "Databases"},
|
56
|
+
{"url"=> "http://localhost/research/homework-help.php", "label"=> "Homework Help"},
|
57
|
+
{"url"=> "http://localhost/research/government.php", "label"=> "Government"},
|
58
|
+
{"url"=> "http://localhost/research/local-history.php", "label"=> "Local/Family History"},
|
59
|
+
{"url"=> "http://localhost/research/teacher-resources.php", "label"=> "Teacher Resources"},
|
60
|
+
{"url"=> "http://localhost/research/business.php", "label"=> "Business"},
|
61
|
+
{"url"=> "http://localhost/research/investing.php", "label"=> "Investing"},
|
62
|
+
{"url"=> "http://localhost/research/careers.php", "label"=> "Careers"}
|
63
|
+
]
|
64
|
+
} ]
|
65
|
+
}
|
66
|
+
}), '<div id="topNav"><ul id="mainNav"><li class="dropdown research"><a class="navLabel" href="http://localhost/research/databases.php">Research</a>
|
67
|
+
<ul class="clearfix"><li class="dropDownItem"><a href="http://localhost/research/databases.php">Databases</a></li><li class="dropDownItem"><a href="http://localhost/research/homework-help.php">Homework Help</a></li><li class="dropDownItem"><a href="http://localhost/research/government.php">Government</a></li><li class="dropDownItem"><a href="http://localhost/research/local-history.php">Local/Family History</a></li><li class="dropDownItem"><a href="http://localhost/research/teacher-resources.php">Teacher Resources</a></li><li class="dropDownItem"><a href="http://localhost/research/business.php">Business</a></li><li class="dropDownItem"><a href="http://localhost/research/investing.php">Investing</a></li><li class="dropDownItem"><a href="http://localhost/research/careers.php">Careers</a></li></ul></li></ul><ul id="subNav"><div class="research"><li><a class="" href="http://localhost/research/databases.php">Databases</a></li><li><a class="" href="http://localhost/research/homework-help.php">Homework Help</a></li><li><a class="" href="http://localhost/research/government.php">Government</a></li><li><a class="" href="http://localhost/research/local-history.php">Local/Family History</a></li><li><a class="" href="http://localhost/research/teacher-resources.php">Teacher Resources</a></li><li><a class="" href="http://localhost/research/business.php">Business</a></li><li><a class="" href="http://localhost/research/investing.php">Investing</a></li><li><a class="" href="http://localhost/research/careers.php">Careers</a></li></div></ul></div>')
|
68
|
+
|
69
|
+
|
70
|
+
|
29
71
|
end
|
30
72
|
end
|
metadata
CHANGED
@@ -50,13 +50,13 @@ rubygems_version: 1.2.0
|
|
50
50
|
requirements: []
|
51
51
|
authors:
|
52
52
|
- FIXME full name
|
53
|
-
date: 2008-11-
|
53
|
+
date: 2008-11-27 05:00:00 +00:00
|
54
54
|
platform: ruby
|
55
55
|
test_files:
|
56
56
|
- test/test_helper.rb
|
57
57
|
- test/test_jsont.rb
|
58
58
|
version: !ruby/object:Gem::Version
|
59
|
-
version: 0.1.
|
59
|
+
version: 0.1.1
|
60
60
|
require_paths:
|
61
61
|
- lib
|
62
62
|
dependencies:
|
@@ -65,21 +65,21 @@ dependencies:
|
|
65
65
|
requirements:
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 1.1.0
|
69
69
|
version:
|
70
|
-
type: :
|
70
|
+
type: :development
|
71
71
|
version_requirement:
|
72
|
-
name:
|
72
|
+
name: newgem
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
74
|
version_requirements: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
76
|
- - '>='
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
78
|
+
version: !str 0
|
79
79
|
version:
|
80
80
|
type: :development
|
81
81
|
version_requirement:
|
82
|
-
name:
|
82
|
+
name: json
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|