HTML-AutoTag 0.0.5 → 0.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 +2 -0
- data/lib/HTML/AutoTag/version.rb +1 -1
- data/lib/HTML/AutoTag.rb +94 -4
- data/readme.md +13 -6
- data/t/04-tag-attrs.rb +120 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28724c56df2f0e66243bc3042c3798af380edcbc
|
4
|
+
data.tar.gz: 6abfeb49b8548f994d508fa3ff4e0c8f072a1c8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35d3838467c0fb0fed4571e3cc86a7bfecba7b0f898ea24a64b21fce8b3526d4a2b2499cd7bdfe0040d1b52e9761bd742306f22de45f394f470ec50f7279551d
|
7
|
+
data.tar.gz: 7b2851ccad5bc32183932507df0d3317a9e8212c579f02762670b6f257ca11c063d72ddf9ebbc57332f2ddc650a9fc295841aa184646155b1de3ad6a9b86ef99
|
data/Changes
CHANGED
data/lib/HTML/AutoTag/version.rb
CHANGED
data/lib/HTML/AutoTag.rb
CHANGED
@@ -19,11 +19,15 @@ module HTML
|
|
19
19
|
|
20
20
|
def tag( params = {} )
|
21
21
|
|
22
|
-
|
22
|
+
if params['attr'].kind_of?( HTML::AutoAttr )
|
23
|
+
attr = params['attr']
|
24
|
+
else
|
25
|
+
attr = HTML::AutoAttr.new( params['attr'] || {}, @sorted )
|
26
|
+
end
|
23
27
|
|
24
28
|
# emtpy tag
|
25
29
|
unless params['cdata'] and params['cdata'].to_s.length
|
26
|
-
return ( @indent * @level ) + '<' + params['tag'] + ' />' + @newline
|
30
|
+
return ( @indent * @level ) + '<' + params['tag'] + attr.to_s + ' />' + @newline
|
27
31
|
end
|
28
32
|
|
29
33
|
cdata = ''
|
@@ -82,7 +86,49 @@ HTML::AutoTag - Just another HTML tag generator.
|
|
82
86
|
require 'HTML/AutoTag'
|
83
87
|
tag = HTML::AutoTag.new
|
84
88
|
|
85
|
-
puts auto.tag( 'tag' => '
|
89
|
+
puts auto.tag( 'tag' => 'hr' )
|
90
|
+
puts auto.tag( 'tag' => 'h1', 'cdata' => 'heading' )
|
91
|
+
puts auto.tag( 'tag' => 'p', 'cdata' => 'paragraph', 'attr' => { 'class' => 'para' } )
|
92
|
+
|
93
|
+
puts auto.tag(
|
94
|
+
'tag' => 'ol',
|
95
|
+
'attr' => { 'reversed' => 'reversed' },
|
96
|
+
'cdata' => data.map{ |d| { 'tag' => 'li', 'attr' => attr, 'cdata' => d } }
|
97
|
+
)
|
98
|
+
|
99
|
+
puts auto.tag(
|
100
|
+
'tag' => 'table',
|
101
|
+
'attr' => { 'class' => 'spreadsheet' },
|
102
|
+
'cdata' => Array[
|
103
|
+
{
|
104
|
+
'tag' => 'tr',
|
105
|
+
'attr' => tr_attr,
|
106
|
+
'cdata' => {
|
107
|
+
'tag' => 'th',
|
108
|
+
'attr' => { 'style' => { 'color' => %w{ red green } } },
|
109
|
+
'cdata' => data,
|
110
|
+
},
|
111
|
+
},
|
112
|
+
{
|
113
|
+
'tag' => 'tr',
|
114
|
+
'attr' => tr_attr,
|
115
|
+
'cdata' => {
|
116
|
+
'tag' => 'td',
|
117
|
+
'attr' => { 'style' => { 'color' => %w{ green blue } } },
|
118
|
+
'cdata' => data,
|
119
|
+
},
|
120
|
+
},
|
121
|
+
{
|
122
|
+
'tag' => 'tr',
|
123
|
+
'attr' => tr_attr,
|
124
|
+
'cdata' => {
|
125
|
+
'tag' => 'td',
|
126
|
+
'attr' => { 'style' => { 'color' => %w{ red green } } },
|
127
|
+
'cdata' => data,
|
128
|
+
},
|
129
|
+
},
|
130
|
+
]
|
131
|
+
)
|
86
132
|
</code>
|
87
133
|
|
88
134
|
== DESCRIPTION
|
@@ -90,9 +136,53 @@ puts auto.tag( 'tag' => 'p', 'cdata' => 'paragraph' )
|
|
90
136
|
Generate nested HTML (HTML4, XHTML and HTML5) tags with custom indentation,
|
91
137
|
custom encoding and automatic attribute value rotation.
|
92
138
|
|
139
|
+
== METHODS
|
140
|
+
|
141
|
+
* new
|
142
|
+
|
143
|
+
Accepts 4 arguments:
|
144
|
+
|
145
|
+
* encodes
|
146
|
+
|
147
|
+
Endcode HTML entities. (boolean)
|
148
|
+
|
149
|
+
* indent
|
150
|
+
|
151
|
+
Pretty print results. (string)
|
152
|
+
|
153
|
+
* level
|
154
|
+
|
155
|
+
Indentation level to start at. (integer)
|
156
|
+
|
157
|
+
* sorted
|
158
|
+
|
159
|
+
Sort attribute names of the tag alphabetically. (boolean)
|
160
|
+
|
161
|
+
* tag
|
162
|
+
|
163
|
+
Accepts 3 arguments:
|
164
|
+
|
165
|
+
* tag
|
166
|
+
|
167
|
+
The name of the tag. (string)
|
168
|
+
|
169
|
+
* attr
|
170
|
+
|
171
|
+
Attributes and values for the tag (hash)
|
172
|
+
|
173
|
+
* cdata
|
174
|
+
|
175
|
+
The value wrapped by the tag. Types allowed are:
|
176
|
+
|
177
|
+
* scalar - the string to be wrapped by the tag
|
178
|
+
|
179
|
+
* hash - another tag with its own cdata and attributes
|
180
|
+
|
181
|
+
* array - list of scalars or list of more hashes
|
182
|
+
|
93
183
|
== SEE ALSO
|
94
184
|
|
95
|
-
*
|
185
|
+
* http://www.w3.org/TR/html5/syntax.html
|
96
186
|
|
97
187
|
== GITHUB
|
98
188
|
|
data/readme.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
HTML-AutoTag (ruby)
|
2
2
|
===================
|
3
|
-
Just another HTML tag generator for ruby.
|
3
|
+
Just another HTML tag generator for ruby. [](https://badge.fury.io/rb/HTML-AutoTag)
|
4
4
|
|
5
5
|
Description
|
6
6
|
-----------
|
@@ -11,18 +11,25 @@ Synopsis
|
|
11
11
|
```ruby
|
12
12
|
require 'HTML/AutoTag'
|
13
13
|
|
14
|
-
auto = HTML::AutoTag.new
|
14
|
+
auto = HTML::AutoTag.new( 'indent' => ' ' )
|
15
15
|
|
16
16
|
puts auto.tag( 'tag' => 'p', 'cdata' => 'a paragraph' )
|
17
|
+
|
18
|
+
attr = { 'style' => { 'color' => %w{ red green } } }
|
19
|
+
data = %w{ one two three four five six seven eight }
|
20
|
+
|
21
|
+
puts auto.tag(
|
22
|
+
'tag' => 'ol',
|
23
|
+
'attr' => { 'reversed' => 'reversed' },
|
24
|
+
'cdata' => data.map{ |d| { 'tag' => 'li', 'attr' => attr, 'cdata' => d } }
|
25
|
+
)
|
17
26
|
```
|
18
27
|
|
19
28
|
Installation
|
20
29
|
------------
|
21
|
-
|
30
|
+
While you are encouraged to install, please note that this Gem is in Alpha release.
|
22
31
|
|
23
|
-
*
|
24
|
-
* rake build
|
25
|
-
* ~~rake install~~ :skull:
|
32
|
+
* gem install HTML-AutoTag
|
26
33
|
|
27
34
|
License and Copyright
|
28
35
|
---------------------
|
data/t/04-tag-attrs.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "HTML/AutoTag"
|
3
|
+
|
4
|
+
class TestTagAttrs < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_simple
|
7
|
+
auto = HTML::AutoTag.new()
|
8
|
+
|
9
|
+
assert_equal(
|
10
|
+
'<p class="paragraph" />',
|
11
|
+
auto.tag( 'tag' => 'p', 'attr' => { 'class' => 'paragraph' } ),
|
12
|
+
'empty paragraph tag correct'
|
13
|
+
)
|
14
|
+
|
15
|
+
assert_equal(
|
16
|
+
'<p class="paragraph">0</p>',
|
17
|
+
auto.tag( 'tag' => 'p', 'attr' => { 'class' => 'paragraph' }, 'cdata' => 0 ),
|
18
|
+
'paragraph tag correct'
|
19
|
+
)
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_one_nested
|
24
|
+
auto = HTML::AutoTag.new()
|
25
|
+
data = %w{ one two three }
|
26
|
+
attr = { 'style' => { 'color' => %w{ red green } } }
|
27
|
+
|
28
|
+
html = auto.tag(
|
29
|
+
'tag' => 'ol',
|
30
|
+
'attr' => { 'reversed' => 'reversed' },
|
31
|
+
'cdata' => data.map{ |d| { 'tag' => 'li', 'attr' => attr, 'cdata' => d } }
|
32
|
+
)
|
33
|
+
|
34
|
+
assert_equal(
|
35
|
+
'<ol reversed="reversed"><li style="color: red;">one</li><li style="color: green;">two</li><li style="color: red;">three</li></ol>',
|
36
|
+
html,
|
37
|
+
'one nested level tags correct'
|
38
|
+
)
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_two_nested
|
43
|
+
auto = HTML::AutoTag.new()
|
44
|
+
data = %w{ one two three }
|
45
|
+
tr_attr = { 'class' => %w{ odd even } }
|
46
|
+
td_attr1 = { 'style' => { 'color' => %w{ red green } } }
|
47
|
+
td_attr2 = { 'style' => { 'color' => %w{ green blue } } }
|
48
|
+
|
49
|
+
html = auto.tag(
|
50
|
+
'tag' => 'table',
|
51
|
+
'attr' => { 'class' => 'spreadsheet' },
|
52
|
+
'cdata' => Array[
|
53
|
+
{
|
54
|
+
'tag' => 'tr',
|
55
|
+
'attr' => tr_attr,
|
56
|
+
'cdata' => data.map{ |d| { 'tag' => 'th', 'attr' => td_attr1, 'cdata' => d } }
|
57
|
+
},
|
58
|
+
{
|
59
|
+
'tag' => 'tr',
|
60
|
+
'attr' => tr_attr,
|
61
|
+
'cdata' => data.map{ |d| { 'tag' => 'td', 'attr' => td_attr2, 'cdata' => d } }
|
62
|
+
},
|
63
|
+
{
|
64
|
+
'tag' => 'tr',
|
65
|
+
'attr' => tr_attr,
|
66
|
+
'cdata' => data.map{ |d| { 'tag' => 'td', 'attr' => td_attr1, 'cdata' => d } }
|
67
|
+
},
|
68
|
+
]
|
69
|
+
)
|
70
|
+
|
71
|
+
assert_equal(
|
72
|
+
'<table class="spreadsheet"><tr class="odd"><th style="color: red;">one</th><th style="color: green;">two</th><th style="color: red;">three</th></tr><tr class="even"><td style="color: green;">one</td><td style="color: blue;">two</td><td style="color: green;">three</td></tr><tr class="odd"><td style="color: green;">one</td><td style="color: red;">two</td><td style="color: green;">three</td></tr></table>',
|
73
|
+
html,
|
74
|
+
'two nested level tags correct'
|
75
|
+
)
|
76
|
+
|
77
|
+
tr_attr = { 'class' => %w{ odd even } }
|
78
|
+
html = auto.tag(
|
79
|
+
'tag' => 'table',
|
80
|
+
'attr' => { 'class' => 'spreadsheet' },
|
81
|
+
'cdata' => Array[
|
82
|
+
{
|
83
|
+
'tag' => 'tr',
|
84
|
+
'attr' => tr_attr,
|
85
|
+
'cdata' => {
|
86
|
+
'tag' => 'th',
|
87
|
+
'attr' => { 'style' => { 'color' => %w{ red green } } },
|
88
|
+
'cdata' => data,
|
89
|
+
},
|
90
|
+
},
|
91
|
+
{
|
92
|
+
'tag' => 'tr',
|
93
|
+
'attr' => tr_attr,
|
94
|
+
'cdata' => {
|
95
|
+
'tag' => 'td',
|
96
|
+
'attr' => { 'style' => { 'color' => %w{ green blue } } },
|
97
|
+
'cdata' => data,
|
98
|
+
},
|
99
|
+
},
|
100
|
+
{
|
101
|
+
'tag' => 'tr',
|
102
|
+
'attr' => tr_attr,
|
103
|
+
'cdata' => {
|
104
|
+
'tag' => 'td',
|
105
|
+
'attr' => { 'style' => { 'color' => %w{ red green } } },
|
106
|
+
'cdata' => data,
|
107
|
+
},
|
108
|
+
},
|
109
|
+
]
|
110
|
+
)
|
111
|
+
|
112
|
+
assert_equal(
|
113
|
+
'<table class="spreadsheet"><tr class="odd"><th style="color: red;">one</th><th style="color: green;">two</th><th style="color: red;">three</th></tr><tr class="even"><td style="color: green;">one</td><td style="color: blue;">two</td><td style="color: green;">three</td></tr><tr class="odd"><td style="color: red;">one</td><td style="color: green;">two</td><td style="color: red;">three</td></tr></table>',
|
114
|
+
html,
|
115
|
+
'two nested level tags correct - inlined attrs'
|
116
|
+
)
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
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: 0.0.
|
4
|
+
version: 0.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-10-
|
11
|
+
date: 2015-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- t/01-load.rb
|
74
74
|
- t/02-tag.rb
|
75
75
|
- t/03-attrs.rb
|
76
|
+
- t/04-tag-attrs.rb
|
76
77
|
homepage: https://github.com/jeffa/html-autotag-ruby
|
77
78
|
licenses:
|
78
79
|
- MIT
|