HTML-AutoTag 0.0.6 → 1.0.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.
- checksums.yaml +4 -4
- data/Changes +4 -0
- data/lib/HTML/AutoAttr.rb +14 -9
- data/lib/HTML/AutoTag/version.rb +1 -1
- data/lib/HTML/AutoTag.rb +27 -95
- data/readme.md +52 -10
- 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: fb83f536fbdc2af2549f681476bffd8a32dca63a
|
4
|
+
data.tar.gz: 329e0118abbc2912b8e3e0a86d1d337d789430f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80bc6faa0dcb51294abc07acfe8017db7e0868d75a0a346449d78976d433e49635e144606d37306b0a3c92fc6c3337185465682750afec419b7e221bdd8e73d6
|
7
|
+
data.tar.gz: 11b7b16d6e36c54c582122dc2130a0510b99b6a3295ebf43619fb2c264e0f332ed7a1e766ed4f4c88c6dba10f9d6ef10b86b78028f6b7d3daeeb8a904dacacbc
|
data/Changes
CHANGED
data/lib/HTML/AutoAttr.rb
CHANGED
@@ -4,11 +4,20 @@ module HTML
|
|
4
4
|
|
5
5
|
attr_accessor 'hash', 'sorted'
|
6
6
|
|
7
|
+
# expects the following arguments
|
8
|
+
# * hash
|
9
|
+
# Contains attribute keys and values
|
10
|
+
#
|
11
|
+
# * sorted
|
12
|
+
# Boolean. Whether or not to render attributes in alphabetical order.
|
13
|
+
#
|
7
14
|
def initialize( hash = {}, sorted = 0 )
|
8
15
|
@hash = hash
|
9
16
|
@sorted = sorted
|
10
17
|
end
|
11
18
|
|
19
|
+
# expects no arguments, emits string containing rendered key/value pairs
|
20
|
+
#
|
12
21
|
def to_s
|
13
22
|
|
14
23
|
return '' unless @hash.kind_of?( Hash )
|
@@ -29,24 +38,29 @@ module HTML
|
|
29
38
|
return str
|
30
39
|
end
|
31
40
|
|
41
|
+
# expects one argument: the key to scrub
|
32
42
|
def key( key )
|
33
43
|
key = key.gsub( /\s+/, '' )
|
34
44
|
key = key.gsub( /["'>=\/]/, '' )
|
35
45
|
return key
|
36
46
|
end
|
37
47
|
|
48
|
+
# expects one argument: the value to scrub
|
38
49
|
def val( val )
|
39
50
|
return '' if val.match( /^\s+$/ )
|
40
51
|
val = val.gsub( /"/, '' )
|
41
52
|
return val
|
42
53
|
end
|
43
54
|
|
55
|
+
# expects one argument: the array to rotate
|
56
|
+
# returns the first element before array is rotated
|
44
57
|
def rotate( array )
|
45
58
|
val = array.shift
|
46
59
|
array.push( val )
|
47
60
|
return val
|
48
61
|
end
|
49
62
|
|
63
|
+
# expects one argument: the hash to 'stringify'
|
50
64
|
def stringify( hash )
|
51
65
|
|
52
66
|
keys = @sorted ? hash.keys.sort : hash.keys
|
@@ -75,15 +89,6 @@ end
|
|
75
89
|
|
76
90
|
HTML::AutoAttr - Just another HTML attribute generator.
|
77
91
|
|
78
|
-
== SYNOPSIS
|
79
|
-
|
80
|
-
<code>
|
81
|
-
require 'HTML/AutoAttr'
|
82
|
-
attr = HTML::AutoAttr.new( { 'foo' => ['bar','baz','qux'] } )
|
83
|
-
|
84
|
-
4.times { puts attr.to_s }
|
85
|
-
</code>
|
86
|
-
|
87
92
|
== DESCRIPTION
|
88
93
|
|
89
94
|
This module will translate nested hash keys and values into HTML
|
data/lib/HTML/AutoTag/version.rb
CHANGED
data/lib/HTML/AutoTag.rb
CHANGED
@@ -8,6 +8,19 @@ module HTML
|
|
8
8
|
|
9
9
|
attr_accessor 'encodes', 'indent', 'level', 'sorted', 'newline'
|
10
10
|
|
11
|
+
# params expects the following keys:
|
12
|
+
# * encodes
|
13
|
+
# Endcode HTML entities. (boolean)
|
14
|
+
#
|
15
|
+
# * indent
|
16
|
+
# Pretty print results. (string)
|
17
|
+
#
|
18
|
+
# * level
|
19
|
+
# Indentation level to start at. (integer)
|
20
|
+
#
|
21
|
+
# * sorted
|
22
|
+
#
|
23
|
+
Sort attribute names of the tag alphabetically. (boolean)
|
11
24
|
def initialize( params = {} )
|
12
25
|
@encodes = params['encodes'] ? 1 : 0
|
13
26
|
@indent = params['indent'] || ''
|
@@ -17,6 +30,20 @@ module HTML
|
|
17
30
|
@encoder = HTMLEntities.new
|
18
31
|
end
|
19
32
|
|
33
|
+
# params expects the following keys:
|
34
|
+
#
|
35
|
+
# * tag
|
36
|
+
# The name of the tag. (string)
|
37
|
+
#
|
38
|
+
# * attr
|
39
|
+
# Attributes and values for the tag (hash)
|
40
|
+
#
|
41
|
+
# * cdata
|
42
|
+
# The value wrapped by the tag. Types allowed are:
|
43
|
+
# * scalar - the string to be wrapped by the tag
|
44
|
+
# * hash - another tag with its own cdata and attributes
|
45
|
+
# * array - list of scalars or list of more hashes
|
46
|
+
#
|
20
47
|
def tag( params = {} )
|
21
48
|
|
22
49
|
if params['attr'].kind_of?( HTML::AutoAttr )
|
@@ -80,106 +107,11 @@ end
|
|
80
107
|
|
81
108
|
HTML::AutoTag - Just another HTML tag generator.
|
82
109
|
|
83
|
-
== SYNOPSIS
|
84
|
-
|
85
|
-
<code>
|
86
|
-
require 'HTML/AutoTag'
|
87
|
-
tag = HTML::AutoTag.new
|
88
|
-
|
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
|
-
)
|
132
|
-
</code>
|
133
|
-
|
134
110
|
== DESCRIPTION
|
135
111
|
|
136
112
|
Generate nested HTML (HTML4, XHTML and HTML5) tags with custom indentation,
|
137
113
|
custom encoding and automatic attribute value rotation.
|
138
114
|
|
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
|
-
|
183
115
|
== SEE ALSO
|
184
116
|
|
185
117
|
* http://www.w3.org/TR/html5/syntax.html
|
data/readme.md
CHANGED
@@ -10,26 +10,68 @@ Synopsis
|
|
10
10
|
--------
|
11
11
|
```ruby
|
12
12
|
require 'HTML/AutoTag'
|
13
|
+
auto = HTML::AutoTag.new
|
13
14
|
|
14
|
-
auto
|
15
|
-
|
16
|
-
puts auto.tag( 'tag' => 'p', 'cdata' => '
|
17
|
-
|
18
|
-
attr = { 'style' => { 'color' => %w{ red green } } }
|
19
|
-
data = %w{ one two three four five six seven eight }
|
15
|
+
puts auto.tag( 'tag' => 'hr' )
|
16
|
+
puts auto.tag( 'tag' => 'h1', 'cdata' => 'heading' )
|
17
|
+
puts auto.tag( 'tag' => 'p', 'cdata' => 'paragraph', 'attr' => { 'class' => 'para' } )
|
20
18
|
|
19
|
+
attr = { 'style' => { 'color' => %w{ odd even } } }
|
21
20
|
puts auto.tag(
|
22
21
|
'tag' => 'ol',
|
23
22
|
'attr' => { 'reversed' => 'reversed' },
|
24
|
-
'cdata' =>
|
23
|
+
'cdata' => %w{ 1 2 3 4 5 }.map{ |d| { 'tag' => 'li', 'attr' => attr, 'cdata' => d } }
|
24
|
+
)
|
25
|
+
|
26
|
+
tr_attr = { 'class' => %w{ odd even } }
|
27
|
+
puts auto.tag(
|
28
|
+
'tag' => 'table',
|
29
|
+
'attr' => { 'class' => 'spreadsheet' },
|
30
|
+
'cdata' => Array[
|
31
|
+
{
|
32
|
+
'tag' => 'tr',
|
33
|
+
'attr' => tr_attr,
|
34
|
+
'cdata' => {
|
35
|
+
'tag' => 'th',
|
36
|
+
'attr' => { 'style' => { 'color' => %w{ red green } } },
|
37
|
+
'cdata' => %w{ one two three },
|
38
|
+
},
|
39
|
+
},
|
40
|
+
{
|
41
|
+
'tag' => 'tr',
|
42
|
+
'attr' => tr_attr,
|
43
|
+
'cdata' => {
|
44
|
+
'tag' => 'td',
|
45
|
+
'attr' => { 'style' => { 'color' => %w{ green blue } } },
|
46
|
+
'cdata' => %w{ four five six },
|
47
|
+
},
|
48
|
+
},
|
49
|
+
{
|
50
|
+
'tag' => 'tr',
|
51
|
+
'attr' => tr_attr,
|
52
|
+
'cdata' => {
|
53
|
+
'tag' => 'td',
|
54
|
+
'attr' => { 'style' => { 'color' => %w{ red green } } },
|
55
|
+
'cdata' => %w{ seven eight nine },
|
56
|
+
},
|
57
|
+
},
|
58
|
+
]
|
25
59
|
)
|
26
60
|
```
|
61
|
+
Also includes HTML::AutoAttr which provides rotating attributes:
|
62
|
+
```ruby
|
63
|
+
require 'HTML/AutoAttr'
|
64
|
+
|
65
|
+
attr = HTML::AutoAttr.new( { 'foo' => ['bar','baz','qux'] } )
|
66
|
+
|
67
|
+
4.times { puts attr.to_s }
|
68
|
+
```
|
27
69
|
|
28
70
|
Installation
|
29
71
|
------------
|
30
|
-
|
31
|
-
|
32
|
-
|
72
|
+
```
|
73
|
+
gem install HTML-AutoTag
|
74
|
+
```
|
33
75
|
|
34
76
|
License and Copyright
|
35
77
|
---------------------
|
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: 1.0.0
|
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-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|