jig 0.1.0

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.
@@ -0,0 +1,26 @@
1
+ require 'jig'
2
+ require 'test/unit'
3
+ require 'test/jig'
4
+
5
+ class TestXML < Test::Unit::TestCase
6
+ XH = Jig::XHTML
7
+ include Asserts
8
+
9
+ def test_eid
10
+ @div = %r{<div id="[^"]*">\n</div>\n}
11
+ @input = %r{<input id="\w*"/>}
12
+ @jig_div_id = XH.div_with_id
13
+ @jig_input = XH.input!
14
+ assert_match(@div, @jig_div_id.to_s)
15
+ assert_raise(RuntimeError,'eid reassignment') { @jig_div_id.eid = "foo" }
16
+ assert_match(@input, XH.input.to_s)
17
+ assert_not_equal(XH.li_with_id.to_s, XH.li_with_id.to_s)
18
+ end
19
+
20
+ def test_element_with_id
21
+ j = XH.element_with_id(:a, :href => "foo")
22
+ id, href = %Q{id="#{j.eid}"}, 'href="foo"'
23
+ assert_match(%r{<a (#{id} #{href}|#{href} #{id})></a>\n}, j.to_s)
24
+ end
25
+
26
+ end
data/test/test_xml.rb ADDED
@@ -0,0 +1,148 @@
1
+ require 'jig'
2
+ require 'test/unit'
3
+ require 'test/jig'
4
+
5
+ class TestXML < Test::Unit::TestCase
6
+ X = Jig::XML
7
+ include Asserts
8
+ def setup
9
+ @div = X.element('div')
10
+ @gaps = [:___]
11
+ end
12
+
13
+ def test_comment
14
+ assert_as_string("<!-- -->\n", X.comment)
15
+ assert_equal(@gaps, X.comment.gaps)
16
+ assert_as_string("<!-- comment -->\n", X.comment('comment'))
17
+ end
18
+
19
+ def test_xml
20
+ assert_as_string(%Q{<?xml version="1.0" ?>\n}, X.xml)
21
+ v,e = %Q{version="1.0"}, %Q{encoding="UTF-8"}
22
+ assert_as_string(%Q{<?xml #{e} #{v} ?>\n}, X.xml(:encoding => "UTF-8"))
23
+ end
24
+
25
+ def test_hash
26
+ # Hash is OK
27
+ assert_nothing_raised(ArgumentError) {X.new('a' => 'b')}
28
+ assert_nothing_raised(ArgumentError) {X.new("a", 'c'=>'d')}
29
+
30
+ # Hash checks
31
+ assert_equal(%Q{ a="b"}, X.new('a' => 'b').to_s, 'create from Hash')
32
+ assert_equal(%Q{ a="b" c="d"}, X.new('a' => 'b', 'c' => 'd').to_s, 'create from Hash, 2 items')
33
+ assert_equal(%Q{ a="b"}, X.new(Jig::GAP, 'a' => 'b').to_s, 'hash and gap')
34
+ assert_equal("", X.new('a' => Jig::GAP).to_s, 'attribute suppression')
35
+
36
+ assert_nothing_raised(ArgumentError, 'hash OK with #new') { X.new(:div, "first", {'a' => 'b'}, "third") }
37
+ assert_equal(%Q{first a="b"third}, X.new(:div, "first", {'a' => 'b'}, "third").to_s)
38
+ end
39
+
40
+ def test_plug_hash
41
+ # plugging hashs
42
+ assert_equal(%Q{ a="b"}, X.new('a' => :alpha).plug(:alpha, "b").to_s, 'plugging an attribute')
43
+ assert_equal(%Q{ a="b"}, X.new('a' => :alpha).plug(:alpha, lambda { "b" }).to_s, 'plugging an attribute with a proc')
44
+ assert_equal(%Q{}, X.new('a' => :alpha).plug(:alpha, lambda { nil }).to_s, 'plugging an attribute with a proc returning nil')
45
+ assert_equal(%Q{}, X.new({'a',Jig::GAP}).plug(lambda { nil }).to_s, 'plugging an attribute with a proc returning nil')
46
+ end
47
+
48
+ def test_element
49
+ # element construction
50
+ @div = "<div>\n</div>\n"
51
+ assert_equal(@div, X.element.to_s, 'default element as "div"')
52
+
53
+ assert_equal(@div, X.element(:div).to_s)
54
+ assert_equal(@div, X.element(:div, Jig::GAP).to_s)
55
+ assert_equal(@div, X.element(:div, Jig::GAP).to_s)
56
+ assert_equal(@div, X.element(:div, X.new).to_s)
57
+
58
+ @div2 = "<div>\ninside</div>\n"
59
+ assert_equal(@div2, X.element(:div, "inside").to_s)
60
+ assert_equal(@div2, X.element(:div, "in", "side").to_s)
61
+
62
+ # element with attributes
63
+ @div_empty = "<div>\n</div>\n"
64
+ @div_1attr= %Q{<div a="b">\n</div>\n}
65
+ @div_1attrfilled= %Q{<div a="b">\ninside</div>\n}
66
+ @div_1attrfilled2= %Q{<div a="b">\ninsidealso</div>\n}
67
+ assert_not_equal(@div_empty, X.element(:div, 'a' => 'b').to_s)
68
+ assert_equal(@div_1attr, X.element(:div, 'a' => 'b').to_s)
69
+ assert_equal(@div_1attrfilled, X.element(:div, 'inside', {'a' => 'b'}).to_s)
70
+ assert_equal(@div_1attrfilled, X.element(:div, {'a' => 'b'}) { "inside" }.to_s)
71
+ assert_equal(@div_1attrfilled, X.element(:div, lambda { "inside" }, {'a' => 'b'} ).to_s)
72
+ assert_equal(@div_1attrfilled2, (X.element(:div, lambda { "inside" }, {'a' => 'b'} ) { "also" }).to_s)
73
+
74
+ #assert_raise(ArgumentError, 'hash only as first argument') { X.element(:div, "first", {'a' => 'b'}, "third") }
75
+ end
76
+
77
+ def test_method_missing
78
+ assert_equal(X.div, X.element(:div))
79
+ assert_equal(X.div(Jig::GAP), X.element(:div, Jig::GAP))
80
+ assert_equal(X.div(Jig::GAP), X.element(:div, Jig::GAP))
81
+ assert_equal(X.div(X.new), X.element(:div, X.new))
82
+
83
+ assert_equal(X.div_, X.div)
84
+
85
+ @div2 = "<div>\ninside</div>\n"
86
+ assert_equal(@div2, X.element(:div, "inside").to_s)
87
+ assert_equal(@div2, X.element(:div, "in", "side").to_s)
88
+
89
+ # element with block
90
+ assert_equal(@div2, (X.element(:div) {"inside"}).to_s)
91
+
92
+ assert_equal(@div2, X.div("inside").to_s)
93
+ assert_equal(@div2, X.div("in", "side").to_s)
94
+
95
+ # div with attributes
96
+ @div_empty = "<div>\n</div>\n"
97
+ @div_1attr= %Q{<div a="b">\n</div>\n}
98
+ @div_1attrfilled= %Q{<div a="b">\ninside</div>\n}
99
+ @div_1attrfilled2= %Q{<div a="b">\ninsidealso</div>\n}
100
+ assert_not_equal(@div_empty, X.div( 'a' => 'b').to_s)
101
+ assert_equal(@div_1attr, X.div( 'a' => 'b').to_s)
102
+ assert_equal(@div_1attrfilled, X.div( "inside", {'a' => 'b'} ).to_s)
103
+ assert_equal(@div_1attrfilled, X.div( {'a' => 'b'}) { "inside" }.to_s)
104
+ assert_equal(@div_1attrfilled, X.div(lambda { "inside" }, {'a' => 'b'} ).to_s)
105
+ assert_equal(@div_1attrfilled2, (X.div(lambda { "inside" }, {'a' => 'b'}) { "also" }).to_s)
106
+ end
107
+
108
+ def test_more_plugging
109
+ @div = "<div>\nabc</div>\n"
110
+ @jdiv = X.new("<div>\nabc</div>\n")
111
+ assert_equal(@div, @jdiv.to_s)
112
+ assert_match(@jdiv, X.div << "abc")
113
+ assert_match(@jdiv, X.div("abc"))
114
+ assert_match(@jdiv, X.div { "abc" })
115
+
116
+ @divp = "<div>\n<p>\n</p>\n</div>\n"
117
+ @pdiv = "<p>\n<div>\n</div>\n</p>\n"
118
+ @jdivp = X.new("<div>\n<p>\n</p>\n</div>\n")
119
+ @jpdiv = X.new("<p>\n<div>\n</div>\n</p>\n")
120
+ assert_equal(@divp, @jdivp.to_s)
121
+ assert_equal(@pdiv, @jpdiv.to_s)
122
+ assert_as_string(@jdivp, (X.div << X.p))
123
+ assert_as_string(@jpdiv, X.p << X.div)
124
+
125
+ @full = %Q{<div a="b">\ninside</div>\n}
126
+ @full_jig = X.new(%Q{<div a="b">\ninside</div>\n})
127
+ assert_equal(@full, @full_jig.to_s)
128
+ assert_match(@full_jig, X.div('a' => 'b') { "inside" })
129
+ assert_match(@full_jig, X.div("inside", {'a' => 'b'}))
130
+ end
131
+
132
+
133
+ def test_misc
134
+ #assert_raise(ArgumentError, 'attribute must be string') { X.div('a' => :gap) << X.p }
135
+ #assert_raise(ArgumentError) { ((X.div('a' => Jig::GAP) << X.p).to_s) }
136
+
137
+ assert_equal( "ab", (X.new(:alpha, :beta) << {:alpha => 'a', :beta => 'b'}).to_s)
138
+ assert_equal( "<div>\n</div>\n", (X.div).to_s)
139
+ assert_not_equal( "ab", X.div.plug("ab").to_s)
140
+ assert_equal( "<div>\nab</div>\n", X.div.plug("ab").to_s)
141
+
142
+ #assert_equal( %Q{<div a="b">ab</div>\n}, X.div("a" => "b").to_s)
143
+ assert_equal( %Q{<div a="b">\nfoo</div>\n}, X.div("a" => "b").plug("foo").to_s)
144
+
145
+ # test plug nil
146
+ # test plug with Hash
147
+ end
148
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: jig
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-05-17 00:00:00 -07:00
8
+ summary: a data structure that supports construction and manipulation of strings with hierarchical structure
9
+ require_paths:
10
+ - lib
11
+ email: gwright@rubyforge.org
12
+ homepage: http://jig.rubyforge.org
13
+ rubyforge_project: jig
14
+ description: "A jig is a data structure designed to facilitate construction and manipulation of strings with an inherent hierarchical syntax. The idea is derived from the <bigwig> project (http://www.brics.dk/bigwig/) and in particular the XML templating constructs described in the paper: A Type System for Dynamic Web Documents (http://www.brics.dk/bigwig/publications/dyndoc.pdf). The name is derived from woodworking where a jig is a template designed to guide other tools. A jig is an ordered sequence of objects (usually strings) and named _gaps_. When rendered as a string by Jig#to_s, the objects are rendered by calling #to_s on each object in order. The gaps are skipped. A new jig may be constructed from an existing jig by 'plugging' one or more of the named gaps. The new jig shares the objects and their ordering from the original jig but with the named gap replaced with the 'plug'. Gaps may be plugged by any object or sequence of objects. When a gap is plugged with another jig, the contents (including gaps) are incorporated into the new jig. In addition to strings and gaps, a Jig may contain a proc object (or lambda or method). Procs within a jig are not evaluated until the jig is rendered as a string by #to_s."
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Gary Wright
30
+ files:
31
+ - History.txt
32
+ - Manifest.txt
33
+ - README.txt
34
+ - Rakefile
35
+ - lib/jig.rb
36
+ - lib/jig/css.rb
37
+ - lib/jig/xhtml.rb
38
+ - lib/jig/xml.rb
39
+ - test/test_css.rb
40
+ - test/test_jig.rb
41
+ - test/test_xhtml.rb
42
+ - test/test_xml.rb
43
+ test_files:
44
+ - test/test_css.rb
45
+ - test/test_jig.rb
46
+ - test/test_xhtml.rb
47
+ - test/test_xml.rb
48
+ rdoc_options: []
49
+
50
+ extra_rdoc_files: []
51
+
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ requirements: []
57
+
58
+ dependencies:
59
+ - !ruby/object:Gem::Dependency
60
+ name: hoe
61
+ version_requirement:
62
+ version_requirements: !ruby/object:Gem::Version::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 1.2.0
67
+ version: