jsont 0.1.2 → 0.1.3

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.
@@ -1,3 +1,7 @@
1
+ == 0.1.3 2008-12-14
2
+
3
+ * Changed tests to rspec. fixed constant name to JsonT
4
+
1
5
  == 0.1.2 2008-11-27
2
6
 
3
7
  * Added Proc support for rules
@@ -1,11 +1,6 @@
1
1
  History.txt
2
- Manifest.txt
3
- PostInstall.txt
4
- README.rdoc
2
+ README.txt
5
3
  Rakefile
6
4
  lib/jsont.rb
7
- script/console
8
- script/destroy
9
- script/generate
10
- test/test_helper.rb
11
- test/test_jsont.rb
5
+ spec/jsont.rb
6
+ spec/spec.opts
@@ -0,0 +1,21 @@
1
+ = JsonT
2
+
3
+ == DESCRIPTION:
4
+
5
+ Port of javascript JsonT transformation library. http://goessner.net/articles/jsont/
6
+
7
+ == FEATURES/PROBLEMS:
8
+
9
+ Conforms to most of the JsonT spec minus the javascript function ability. (Have to use Proc's instead of javascript function)
10
+
11
+ == SYNOPSIS:
12
+
13
+ JsonT.new({'self' = > '<div>{$.test}</div>', 'test' = > '<p>{$.x} {$.y}</p>'}).transform({'test' = > {'x' = > 1, 'y' = > 2}})
14
+ = > <div><p>1 2</p></div>
15
+
16
+ JsonT.new({'self' = > '<div>{$.test}</div>', 'test' = > Proc.new{|t, opts| t['x']+t['y']}}).transform({'test' = > {'x' = > 1, 'y' = > 2}})
17
+ = > <div>3</div>
18
+
19
+ == INSTALL:
20
+
21
+ sudo gem install jsont
data/Rakefile CHANGED
@@ -1,23 +1,34 @@
1
- %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
- require File.dirname(__FILE__) + '/lib/jsont'
1
+ require 'rake/testtask'
3
2
 
4
- # Generate all the Rake tasks
5
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
- $hoe = Hoe.new('jsont', Jsont::VERSION) do |p|
7
- p.developer('FIXME full name', 'FIXME email')
8
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
- p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
10
- p.rubyforge_name = p.name # TODO this is default value
11
- p.extra_dev_deps = []
12
-
13
- p.clean_globs |= %w[**/.DS_Store tmp *.log]
14
- path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
15
- p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
16
- p.rsync_args = '-av --delete --ignore-errors'
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |s|
6
+ s.name = "jsont"
7
+ s.description = s.summary = "Ruby implementation of http://goessner.net/articles/jsont/"
8
+ s.email = "joshbuddy@gmail.com"
9
+ s.homepage = "http://github.com/joshbuddy/jsont"
10
+ s.authors = ['Joshua Hull']
11
+ s.files = FileList["[A-Z]*", "{lib,spec}/**/*"]
12
+ end
13
+ Jeweler::GemcutterTasks.new
14
+ rescue LoadError
15
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
17
16
  end
18
17
 
19
- require 'newgem/tasks' # load /tasks/*.rake
20
- Dir['tasks/**/*.rake'].each { |t| load t }
18
+ require 'rake/rdoctask'
19
+ desc "Generate documentation"
20
+ Rake::RDocTask.new do |rd|
21
+ rd.main = "README.rdoc"
22
+ rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
23
+ rd.rdoc_dir = 'rdoc'
24
+ end
25
+
26
+ require 'rubygems'
27
+ require 'spec'
28
+ require 'spec/rake/spectask'
21
29
 
22
- # TODO - want other tests/tasks run by default? Add them to the list
23
- # task :default => [:spec, :features]
30
+ Spec::Rake::SpecTask.new do |t|
31
+ t.spec_opts ||= []
32
+ t.spec_opts << "--options" << "spec/spec.opts"
33
+ t.spec_files = FileList['spec/*.rb']
34
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.3
@@ -1,8 +1,8 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
- class Jsont
5
- VERSION = '0.1.2'
4
+ class JsonT
5
+ VERSION = '0.1.3'
6
6
 
7
7
  def initialize(rules)
8
8
  @rules = rules
@@ -0,0 +1,14 @@
1
+ require "rubygems"
2
+ require 'lib/jsont.rb'
3
+ require 'json'
4
+ describe "JsonT with arrays" do
5
+
6
+ it "should transform" do
7
+ JsonT.new(
8
+ JSON.parse('{ "self": "<table><tr>{$}</tr></table>","self[*]": "<td>{$}</td>" }')
9
+ ).transform(
10
+ JSON.parse('[1,2]')
11
+ ).should == '<table><tr><td>1</td><td>2</td></tr></table>'
12
+ end
13
+
14
+ end
@@ -0,0 +1,23 @@
1
+ require "rubygems"
2
+ require 'lib/jsont.rb'
3
+ require 'json'
4
+ describe "JsonT was a hash" do
5
+
6
+ it "should use $ references" do
7
+ JsonT.new(
8
+ {'self' => '<div>{$.test}</div>', 'test' => '<p>{$.x} {$.y}</p>'}
9
+ ).transform(
10
+ {'test' => {'x' => 1, 'y' => 2}}
11
+ ).should == '<div><p>1 2</p></div>'
12
+ end
13
+
14
+ it "should transform" do
15
+ JsonT.new(
16
+ JSON.parse('{ "self": "<table>{pnt}</table>", "pnt": "<tr><td>{pnt.x}</td><td>{pnt.y}</td></tr>" }')
17
+ ).transform(
18
+ JSON.parse('{"pnt": { "x":2, "y":3 }}')
19
+ ).should == '<table><tr><td>2</td><td>3</td></tr></table>'
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,14 @@
1
+ require "rubygems"
2
+ require 'lib/jsont.rb'
3
+ require 'json'
4
+ describe "JsonT with a multi-dimensional array" do
5
+
6
+ it "should transform" do
7
+ JsonT.new(
8
+ JSON.parse('{ "self": "<table>\n{$}\n</table>", "self[*]": "<tr>{$}</tr>\n", "self[*][*]": "<td>{$}</td>" }')
9
+ ).transform(
10
+ JSON.parse('[[1,2],[3,4]]')
11
+ ).should == "<table>\n<tr><td>1</td><td>2</td></tr>\n<tr><td>3</td><td>4</td></tr>\n\n</table>"
12
+ end
13
+
14
+ end
@@ -0,0 +1,14 @@
1
+ require "rubygems"
2
+ require 'lib/jsont.rb'
3
+ require 'json'
4
+ describe "JsonT with procs" do
5
+
6
+ it "should transform" do
7
+ JsonT.new(
8
+ {'self' => '<div>{$.test}</div>', 'test' => Proc.new{|t, opts| t['x']+t['y']}}
9
+ ).transform(
10
+ {'test' => {'x' => 1, 'y' => 2}}
11
+ ).should == '<div>3</div>'
12
+ end
13
+
14
+ end
@@ -0,0 +1,7 @@
1
+ --colour
2
+ --format
3
+ specdoc
4
+ --loadby
5
+ mtime
6
+ --reverse
7
+ --backtrace
metadata CHANGED
@@ -1,74 +1,68 @@
1
- --- !ruby/object:Gem::Specification
2
- required_ruby_version: !ruby/object:Gem::Requirement
3
- requirements:
4
- - - '>='
5
- - !ruby/object:Gem::Version
6
- version: !str 0
7
- version:
8
- email:
9
- - FIXME email
10
- cert_chain: []
11
- summary: Port of javascript JsonT transformation library
12
- post_install_message: PostInstall.txt
13
- extra_rdoc_files:
14
- - History.txt
15
- - Manifest.txt
16
- - PostInstall.txt
17
- - README.rdoc
18
- homepage: http://jsonp.rubyforge.org
19
- signing_key:
1
+ --- !ruby/object:Gem::Specification
20
2
  name: jsont
21
- rdoc_options:
22
- - --main
23
- - README.rdoc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Joshua Hull
24
8
  autorequire:
25
- rubyforge_project: jsont
26
- executables: []
27
- description: Port of javascript JsonT transformation library. http://goessner.net/articles/jsont/
28
- specification_version: 2
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-25 00:00:00 -05:00
29
13
  default_executable:
14
+ dependencies: []
15
+
16
+ description: Ruby implementation of http://goessner.net/articles/jsont/
17
+ email: joshbuddy@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.txt
30
24
  files:
31
25
  - History.txt
32
26
  - Manifest.txt
33
- - PostInstall.txt
34
- - README.rdoc
27
+ - README.txt
35
28
  - Rakefile
29
+ - VERSION
36
30
  - lib/jsont.rb
37
- - script/console
38
- - script/destroy
39
- - script/generate
40
- - test/test_helper.rb
41
- - test/test_jsont.rb
42
- required_rubygems_version: !ruby/object:Gem::Requirement
31
+ - spec/array.rb
32
+ - spec/hash.rb
33
+ - spec/multiarray.rb
34
+ - spec/proc.rb
35
+ - spec/spec.opts
36
+ has_rdoc: true
37
+ homepage: http://github.com/joshbuddy/jsont
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
43
46
  requirements:
44
- - - '>='
45
- - !ruby/object:Gem::Version
46
- version: !str 0
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
47
56
  version:
48
- extensions: []
49
- rubygems_version: 1.2.0
50
57
  requirements: []
51
- authors:
52
- - FIXME full name
53
- date: 2008-11-27 05:00:00 +00:00
54
- platform: ruby
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.5
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Ruby implementation of http://goessner.net/articles/jsont/
55
64
  test_files:
56
- - test/test_helper.rb
57
- - test/test_jsont.rb
58
- version: !ruby/object:Gem::Version
59
- version: 0.1.2
60
- require_paths:
61
- - lib
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.8.0
69
- version:
70
- type: :development
71
- version_requirement:
72
- name: hoe
73
- bindir: bin
74
- has_rdoc: true
65
+ - spec/array.rb
66
+ - spec/hash.rb
67
+ - spec/multiarray.rb
68
+ - spec/proc.rb
@@ -1,7 +0,0 @@
1
-
2
- For more information on jsont, see http://jsont.rubyforge.org
3
-
4
- NOTE: Change this information in PostInstall.txt
5
- You can also delete it if you don't want it.
6
-
7
-
@@ -1,191 +0,0 @@
1
- = jsont
2
-
3
- http://jsonp.rubyforge.org
4
-
5
- == DESCRIPTION:
6
-
7
- Port of javascript JsonT transformation library. http://goessner.net/articles/jsont/
8
-
9
- == FEATURES/PROBLEMS:
10
-
11
- Conforms to most of the JsonT spec minus the javascript function ability. (Have to use Proc's instead)
12
-
13
- == SYNOPSIS:
14
-
15
- Jsont.new({'self' => '<div>{$.test}</div>', 'test' => '<p>{$.x} {$.y}</p>'}).transform({'test' => {'x' => 1, 'y' => 2}})
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>
20
-
21
- == INSTALL:
22
-
23
- sudo gem install jsont
24
-
25
- == LICENSE:
26
-
27
- GNU LESSER GENERAL PUBLIC LICENSE
28
- Version 3, 29 June 2007
29
-
30
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
31
- Everyone is permitted to copy and distribute verbatim copies
32
- of this license document, but changing it is not allowed.
33
-
34
-
35
- This version of the GNU Lesser General Public License incorporates
36
- the terms and conditions of version 3 of the GNU General Public
37
- License, supplemented by the additional permissions listed below.
38
-
39
- 0. Additional Definitions.
40
-
41
- As used herein, "this License" refers to version 3 of the GNU Lesser
42
- General Public License, and the "GNU GPL" refers to version 3 of the GNU
43
- General Public License.
44
-
45
- "The Library" refers to a covered work governed by this License,
46
- other than an Application or a Combined Work as defined below.
47
-
48
- An "Application" is any work that makes use of an interface provided
49
- by the Library, but which is not otherwise based on the Library.
50
- Defining a subclass of a class defined by the Library is deemed a mode
51
- of using an interface provided by the Library.
52
-
53
- A "Combined Work" is a work produced by combining or linking an
54
- Application with the Library. The particular version of the Library
55
- with which the Combined Work was made is also called the "Linked
56
- Version".
57
-
58
- The "Minimal Corresponding Source" for a Combined Work means the
59
- Corresponding Source for the Combined Work, excluding any source code
60
- for portions of the Combined Work that, considered in isolation, are
61
- based on the Application, and not on the Linked Version.
62
-
63
- The "Corresponding Application Code" for a Combined Work means the
64
- object code and/or source code for the Application, including any data
65
- and utility programs needed for reproducing the Combined Work from the
66
- Application, but excluding the System Libraries of the Combined Work.
67
-
68
- 1. Exception to Section 3 of the GNU GPL.
69
-
70
- You may convey a covered work under sections 3 and 4 of this License
71
- without being bound by section 3 of the GNU GPL.
72
-
73
- 2. Conveying Modified Versions.
74
-
75
- If you modify a copy of the Library, and, in your modifications, a
76
- facility refers to a function or data to be supplied by an Application
77
- that uses the facility (other than as an argument passed when the
78
- facility is invoked), then you may convey a copy of the modified
79
- version:
80
-
81
- a) under this License, provided that you make a good faith effort to
82
- ensure that, in the event an Application does not supply the
83
- function or data, the facility still operates, and performs
84
- whatever part of its purpose remains meaningful, or
85
-
86
- b) under the GNU GPL, with none of the additional permissions of
87
- this License applicable to that copy.
88
-
89
- 3. Object Code Incorporating Material from Library Header Files.
90
-
91
- The object code form of an Application may incorporate material from
92
- a header file that is part of the Library. You may convey such object
93
- code under terms of your choice, provided that, if the incorporated
94
- material is not limited to numerical parameters, data structure
95
- layouts and accessors, or small macros, inline functions and templates
96
- (ten or fewer lines in length), you do both of the following:
97
-
98
- a) Give prominent notice with each copy of the object code that the
99
- Library is used in it and that the Library and its use are
100
- covered by this License.
101
-
102
- b) Accompany the object code with a copy of the GNU GPL and this license
103
- document.
104
-
105
- 4. Combined Works.
106
-
107
- You may convey a Combined Work under terms of your choice that,
108
- taken together, effectively do not restrict modification of the
109
- portions of the Library contained in the Combined Work and reverse
110
- engineering for debugging such modifications, if you also do each of
111
- the following:
112
-
113
- a) Give prominent notice with each copy of the Combined Work that
114
- the Library is used in it and that the Library and its use are
115
- covered by this License.
116
-
117
- b) Accompany the Combined Work with a copy of the GNU GPL and this license
118
- document.
119
-
120
- c) For a Combined Work that displays copyright notices during
121
- execution, include the copyright notice for the Library among
122
- these notices, as well as a reference directing the user to the
123
- copies of the GNU GPL and this license document.
124
-
125
- d) Do one of the following:
126
-
127
- 0) Convey the Minimal Corresponding Source under the terms of this
128
- License, and the Corresponding Application Code in a form
129
- suitable for, and under terms that permit, the user to
130
- recombine or relink the Application with a modified version of
131
- the Linked Version to produce a modified Combined Work, in the
132
- manner specified by section 6 of the GNU GPL for conveying
133
- Corresponding Source.
134
-
135
- 1) Use a suitable shared library mechanism for linking with the
136
- Library. A suitable mechanism is one that (a) uses at run time
137
- a copy of the Library already present on the user's computer
138
- system, and (b) will operate properly with a modified version
139
- of the Library that is interface-compatible with the Linked
140
- Version.
141
-
142
- e) Provide Installation Information, but only if you would otherwise
143
- be required to provide such information under section 6 of the
144
- GNU GPL, and only to the extent that such information is
145
- necessary to install and execute a modified version of the
146
- Combined Work produced by recombining or relinking the
147
- Application with a modified version of the Linked Version. (If
148
- you use option 4d0, the Installation Information must accompany
149
- the Minimal Corresponding Source and Corresponding Application
150
- Code. If you use option 4d1, you must provide the Installation
151
- Information in the manner specified by section 6 of the GNU GPL
152
- for conveying Corresponding Source.)
153
-
154
- 5. Combined Libraries.
155
-
156
- You may place library facilities that are a work based on the
157
- Library side by side in a single library together with other library
158
- facilities that are not Applications and are not covered by this
159
- License, and convey such a combined library under terms of your
160
- choice, if you do both of the following:
161
-
162
- a) Accompany the combined library with a copy of the same work based
163
- on the Library, uncombined with any other library facilities,
164
- conveyed under the terms of this License.
165
-
166
- b) Give prominent notice with the combined library that part of it
167
- is a work based on the Library, and explaining where to find the
168
- accompanying uncombined form of the same work.
169
-
170
- 6. Revised Versions of the GNU Lesser General Public License.
171
-
172
- The Free Software Foundation may publish revised and/or new versions
173
- of the GNU Lesser General Public License from time to time. Such new
174
- versions will be similar in spirit to the present version, but may
175
- differ in detail to address new problems or concerns.
176
-
177
- Each version is given a distinguishing version number. If the
178
- Library as you received it specifies that a certain numbered version
179
- of the GNU Lesser General Public License "or any later version"
180
- applies to it, you have the option of following the terms and
181
- conditions either of that published version or of any later version
182
- published by the Free Software Foundation. If the Library as you
183
- received it does not specify a version number of the GNU Lesser
184
- General Public License, you may choose any version of the GNU Lesser
185
- General Public License ever published by the Free Software Foundation.
186
-
187
- If the Library as you received it specifies that a proxy can decide
188
- whether future versions of the GNU Lesser General Public License shall
189
- apply, that proxy's public statement of acceptance of any version is
190
- permanent authorization for you to choose that version for the
191
- Library.
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # File: script/console
3
- irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
-
5
- libs = " -r irb/completion"
6
- # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
- # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
- libs << " -r #{File.dirname(__FILE__) + '/../lib/jsont.rb'}"
9
- puts "Loading jsont gem"
10
- exec "#{irb} #{libs} --simple-prompt"
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/destroy'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
- RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/generate'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
- RubiGen::Scripts::Generate.new.run(ARGV)
@@ -1,3 +0,0 @@
1
- require 'stringio'
2
- require 'test/unit'
3
- require File.dirname(__FILE__) + '/../lib/jsont'
@@ -1,79 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
- require 'json'
3
- class TestJsont < Test::Unit::TestCase
4
-
5
- def setup
6
- end
7
-
8
- def test_expressions
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
-
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
-
13
- assert_equal(Jsont.new(JSON.parse('{ "self": "<table>\n{$}\n</table>",
14
- "self[*]": "<tr>{$}</tr>\n",
15
- "self[*][*]": "<td>{$}</td>" }')).transform(JSON.parse('[[1,2],[3,4]]')), '<table>
16
- <tr><td>1</td><td>2</td></tr>
17
- <tr><td>3</td><td>4</td></tr>
18
-
19
- </table>')
20
-
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
- <table><tr><td>1</td><td>2</td><td>3</td><td>4</td></tr></table>
23
-
24
- </div>')
25
-
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
-
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
- 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>')
76
-
77
-
78
- end
79
- end