hom 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/hom.gemspec +1 -1
- data/lib/hom.rb +9 -1
- data/spec/element_spec.rb +14 -1
- data/spec/encoding_spec.rb +6 -1
- data/spec/entity_spec.rb +35 -42
- data/spec/node_list_spec.rb +10 -5
- metadata +2 -2
data/hom.gemspec
CHANGED
data/lib/hom.rb
CHANGED
@@ -25,6 +25,10 @@ module HOM
|
|
25
25
|
def html_safe?
|
26
26
|
true
|
27
27
|
end
|
28
|
+
|
29
|
+
def +(object)
|
30
|
+
NodeList.new([self, object])
|
31
|
+
end
|
28
32
|
end
|
29
33
|
|
30
34
|
class Element
|
@@ -45,6 +49,10 @@ module HOM
|
|
45
49
|
def to_s
|
46
50
|
Encoding.safe_encode(self)
|
47
51
|
end
|
52
|
+
|
53
|
+
def +(object)
|
54
|
+
NodeList.new([self, object])
|
55
|
+
end
|
48
56
|
end
|
49
57
|
|
50
58
|
class NodeList
|
@@ -69,7 +77,7 @@ module HOM
|
|
69
77
|
end
|
70
78
|
|
71
79
|
def join(separator)
|
72
|
-
|
80
|
+
self.class.new(intersperse(separator, @nodes))
|
73
81
|
end
|
74
82
|
|
75
83
|
private
|
data/spec/element_spec.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'active_support/core_ext/string/output_safety'
|
3
|
-
|
3
|
+
|
4
|
+
if defined? require_relative
|
5
|
+
require_relative '../lib/hom'
|
6
|
+
else
|
7
|
+
require File.join(File.dirname(__FILE__), '../lib/hom')
|
8
|
+
end
|
4
9
|
|
5
10
|
describe 'HOM::Element' do
|
6
11
|
describe 'content query method' do
|
@@ -26,4 +31,12 @@ describe 'HOM::Element' do
|
|
26
31
|
output.must_equal('<br>')
|
27
32
|
end
|
28
33
|
end
|
34
|
+
|
35
|
+
describe 'addition of an element with another object' do
|
36
|
+
it 'returns a node list containing the two nodes' do
|
37
|
+
nodes = HOM::Element.new(:br) + "\n"
|
38
|
+
nodes.must_be_instance_of(HOM::NodeList)
|
39
|
+
nodes.to_s.must_equal("<br>\n")
|
40
|
+
end
|
41
|
+
end
|
29
42
|
end
|
data/spec/encoding_spec.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'active_support/core_ext/string/output_safety'
|
3
|
-
|
3
|
+
|
4
|
+
if defined? require_relative
|
5
|
+
require_relative '../lib/hom'
|
6
|
+
else
|
7
|
+
require File.join(File.dirname(__FILE__), '../lib/hom')
|
8
|
+
end
|
4
9
|
|
5
10
|
describe 'HOM::Encoding' do
|
6
11
|
describe 'encode method' do
|
data/spec/entity_spec.rb
CHANGED
@@ -1,74 +1,67 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
|
-
require 'hom'
|
3
2
|
|
4
|
-
|
3
|
+
if defined? require_relative
|
4
|
+
require_relative '../lib/hom'
|
5
|
+
else
|
6
|
+
require File.join(File.dirname(__FILE__), '../lib/hom')
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'HOM::Entity' do
|
5
10
|
before do
|
6
|
-
@
|
11
|
+
@named_entity = HOM::Entity.new(:nbsp)
|
12
|
+
|
13
|
+
@numeric_entity = HOM::Entity.new(160)
|
7
14
|
end
|
8
15
|
|
9
16
|
describe 'value method' do
|
10
|
-
it 'returns the
|
11
|
-
@
|
17
|
+
it 'returns the value passed to the constructor' do
|
18
|
+
@named_entity.value.must_equal(:nbsp)
|
19
|
+
|
20
|
+
@numeric_entity.value.must_equal(160)
|
12
21
|
end
|
13
22
|
end
|
14
23
|
|
15
24
|
describe 'numeric query method' do
|
16
|
-
it 'returns false' do
|
17
|
-
@
|
25
|
+
it 'returns false for named entities' do
|
26
|
+
@named_entity.numeric?.must_equal(false)
|
18
27
|
end
|
19
|
-
end
|
20
28
|
|
21
|
-
|
22
|
-
|
23
|
-
@entity.named?.must_equal(true)
|
29
|
+
it 'returns true for numeric entities' do
|
30
|
+
@numeric_entity.numeric?.must_equal(true)
|
24
31
|
end
|
25
32
|
end
|
26
33
|
|
27
|
-
describe '
|
28
|
-
it 'returns
|
29
|
-
@
|
34
|
+
describe 'named query method' do
|
35
|
+
it 'returns true for named entities' do
|
36
|
+
@named_entity.named?.must_equal(true)
|
30
37
|
end
|
31
|
-
end
|
32
38
|
|
33
|
-
|
34
|
-
|
35
|
-
@entity.html_safe?.must_equal(true)
|
39
|
+
it 'returns false for numeric entities' do
|
40
|
+
@numeric_entity.named?.must_equal(false)
|
36
41
|
end
|
37
42
|
end
|
38
|
-
end
|
39
43
|
|
40
|
-
describe '
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
+
describe 'to_s method' do
|
45
|
+
it 'returns the encoded html entity' do
|
46
|
+
@named_entity.to_s.must_equal(' ')
|
44
47
|
|
45
|
-
|
46
|
-
it 'returns the integer value' do
|
47
|
-
@entity.value.must_equal(160)
|
48
|
+
@numeric_entity.to_s.must_equal(' ')
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
describe '
|
52
|
+
describe 'html_safe query method' do
|
52
53
|
it 'returns true' do
|
53
|
-
@
|
54
|
-
end
|
55
|
-
end
|
54
|
+
@named_entity.html_safe?.must_equal(true)
|
56
55
|
|
57
|
-
|
58
|
-
it 'returns false' do
|
59
|
-
@entity.named?.must_equal(false)
|
56
|
+
@numeric_entity.html_safe?.must_equal(true)
|
60
57
|
end
|
61
58
|
end
|
62
59
|
|
63
|
-
describe '
|
64
|
-
it 'returns the
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
describe 'html_safe query method' do
|
70
|
-
it 'returns true' do
|
71
|
-
@entity.html_safe?.must_equal(true)
|
60
|
+
describe 'addition of an entity with another object' do
|
61
|
+
it 'returns a node list containing the two nodes' do
|
62
|
+
nodes = HOM::Entity.new(:pound) + '9.99'
|
63
|
+
nodes.must_be_instance_of(HOM::NodeList)
|
64
|
+
nodes.to_s.must_equal('£9.99')
|
72
65
|
end
|
73
66
|
end
|
74
67
|
end
|
data/spec/node_list_spec.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'active_support/core_ext/string/output_safety'
|
3
|
-
|
3
|
+
|
4
|
+
if defined? require_relative
|
5
|
+
require_relative '../lib/hom'
|
6
|
+
else
|
7
|
+
require File.join(File.dirname(__FILE__), '../lib/hom')
|
8
|
+
end
|
4
9
|
|
5
10
|
describe 'HOM::NodeList' do
|
6
11
|
describe 'html_safe query method' do
|
@@ -45,10 +50,10 @@ describe 'HOM::NodeList' do
|
|
45
50
|
end
|
46
51
|
|
47
52
|
describe 'join method' do
|
48
|
-
it 'returns
|
49
|
-
|
50
|
-
|
51
|
-
|
53
|
+
it 'returns a new node list containing the items in the list seperated by the given node' do
|
54
|
+
nodes = HOM::NodeList.new(%w(a b c)).join(HOM::Entity.new(:nbsp))
|
55
|
+
nodes.must_be_instance_of(HOM::NodeList)
|
56
|
+
nodes.to_s.must_equal('a b c')
|
52
57
|
end
|
53
58
|
end
|
54
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-06-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|