HTML-AutoTag 1.0.5 → 1.0.6
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.
- checksums.yaml +4 -4
- data/Changes +4 -0
- data/README +4 -4
- data/lib/HTML/AutoTag/version.rb +1 -1
- data/lib/HTML/AutoTag.rb +4 -3
- data/lib/HTML/Encoder.rb +16 -20
- data/t/02-tag.rb +11 -9
- data/t/05-encode.rb +9 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e62c12acd8d530e8e9d7fb5a8bd3ad917b0b13f
|
4
|
+
data.tar.gz: 654a095d32d9e1c1c592163cb56c93814bf0d835
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f4cf5d79e775ea646d56a4fdca1f9be040829033bbe66454ca7a9173ce8ba4d7ea74824f046034dfc4c92777d2b9f9fbd4424a4c97abba5c6daf2384e443b10
|
7
|
+
data.tar.gz: 393be2a6b9ecd0a34233599312525285fa642d974c013e4f8cbdaf1f8b9d0b30f54c33c374e1b02449229dc00f402fa05fac46fba090fe54491b08b5b755ce12
|
data/Changes
CHANGED
data/README
CHANGED
@@ -28,15 +28,15 @@ Also includes HTML::AutoAttr which provides rotating attributes:
|
|
28
28
|
attr = HTML::AutoAttr.new( { 'foo' => ['bar','baz','qux'] } )
|
29
29
|
4.times { puts attr.to_s }
|
30
30
|
|
31
|
-
== Dependencies
|
32
|
-
* htmlentities
|
33
|
-
|
34
31
|
== Methods
|
35
32
|
With the exception of new, all methods return an HTML table as a string.
|
36
33
|
|
37
34
|
* new( params )
|
35
|
+
* encode=(boolean)
|
36
|
+
Whether or not to Encode entities.
|
38
37
|
* encodes=(string)
|
39
|
-
Encode HTML entities. Pass
|
38
|
+
Encode these HTML entities. Pass string with chars you want encoded
|
39
|
+
or leave blank for default control and high bit chars and <>!'"
|
40
40
|
* indent=(string)
|
41
41
|
Pretty print results.
|
42
42
|
* level=(integer)
|
data/lib/HTML/AutoTag/version.rb
CHANGED
data/lib/HTML/AutoTag.rb
CHANGED
@@ -6,12 +6,13 @@ module HTML
|
|
6
6
|
|
7
7
|
class AutoTag
|
8
8
|
|
9
|
-
attr_accessor 'encodes', 'indent', 'level', 'sorted', 'newline'
|
9
|
+
attr_accessor 'encode', 'encodes', 'indent', 'level', 'sorted', 'newline'
|
10
10
|
|
11
11
|
# Defaults to empty string which produces no encoding.
|
12
12
|
|
13
13
|
def initialize( params = {} )
|
14
|
-
@encodes = params
|
14
|
+
@encodes = params['encodes']
|
15
|
+
@encode = params['encode'] || !@encodes.nil?
|
15
16
|
@indent = params['indent'] || ''
|
16
17
|
@level = params['level'] || 0
|
17
18
|
@sorted = params['sorted'] ? 1 : 0
|
@@ -62,7 +63,7 @@ module HTML
|
|
62
63
|
@level -= 1
|
63
64
|
|
64
65
|
else
|
65
|
-
rendered = @encoder.encode( cdata, @encodes )
|
66
|
+
rendered = @encode ? @encoder.encode( cdata, @encodes ) : cdata
|
66
67
|
no_post_indent = 1
|
67
68
|
end
|
68
69
|
|
data/lib/HTML/Encoder.rb
CHANGED
@@ -93,7 +93,7 @@ module HTML
|
|
93
93
|
'uml' => 168.chr,
|
94
94
|
'ordf' => 170.chr,
|
95
95
|
'laquo' => 171.chr,
|
96
|
-
'not' => 172.chr,
|
96
|
+
'not' => 172.chr,
|
97
97
|
'shy' => 173.chr,
|
98
98
|
'macr' => 175.chr,
|
99
99
|
'deg' => 176.chr,
|
@@ -112,7 +112,7 @@ module HTML
|
|
112
112
|
'frac12' => 189.chr,
|
113
113
|
'frac34' => 190.chr,
|
114
114
|
'iquest' => 191.chr,
|
115
|
-
'times' => 215.chr,
|
115
|
+
'times' => 215.chr,
|
116
116
|
'divide' => 247.chr,
|
117
117
|
}
|
118
118
|
|
@@ -132,26 +132,22 @@ module HTML
|
|
132
132
|
|
133
133
|
end
|
134
134
|
|
135
|
-
def encode( *args )
|
135
|
+
def encode( string, *args )
|
136
136
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
lookup[c]
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
else
|
150
|
-
encoded += c
|
151
|
-
end
|
152
|
-
}
|
137
|
+
if (! args[0].nil? and ! args[0].to_s.empty?)
|
138
|
+
lookup = {}
|
139
|
+
args[0].to_s.each_char{ |c|
|
140
|
+
lookup[c] = @char2entity[c].nil? ? num_entity(c) : @char2entity[c]
|
141
|
+
}
|
142
|
+
string = string.to_s.gsub( /./ ) {|c| lookup[c].nil? ? c : lookup[c] }
|
143
|
+
else
|
144
|
+
# Encode control chars, high bit chars and '<', '&', '>', ''' and '"'
|
145
|
+
string = string.to_s.gsub( /([^\n\r\t !\#\$%\(-;=?-~])/ ) {|c|
|
146
|
+
@char2entity[c].nil? ? num_entity(c) : @char2entity[c]
|
147
|
+
}
|
148
|
+
end
|
153
149
|
|
154
|
-
return
|
150
|
+
return string
|
155
151
|
|
156
152
|
end
|
157
153
|
|
data/t/02-tag.rb
CHANGED
@@ -5,14 +5,16 @@ class TestTag < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
def test_init
|
7
7
|
auto = HTML::AutoTag.new
|
8
|
-
assert_equal(
|
9
|
-
assert_equal(
|
10
|
-
assert_equal(
|
11
|
-
assert_equal( 0, auto.
|
12
|
-
assert_equal(
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
assert_equal( false, auto.encode, "no args encode correct" )
|
9
|
+
assert_equal( nil, auto.encodes, "no args encodes correct" )
|
10
|
+
assert_equal( '', auto.indent, "no args indent correct" )
|
11
|
+
assert_equal( 0, auto.level, "no args level correct" )
|
12
|
+
assert_equal( 0, auto.sorted, "no args sorted correct" )
|
13
|
+
assert_equal( '', auto.newline, "no args newline correct" )
|
14
|
+
|
15
|
+
auto = HTML::AutoTag.new( 'encodes' => '<>', 'indent' => ' ' )
|
16
|
+
assert_equal( true, auto.encode, "encode set correct" )
|
17
|
+
assert_equal( '<>', auto.encodes, "encodes set correct" )
|
16
18
|
assert_equal( ' ', auto.indent, "indent set correct" )
|
17
19
|
assert_equal( "\n", auto.newline, "newline set correct" )
|
18
20
|
end
|
@@ -48,7 +50,7 @@ class TestTag < Test::Unit::TestCase
|
|
48
50
|
assert_equal( '<p><0></p>', auto.tag( 'tag' => 'p', 'cdata' => '<0>' ), "specific encodes work" )
|
49
51
|
|
50
52
|
auto = HTML::AutoTag.new( 'encodes' => nil )
|
51
|
-
assert_equal( '<p
|
53
|
+
assert_equal( '<p><"0\'&></p>', auto.tag( 'tag' => 'p', 'cdata' => '<"0\'&>' ), "no encoding when encodes is nil" )
|
52
54
|
|
53
55
|
auto = HTML::AutoTag.new( 'encodes' => 0 )
|
54
56
|
assert_equal( '<p><0></p>', auto.tag( 'tag' => 'p', 'cdata' => '<0>' ), "zero only encode work" )
|
data/t/05-encode.rb
CHANGED
@@ -10,13 +10,13 @@ class TestHTML_Encoder < Test::Unit::TestCase
|
|
10
10
|
assert_equal(
|
11
11
|
'&<>"'',
|
12
12
|
encoder.encode( '&<>"\'' ),
|
13
|
-
'default chars encoded
|
13
|
+
'default chars encoded when chars is nil'
|
14
14
|
)
|
15
15
|
|
16
16
|
assert_equal(
|
17
|
-
'
|
17
|
+
'&<>"'',
|
18
18
|
encoder.encode( '&<>"\'', '' ),
|
19
|
-
'
|
19
|
+
'encodes when chars is empty'
|
20
20
|
)
|
21
21
|
|
22
22
|
assert_equal(
|
@@ -40,13 +40,13 @@ class TestHTML_Encoder < Test::Unit::TestCase
|
|
40
40
|
assert_equal(
|
41
41
|
'hello',
|
42
42
|
encoder.encode( 'hello' ),
|
43
|
-
'no encodes when default chars
|
43
|
+
'no encodes when default chars is nil'
|
44
44
|
)
|
45
45
|
|
46
46
|
assert_equal(
|
47
47
|
'hello',
|
48
48
|
encoder.encode( 'hello', '' ),
|
49
|
-
'no
|
49
|
+
'no encodes when default chars is empty'
|
50
50
|
)
|
51
51
|
|
52
52
|
deadbeef = 222.chr + 173.chr + 190.chr + 239.chr
|
@@ -58,15 +58,15 @@ class TestHTML_Encoder < Test::Unit::TestCase
|
|
58
58
|
)
|
59
59
|
|
60
60
|
assert_equal(
|
61
|
-
|
61
|
+
'Þ­¾ï',
|
62
62
|
encoder.encode( deadbeef ),
|
63
|
-
'
|
63
|
+
'hex codes encoded correctly when chars is nil'
|
64
64
|
)
|
65
65
|
|
66
66
|
assert_equal(
|
67
|
-
|
67
|
+
'Þ­¾ï',
|
68
68
|
encoder.encode( deadbeef, '' ),
|
69
|
-
'
|
69
|
+
'hex codes encoded correctly when chars is empty'
|
70
70
|
)
|
71
71
|
|
72
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: HTML-AutoTag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jeffa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|