HTML-AutoTag 1.0.1 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8652395df3490769d14bdcfac34679723b0d5abc
4
- data.tar.gz: 40b6c324542c872274c7bea5523cfa46cf7d6edd
3
+ metadata.gz: 0caa4fef9425233c5a1a220bd50232abfb982264
4
+ data.tar.gz: 864955619111973f765e34217ac008de48e09afc
5
5
  SHA512:
6
- metadata.gz: df802abd00b4ba155e883f60988c206fdd37df168be5713d63904683443dabeb9941b2fbc131d791561c5887da3cff8ba4ecebf81018db805efd26c0d868ab02
7
- data.tar.gz: 5a907014bbfbe83a65cd4f376537f0f977b45d6ee91c7a46f6d1fafe471407a6e4c57591b49843462f134eda9a05207c3399231229f0e5f30f8ee67a03d84898
6
+ metadata.gz: edd4ad4e0173a37124a390b69b35ad1d82377914a4d160b4cd8727d5a322de7e6e4c8bcfbedb48434aba65d07b2c14255e29ecf35cbf745a8b08220576e77e93
7
+ data.tar.gz: 742447f30494ba9a30a7136f69b51a1b6a9cf301f0243a59f59ca5a13f6a4e3967285658ae7818209bf15b75e6566c53dbf1dadc3cbb248963401e9e3ee66340
data/Changes CHANGED
@@ -1,5 +1,8 @@
1
1
  Revision history for html-autotag-ruby
2
2
 
3
+ 1.0.2
4
+ - added README for rubydoc.info
5
+
3
6
  1.0.1
4
7
  - fixed ridiculous typo introduced by trying to document
5
8
 
data/HTML-AutoTag.gemspec CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
+ spec.extra_rdoc_files = ["README"]
20
21
 
21
22
  spec.add_development_dependency "bundler", "~> 1.3"
22
23
  spec.add_development_dependency "rake"
data/README ADDED
@@ -0,0 +1,112 @@
1
+ h1. HTML::AutoTag
2
+ p. Just another HTML tag and attribute generator for ruby.
3
+
4
+ h1. Description
5
+ p. Generate HTML tags and attributes with ease (HTML4, XHTML and HTML5). Handles rotating attributes.
6
+
7
+ h1. Installation
8
+ bc. gem install HTML-AutoTag
9
+
10
+ h1. Synopsis
11
+ bc. require 'HTML/AutoTag'
12
+ auto = HTML::AutoTag.new
13
+
14
+ puts auto.tag( 'tag' => 'hr' )
15
+ puts auto.tag( 'tag' => 'h1', 'cdata' => 'heading' )
16
+ puts auto.tag( 'tag' => 'p', 'cdata' => 'paragraph', 'attr' => { 'class' => 'para' } )
17
+
18
+ attr = { 'style' => { 'color' => %w{ odd even } } }
19
+ puts auto.tag(
20
+ 'tag' => 'ol',
21
+ 'attr' => { 'reversed' => 'reversed' },
22
+ 'cdata' => %w{ 1 2 3 4 5 }.map{ |d| { 'tag' => 'li', 'attr' => attr, 'cdata' => d } }
23
+ )
24
+ end
25
+
26
+ p. Also includes HTML::AutoAttr which provides rotating attributes:
27
+ bc. require 'HTML/AutoAttr'
28
+ attr = HTML::AutoAttr.new( { 'foo' => ['bar','baz','qux'] } )
29
+ 4.times { puts attr.to_s }
30
+ end
31
+
32
+ h1. Dependencies
33
+ * htmlentities
34
+
35
+ h1. Methods
36
+ p. With the exception of new, all methods return an HTML table as a string.
37
+
38
+ * new( params )
39
+ * encodes=(boolean)
40
+ Encode HTML entities (via htmlentities)
41
+ * indent=(string)
42
+ Pretty print results.
43
+ * level=(integer)
44
+ Indentation level to start at.
45
+ * sorted=(boolean)
46
+ Sort attribute names of the tag alphabetically.
47
+
48
+ * tag( params )
49
+ * tag=(string)
50
+ The name of the tag.
51
+ * attr=(hash)
52
+ Attribute names and values for the tag.
53
+ * cdata=(string,hash,array)
54
+ The value wrapped by the tag.
55
+ * scalar - the string to be wrapped by the tag
56
+ * hash - another tag with its own cdata and attributes
57
+ * array - list of scalars or list of more hashes
58
+
59
+ h1. More Complex Example
60
+ p. The follow will render an HTML table with row that have alternating class names and cells that have alternating background colors:
61
+
62
+ bc. require 'HTML/AutoTag'
63
+ auto = HTML::AutoTag.new
64
+
65
+ tr_attr = { 'class' => %w{ odd even } }
66
+ puts auto.tag(
67
+ 'tag' => 'table',
68
+ 'attr' => { 'class' => 'spreadsheet' },
69
+ 'cdata' => Array[
70
+ {
71
+ 'tag' => 'tr',
72
+ 'attr' => tr_attr,
73
+ 'cdata' => {
74
+ 'tag' => 'th',
75
+ 'attr' => { 'style' => { 'color' => %w{ red green } } },
76
+ 'cdata' => %w{ one two three },
77
+ },
78
+ },
79
+ {
80
+ 'tag' => 'tr',
81
+ 'attr' => tr_attr,
82
+ 'cdata' => {
83
+ 'tag' => 'td',
84
+ 'attr' => { 'style' => { 'color' => %w{ green blue } } },
85
+ 'cdata' => %w{ four five six },
86
+ },
87
+ },
88
+ {
89
+ 'tag' => 'tr',
90
+ 'attr' => tr_attr,
91
+ 'cdata' => {
92
+ 'tag' => 'td',
93
+ 'attr' => { 'style' => { 'color' => %w{ red green } } },
94
+ 'cdata' => %w{ seven eight nine },
95
+ },
96
+ },
97
+ ]
98
+ )
99
+ end
100
+ p. See Spreadsheet-HTML for generating HTML tables.
101
+
102
+ h1. License
103
+ p. MIT
104
+
105
+ h1. Copyright
106
+ p. (C) 2015 Jeff Anderson -- All Rights Reserved
107
+
108
+ h1. Warranty
109
+ p. This package is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose.
110
+
111
+ h1. Author
112
+ p. Jeff Anderson jeffa@cpan.org
data/lib/HTML/AutoAttr.rb CHANGED
@@ -89,31 +89,6 @@ end
89
89
 
90
90
  =begin rdoc
91
91
 
92
- = NAME
93
-
94
- HTML::AutoAttr - Just another HTML attribute generator.
95
-
96
- == DESCRIPTION
97
-
98
- This module will translate nested hash keys and values into HTML
99
- tag attributes that can have ther values automatically rotated.
100
-
101
- == SEE ALSO
102
-
103
- * http://www.w3.org/TR/html5/syntax.html#attributes-0
104
-
105
- * http://www.w3.org/TR/html-markup/syntax.html#syntax-attributes
106
-
107
- == GITHUB
108
-
109
- The Github project is https://github.com/jeffa/html-autotag-ruby
110
-
111
- == SUPPORT
112
-
113
- You can find documentation for this module with the ri command.
114
-
115
- ri HTML::AutoAttr
116
-
117
92
  == AUTHOR
118
93
 
119
94
  Jeff Anderson, <jeffa at cpan.org>
data/lib/HTML/AutoTag.rb CHANGED
@@ -8,19 +8,6 @@ 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
- # Sort attribute names of the tag alphabetically. (boolean)
23
- #
24
11
  def initialize( params = {} )
25
12
  @encodes = params['encodes'] ? 1 : 0
26
13
  @indent = params['indent'] || ''
@@ -30,70 +17,58 @@ module HTML
30
17
  @encoder = HTMLEntities.new
31
18
  end
32
19
 
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
- #
47
- def tag( params = {} )
48
-
49
- if params['attr'].kind_of?( HTML::AutoAttr )
50
- attr = params['attr']
51
- else
52
- attr = HTML::AutoAttr.new( params['attr'] || {}, @sorted )
20
+ def tag( params )
21
+
22
+ # TODO: make these method args if possible
23
+ tag = params['tag']
24
+ attr = params['attr']
25
+ cdata = params['cdata']
26
+
27
+ unless attr.kind_of?( HTML::AutoAttr )
28
+ attr = HTML::AutoAttr.new( attr, @sorted )
53
29
  end
54
30
 
55
31
  # emtpy tag
56
- unless params['cdata'] and params['cdata'].to_s.length
57
- return ( @indent * @level ) + '<' + params['tag'] + attr.to_s + ' />' + @newline
32
+ unless cdata and cdata.to_s.length
33
+ return ( @indent * @level ) + '<' + tag + attr.to_s + ' />' + @newline
58
34
  end
59
35
 
60
- cdata = ''
36
+ rendered = ''
61
37
  no_post_indent = 0
62
- if params['cdata'].kind_of?( Array )
63
38
 
64
- if params['cdata'][0].kind_of?( Hash )
39
+ if cdata.kind_of?( Array )
65
40
 
41
+ if cdata[0].kind_of?( Hash )
66
42
  @level += 1
67
- cdata = @newline
43
+ rendered = @newline
68
44
 
69
- params['cdata'].each do |hash|
70
- cdata += tag( hash )
45
+ cdata.each do |hash|
46
+ rendered += tag( 'tag' => hash['tag'], 'attr' => hash['attr'], 'cdata' => hash['cdata'] )
71
47
  end
72
48
  @level -= 1
73
-
74
49
  else
75
50
  str = ''
76
- params['cdata'].each do |scalar|
77
- str += tag( 'tag' => params['tag'], 'attr' => attr, 'cdata' => scalar )
51
+ cdata.each do |scalar|
52
+ str += tag( 'tag' => tag, 'attr' => attr, 'cdata' => scalar )
78
53
  end
79
54
  return str
80
55
  end
81
56
 
82
- elsif params['cdata'].kind_of?( Hash )
57
+ elsif cdata.kind_of?( Hash )
83
58
  @level += 1
84
- cdata = @newline + tag( params['cdata'] )
59
+ rendered = @newline + tag( 'tag' => cdata['tag'], 'attr' => cdata['attr'], 'cdata' => cdata['cdata'] )
85
60
  @level -= 1
86
61
 
87
62
  else
88
- cdata = params['cdata']
89
- cdata = @encoder.encode( cdata ) if @encodes == 1
63
+ rendered = cdata
64
+ rendered = @encoder.encode( rendered ) if @encodes == 1
90
65
  no_post_indent = 1
91
66
  end
92
67
 
93
68
  return (@indent * @level) \
94
- + '<' + params['tag'] + attr.to_s + '>' \
95
- + cdata.to_s + ( no_post_indent == 1 ? '' : ( @indent * @level ) ) \
96
- + '</' + params['tag'] + '>' + @newline
69
+ + '<' + tag + attr.to_s + '>' \
70
+ + rendered.to_s + ( no_post_indent == 1 ? '' : ( @indent * @level ) ) \
71
+ + '</' + tag + '>' + @newline
97
72
 
98
73
  end
99
74
 
@@ -103,29 +78,6 @@ end
103
78
 
104
79
  =begin rdoc
105
80
 
106
- = NAME
107
-
108
- HTML::AutoTag - Just another HTML tag generator.
109
-
110
- == DESCRIPTION
111
-
112
- Generate nested HTML (HTML4, XHTML and HTML5) tags with custom indentation,
113
- custom encoding and automatic attribute value rotation.
114
-
115
- == SEE ALSO
116
-
117
- * http://www.w3.org/TR/html5/syntax.html
118
-
119
- == GITHUB
120
-
121
- The Github project is https://github.com/jeffa/html-autotag-ruby
122
-
123
- == SUPPORT
124
-
125
- You can find documentation for this module with the ri command.
126
-
127
- ri HTML::AutoTag
128
-
129
81
  == AUTHOR
130
82
 
131
83
  Jeff Anderson, <jeffa at cpan.org>
@@ -1,5 +1,5 @@
1
1
  module HTML
2
2
  class AutoTag
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  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.1
4
+ version: 1.0.2
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-22 00:00:00.000000000 Z
11
+ date: 2015-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -57,7 +57,8 @@ email:
57
57
  - jeffa@cpan.org
58
58
  executables: []
59
59
  extensions: []
60
- extra_rdoc_files: []
60
+ extra_rdoc_files:
61
+ - README
61
62
  files:
62
63
  - ".gitignore"
63
64
  - ".travis.yml"
@@ -65,6 +66,7 @@ files:
65
66
  - Gemfile
66
67
  - HTML-AutoTag.gemspec
67
68
  - License.md
69
+ - README
68
70
  - Rakefile
69
71
  - lib/HTML/AutoAttr.rb
70
72
  - lib/HTML/AutoTag.rb