jsont 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/README.rdoc +5 -2
- data/Rakefile +1 -4
- data/lib/jsont.rb +22 -18
- data/test/test_jsont.rb +7 -0
- metadata +1 -21
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -8,12 +8,15 @@ Port of javascript JsonT transformation library. http://goessner.net/articles/js
|
|
8
8
|
|
9
9
|
== FEATURES/PROBLEMS:
|
10
10
|
|
11
|
-
Conforms to most of the JsonT spec minus the javascript function ability.
|
11
|
+
Conforms to most of the JsonT spec minus the javascript function ability. (Have to use Proc's instead)
|
12
12
|
|
13
13
|
== SYNOPSIS:
|
14
14
|
|
15
15
|
Jsont.new({'self' => '<div>{$.test}</div>', 'test' => '<p>{$.x} {$.y}</p>'}).transform({'test' => {'x' => 1, 'y' => 2}})
|
16
|
-
|
16
|
+
=> <div><p>1 2</p></div>
|
17
|
+
|
18
|
+
Jsont.new({'self' => '<div>{$.test}</div>', 'test' => Proc.new{|t, opts| t['x']+t['y']}}).transform({'test' => {'x' => 1, 'y' => 2}})
|
19
|
+
=> <div>3</div>
|
17
20
|
|
18
21
|
== INSTALL:
|
19
22
|
|
data/Rakefile
CHANGED
@@ -8,10 +8,7 @@ $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_dev_deps = [
|
12
|
-
['newgem', ">= #{::Newgem::VERSION}"],
|
13
|
-
['json']
|
14
|
-
]
|
11
|
+
p.extra_dev_deps = []
|
15
12
|
|
16
13
|
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
17
14
|
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
data/lib/jsont.rb
CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
4
|
class Jsont
|
5
|
-
VERSION = '0.1.
|
5
|
+
VERSION = '0.1.2'
|
6
6
|
|
7
7
|
def initialize(rules)
|
8
8
|
@rules = rules
|
@@ -31,27 +31,31 @@ class Jsont
|
|
31
31
|
end
|
32
32
|
|
33
33
|
if (rule = @rules[target_path])
|
34
|
-
rule.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
34
|
+
if rule.respond_to?(:call)
|
35
|
+
rule.call(target, :target_path => target_path)
|
36
|
+
else
|
37
|
+
rule.gsub(/\{([a-z0-9\$\.]+)\}/i) do |match|
|
38
|
+
path = match[1,match.size - 2]
|
39
|
+
n = case path[0]
|
40
|
+
when ?$
|
41
|
+
target
|
42
|
+
else
|
43
|
+
@parent
|
44
|
+
end
|
45
|
+
path.gsub!(/^\$\.?/,'')
|
43
46
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
if path.size > 0
|
48
|
+
path.split('.').each do |piece|
|
49
|
+
n = case piece
|
50
|
+
when /^[0-9]+$/
|
51
|
+
n[Integer(piece)]
|
52
|
+
else
|
53
|
+
n[piece]
|
54
|
+
end
|
51
55
|
end
|
52
56
|
end
|
57
|
+
n
|
53
58
|
end
|
54
|
-
n
|
55
59
|
end
|
56
60
|
else
|
57
61
|
target
|
data/test/test_jsont.rb
CHANGED
@@ -66,6 +66,13 @@ class TestJsont < Test::Unit::TestCase
|
|
66
66
|
}), '<div id="topNav"><ul id="mainNav"><li class="dropdown research"><a class="navLabel" href="http://localhost/research/databases.php">Research</a>
|
67
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
68
|
|
69
|
+
assert_equal(
|
70
|
+
Jsont.new(
|
71
|
+
{'self' => '<div>{$.test}</div>',
|
72
|
+
'test' => Proc.new{|t, opts| t['x']+t['y']}}
|
73
|
+
).transform(
|
74
|
+
{'test' => {'x' => 1, 'y' => 2}}
|
75
|
+
), '<div>3</div>')
|
69
76
|
|
70
77
|
|
71
78
|
end
|
metadata
CHANGED
@@ -56,30 +56,10 @@ 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.2
|
60
60
|
require_paths:
|
61
61
|
- lib
|
62
62
|
dependencies:
|
63
|
-
- !ruby/object:Gem::Dependency
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '>='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 1.1.0
|
69
|
-
version:
|
70
|
-
type: :development
|
71
|
-
version_requirement:
|
72
|
-
name: newgem
|
73
|
-
- !ruby/object:Gem::Dependency
|
74
|
-
version_requirements: !ruby/object:Gem::Requirement
|
75
|
-
requirements:
|
76
|
-
- - '>='
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version: !str 0
|
79
|
-
version:
|
80
|
-
type: :development
|
81
|
-
version_requirement:
|
82
|
-
name: json
|
83
63
|
- !ruby/object:Gem::Dependency
|
84
64
|
version_requirements: !ruby/object:Gem::Requirement
|
85
65
|
requirements:
|