rind 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,9 @@
1
+ require 'test/unit'
2
+ require 'rind'
3
+
4
+ class CommentTest < Test::Unit::TestCase
5
+ def test_to_s
6
+ comment = Rind::Comment.new('foo')
7
+ assert_equal(comment.to_s, '<!--foo-->')
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ require 'test/unit'
2
+ require 'rind'
3
+
4
+ class DocumentTest < Test::Unit::TestCase
5
+ def setup
6
+ @doc = Rind::Document.new('files/document_test.html')
7
+ end
8
+
9
+ def test_template_failure
10
+ assert_raise(RuntimeError) do
11
+ Rind::Document.new('files/missing_template.html')
12
+ end
13
+ end
14
+
15
+ def test_type
16
+ assert_equal(@doc.type, 'html')
17
+ assert_equal(Rind::Document.new('files/document_test.html', {:type => 'xml'}).type, 'xml' )
18
+ end
19
+
20
+ def test_root
21
+ assert_equal(@doc.root.name, 'html')
22
+ end
23
+ end
@@ -0,0 +1,49 @@
1
+ require 'test/unit'
2
+ require 'rind'
3
+
4
+ class ElementTest < Test::Unit::TestCase
5
+ def setup
6
+ @element = Rind::Element.new(
7
+ :attributes => {:class => "foo", :id => 'bar'},
8
+ :children => ['This is some text!', Rind::Element.new()]
9
+ );
10
+ end
11
+
12
+ def test_attribute_parsing
13
+ element2 = Rind::Element.new(
14
+ :attributes => 'class="foo" id="bar"',
15
+ :children => ['This is some text!', Rind::Element.new()]
16
+ );
17
+ assert_equal(element2, @element)
18
+ end
19
+
20
+ def test_accessor
21
+ # get
22
+ assert_equal(@element[], {'class' => 'foo', 'id' => 'bar'})
23
+ assert_equal(@element[:id], 'bar')
24
+ assert_equal(@element['class'], 'foo')
25
+
26
+ # set
27
+ @element[:class] = 'hi'
28
+ assert_equal(@element[:class], 'hi')
29
+ @element['id'] = 'second'
30
+ assert_equal(@element[:id], 'second')
31
+ end
32
+
33
+ def test_local_name
34
+ assert_equal(@element.local_name, 'element')
35
+ end
36
+
37
+ def test_namespace
38
+ assert_equal(@element.namespace_name, 'rind')
39
+ end
40
+
41
+ def test_expanded_name
42
+ assert_equal(@element.expanded_name, 'element')
43
+ assert_equal(Rind::Element.new(:namespace_name => 'test').expanded_name, 'test:element')
44
+ end
45
+
46
+ def test_to_s
47
+ assert_equal(@element.to_s, '<element class="foo" id="bar">This is some text!<element /></element>')
48
+ end
49
+ end
@@ -0,0 +1,19 @@
1
+ require 'test/unit'
2
+ require 'rind'
3
+
4
+ class EqualityTest < Test::Unit::TestCase
5
+ def setup
6
+ @a = Rind::Comment.new('hello world')
7
+ @b = Rind::Comment.new('hello world')
8
+ end
9
+
10
+ def test_double_equal
11
+ assert_equal(@a, @b)
12
+ assert_equal(@a, @b.to_s)
13
+ end
14
+
15
+ def test_eql
16
+ assert(@a.eql?(@b))
17
+ assert(! @a.eql?('<!--hello world-->'))
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ <html>
2
+ <head>
3
+ <title>Document Test</title>
4
+ </head>
5
+ <body>
6
+ <p>This is the document test!</p>
7
+ </body>
8
+ </html>
@@ -0,0 +1,13 @@
1
+ <a>
2
+ <b>
3
+ <c>
4
+ <d>
5
+ <e/>
6
+ <f/>
7
+ <g/>
8
+ </d>
9
+ <h/>
10
+ <i/>
11
+ </c>
12
+ </b>
13
+ </a>
data/test/html_test.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'test/unit'
2
+ require 'rind'
3
+
4
+ class HtmlTest < Test::Unit::TestCase
5
+ def test_expanded_name
6
+ assert_equal(Rind::Html::Br.new().expanded_name, 'br')
7
+ end
8
+
9
+ def test_to_s
10
+ # self closing tag
11
+ assert_equal(Rind::Html::Br.new().to_s, '<br />')
12
+
13
+ # requires separate closing tag
14
+ assert_equal(Rind::Html::P.new().to_s, '<p></p>')
15
+ end
16
+ end
@@ -0,0 +1,23 @@
1
+ require 'test/unit'
2
+ require 'rind'
3
+
4
+ class ManipulateTest < Test::Unit::TestCase
5
+ def setup
6
+ @p = Rind::Html::P.new(:children => ['This is some text!'])
7
+ @br = Rind::Html::Br.new()
8
+ @hr = Rind::Html::Hr.new()
9
+ end
10
+
11
+ def test_insert_after
12
+ assert_equal(@p.children.first.insert_after(@br, @hr), ['This is some text!', @br, @hr])
13
+ end
14
+
15
+ def test_insert_before
16
+ assert_equal(@p.children.first.insert_before(@br, @hr), [@br, @hr, 'This is some text!'])
17
+ end
18
+
19
+ def test_remove
20
+ assert_equal(@p.children.first.remove, 'This is some text!')
21
+ assert(@p.children.empty?)
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require 'test/unit'
2
+ require 'rind'
3
+
4
+ class NodesTest < Test::Unit::TestCase
5
+ def setup
6
+ @p_one = Rind::Html::P.new(:attributes => {:class => '1'})
7
+ @p_two = Rind::Html::P.new(:attributes => {:class => '2'})
8
+ @br_one = Rind::Html::Br.new(:attributes => {:class => '1'})
9
+ @br_two = Rind::Html::Br.new(:attributes => {:class => '2'})
10
+ @nodes = Rind::Nodes.new([@p_one, @p_two, @br_one, @br_two])
11
+ end
12
+
13
+ def test_filter
14
+ assert_equal(@nodes.filter('br'), [@br_one, @br_two])
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+ require 'rind'
3
+
4
+ class ParserTest < Test::Unit::TestCase
5
+ def test_parse
6
+ end
7
+ end
@@ -0,0 +1,57 @@
1
+ require 'test/unit'
2
+ require 'rind'
3
+
4
+ class TraverseTest < Test::Unit::TestCase
5
+ def setup
6
+ @root = Rind::Document.new('files/traverse_test.html').root
7
+ end
8
+
9
+ def test_ancestors
10
+ assert_equal(@root.down('f').ancestors, [@root.down('d'), @root.down('c'), @root.down('b'), @root])
11
+ assert_equal(@root.down('f').ancestors('c'), [@root.down('c')])
12
+ end
13
+
14
+ def test_descendants
15
+ assert_equal(@root.down('c').descendants, [@root.down('d'), @root.down('h'), @root.down('i'), @root.down('e'), @root.down('f'), @root.down('g')])
16
+ assert_equal(@root.descendants('f'), [@root.down('f')])
17
+ end
18
+
19
+ def test_down
20
+ assert_equal(@root.down.name, 'b')
21
+ assert_equal(@root.down('f').name, 'f')
22
+ end
23
+
24
+ def test_next
25
+ assert_same(@root.down('f').next, @root.down('g'))
26
+ assert_same(@root.down('e').next('g'), @root.down('g'))
27
+ end
28
+
29
+ def test_next_siblings
30
+ assert_equal(@root.down('f').next_siblings, [@root.down('g')])
31
+ assert_equal(@root.down('e').next_siblings('g'), [@root.down('g')])
32
+ end
33
+
34
+ def test_parent
35
+ assert_same(@root.down.parent, @root)
36
+ end
37
+
38
+ def test_prev
39
+ assert_same(@root.down('f').prev, @root.down('e'))
40
+ assert_same(@root.down('g').prev('e'), @root.down('e'))
41
+ end
42
+
43
+ def test_prev_siblings
44
+ assert_equal(@root.down('f').prev_siblings, [@root.down('e')])
45
+ assert_equal(@root.down('g').prev_siblings('e'), [@root.down('e')])
46
+ end
47
+
48
+ def test_siblings
49
+ assert_equal(@root.down('f').siblings, [@root.down('e'), @root.down('g')])
50
+ assert_equal(@root.down('f').siblings('e'), [@root.down('e')])
51
+ end
52
+
53
+ def test_up
54
+ assert_same(@root.down('f').up, @root.down('d'))
55
+ assert_same(@root.down('f').up('b'), @root.down('b'))
56
+ end
57
+ end
data/test/xml_test.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'test/unit'
2
+ require 'rind'
3
+
4
+ class XmlTest < Test::Unit::TestCase
5
+ def test_to_s
6
+ # no children
7
+ a_tag = Rind::Xml::A.new();
8
+ assert_equal(a_tag.to_s, '<a />')
9
+
10
+ # with children
11
+ b_tag = Rind::Xml::B.new(:children => a_tag);
12
+ assert_equal(b_tag.to_s, '<b><a /></b>')
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ require 'test/unit'
2
+ require 'rind'
3
+
4
+ class XpathTest < Test::Unit::TestCase
5
+ def setup
6
+ @br_one = Rind::Html::Br.new(:attributes => {:id => 'br_one', :class => '1'})
7
+ @br_two = Rind::Html::Br.new(:attributes => {:id => 'br_two', :class => '2'})
8
+ @br_three = Rind::Html::Br.new()
9
+ @p_one = Rind::Html::P.new(:attributes => {:class => '1'}, :children => [@br_one, @br_two, @br_three])
10
+ end
11
+
12
+ def test_s
13
+ assert_equal(@p_one.s('br'), [@br_one, @br_two, @br_three])
14
+
15
+ # attribute tests
16
+ assert_equal(@p_one.s('br[@class="1"]'), [@br_one])
17
+
18
+ # position tests
19
+ assert_equal(@p_one.s('br[2]'), [@br_two])
20
+ assert_equal(@p_one.s('br[position()=1]'), [@br_one])
21
+ assert_equal(@p_one.s('br[last()]'), [@br_three])
22
+ end
23
+
24
+ def test_sf
25
+ assert_same(@p_one.sf('br'), @br_one)
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rind
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Aaron Lasseigne
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-12 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: "Rind is a templating engine that turns HTML (and XML) into node trees and allows you to create custom tags or reuse someone else\xE2\x80\x99s genius. Rind gives web devs tags to work with and provides the same thing to app devs as an object. This project is just getting started so watch out for sharp corners and unfinished rooms."
23
+ email: aaron.lasseigne@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/rind/document.rb
32
+ - lib/rind/html.rb
33
+ - lib/rind/equality.rb
34
+ - lib/rind/manipulate.rb
35
+ - lib/rind/xpath.rb
36
+ - lib/rind/nodes.rb
37
+ - lib/rind/parser.rb
38
+ - lib/rind/xml.rb
39
+ - lib/rind/traverse.rb
40
+ - lib/rind.rb
41
+ - README.rdoc
42
+ - LICENSE
43
+ - test/children_test.rb
44
+ - test/xml_test.rb
45
+ - test/traverse_test.rb
46
+ - test/html_test.rb
47
+ - test/element_test.rb
48
+ - test/parser_test.rb
49
+ - test/nodes_test.rb
50
+ - test/manipulate_test.rb
51
+ - test/equality_test.rb
52
+ - test/comment_test.rb
53
+ - test/cdata_test.rb
54
+ - test/document_test.rb
55
+ - test/all_test.rb
56
+ - test/xpath_test.rb
57
+ - test/files/traverse_test.html
58
+ - test/files/document_test.html
59
+ has_rdoc: true
60
+ homepage: http://github.com/AaronLasseigne/Rind
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --quiet
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.3.7
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: A templating engine that turns HTML (and XML) into node trees and allows you to create custom tags.
93
+ test_files:
94
+ - test/children_test.rb
95
+ - test/xml_test.rb
96
+ - test/traverse_test.rb
97
+ - test/html_test.rb
98
+ - test/element_test.rb
99
+ - test/parser_test.rb
100
+ - test/nodes_test.rb
101
+ - test/manipulate_test.rb
102
+ - test/equality_test.rb
103
+ - test/comment_test.rb
104
+ - test/cdata_test.rb
105
+ - test/document_test.rb
106
+ - test/all_test.rb
107
+ - test/xpath_test.rb
108
+ - test/files/traverse_test.html
109
+ - test/files/document_test.html