html_tags 0.1.183

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.
Files changed (120) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +456 -0
  3. data/USAGE.md +17 -0
  4. data/doc/README.gen +256 -0
  5. data/html_tags.gemspec +48 -0
  6. data/images/logo_for_the_html_tags_project.png +0 -0
  7. data/lib/html_tags/array_registered_html_tags.rb +126 -0
  8. data/lib/html_tags/autoinclude.rb +2 -0
  9. data/lib/html_tags/autoinclude_base_module.rb +7 -0
  10. data/lib/html_tags/base/README.md +3 -0
  11. data/lib/html_tags/base/base.rb +11 -0
  12. data/lib/html_tags/base/base_module.rb +271 -0
  13. data/lib/html_tags/base/prototype.rb +19 -0
  14. data/lib/html_tags/checks.rb +58 -0
  15. data/lib/html_tags/closing_tag/closing_tag.rb +76 -0
  16. data/lib/html_tags/constants/array_strip_newlines.rb +14 -0
  17. data/lib/html_tags/constants/misc.rb +21 -0
  18. data/lib/html_tags/constants.rb +26 -0
  19. data/lib/html_tags/html_closing_tags.rb +36 -0
  20. data/lib/html_tags/html_comment.rb +29 -0
  21. data/lib/html_tags/html_tags.rb +118 -0
  22. data/lib/html_tags/html_tags_constants.rb +14 -0
  23. data/lib/html_tags/individual_tags/a.rb +646 -0
  24. data/lib/html_tags/individual_tags/abbr.rb +44 -0
  25. data/lib/html_tags/individual_tags/address.rb +50 -0
  26. data/lib/html_tags/individual_tags/area.rb +60 -0
  27. data/lib/html_tags/individual_tags/article.rb +48 -0
  28. data/lib/html_tags/individual_tags/aside.rb +80 -0
  29. data/lib/html_tags/individual_tags/audio.rb +54 -0
  30. data/lib/html_tags/individual_tags/b.rb +22 -0
  31. data/lib/html_tags/individual_tags/bdo.rb +50 -0
  32. data/lib/html_tags/individual_tags/blockquote.rb +19 -0
  33. data/lib/html_tags/individual_tags/body.rb +19 -0
  34. data/lib/html_tags/individual_tags/br.rb +28 -0
  35. data/lib/html_tags/individual_tags/button.rb +143 -0
  36. data/lib/html_tags/individual_tags/canvas.rb +19 -0
  37. data/lib/html_tags/individual_tags/caption.rb +107 -0
  38. data/lib/html_tags/individual_tags/cite.rb +78 -0
  39. data/lib/html_tags/individual_tags/code.rb +105 -0
  40. data/lib/html_tags/individual_tags/del.rb +112 -0
  41. data/lib/html_tags/individual_tags/details.rb +79 -0
  42. data/lib/html_tags/individual_tags/dialog.rb +108 -0
  43. data/lib/html_tags/individual_tags/div.rb +99 -0
  44. data/lib/html_tags/individual_tags/em.rb +99 -0
  45. data/lib/html_tags/individual_tags/fieldset.rb +88 -0
  46. data/lib/html_tags/individual_tags/figure.rb +42 -0
  47. data/lib/html_tags/individual_tags/footer.rb +61 -0
  48. data/lib/html_tags/individual_tags/form.rb +93 -0
  49. data/lib/html_tags/individual_tags/h1.rb +48 -0
  50. data/lib/html_tags/individual_tags/h2.rb +46 -0
  51. data/lib/html_tags/individual_tags/h3.rb +78 -0
  52. data/lib/html_tags/individual_tags/h4.rb +36 -0
  53. data/lib/html_tags/individual_tags/h5.rb +36 -0
  54. data/lib/html_tags/individual_tags/h6.rb +40 -0
  55. data/lib/html_tags/individual_tags/head.rb +47 -0
  56. data/lib/html_tags/individual_tags/header.rb +54 -0
  57. data/lib/html_tags/individual_tags/hgroup.rb +78 -0
  58. data/lib/html_tags/individual_tags/html.rb +61 -0
  59. data/lib/html_tags/individual_tags/i.rb +47 -0
  60. data/lib/html_tags/individual_tags/iframe.rb +131 -0
  61. data/lib/html_tags/individual_tags/img.rb +135 -0
  62. data/lib/html_tags/individual_tags/input.rb +96 -0
  63. data/lib/html_tags/individual_tags/ins.rb +102 -0
  64. data/lib/html_tags/individual_tags/kbd.rb +109 -0
  65. data/lib/html_tags/individual_tags/keygen.rb +90 -0
  66. data/lib/html_tags/individual_tags/label.rb +77 -0
  67. data/lib/html_tags/individual_tags/legend.rb +48 -0
  68. data/lib/html_tags/individual_tags/li.rb +74 -0
  69. data/lib/html_tags/individual_tags/link.rb +58 -0
  70. data/lib/html_tags/individual_tags/main.rb +29 -0
  71. data/lib/html_tags/individual_tags/map.rb +95 -0
  72. data/lib/html_tags/individual_tags/mark.rb +78 -0
  73. data/lib/html_tags/individual_tags/menu.rb +79 -0
  74. data/lib/html_tags/individual_tags/nav.rb +64 -0
  75. data/lib/html_tags/individual_tags/object.rb +76 -0
  76. data/lib/html_tags/individual_tags/ol.rb +50 -0
  77. data/lib/html_tags/individual_tags/p.rb +92 -0
  78. data/lib/html_tags/individual_tags/pre.rb +16 -0
  79. data/lib/html_tags/individual_tags/progress.rb +114 -0
  80. data/lib/html_tags/individual_tags/script.rb +22 -0
  81. data/lib/html_tags/individual_tags/source.rb +42 -0
  82. data/lib/html_tags/individual_tags/span.rb +95 -0
  83. data/lib/html_tags/individual_tags/strong.rb +17 -0
  84. data/lib/html_tags/individual_tags/style.rb +29 -0
  85. data/lib/html_tags/individual_tags/summary.rb +77 -0
  86. data/lib/html_tags/individual_tags/sup.rb +57 -0
  87. data/lib/html_tags/individual_tags/table.rb +90 -0
  88. data/lib/html_tags/individual_tags/tbody.rb +19 -0
  89. data/lib/html_tags/individual_tags/td.rb +30 -0
  90. data/lib/html_tags/individual_tags/textarea.rb +72 -0
  91. data/lib/html_tags/individual_tags/th.rb +50 -0
  92. data/lib/html_tags/individual_tags/thead.rb +53 -0
  93. data/lib/html_tags/individual_tags/time.rb +50 -0
  94. data/lib/html_tags/individual_tags/title.rb +59 -0
  95. data/lib/html_tags/individual_tags/tr.rb +50 -0
  96. data/lib/html_tags/individual_tags/track.rb +59 -0
  97. data/lib/html_tags/individual_tags/u.rb +47 -0
  98. data/lib/html_tags/individual_tags/ul.rb +23 -0
  99. data/lib/html_tags/individual_tags/var.rb +46 -0
  100. data/lib/html_tags/individual_tags/video.rb +70 -0
  101. data/lib/html_tags/module.rb +5 -0
  102. data/lib/html_tags/opening_tag/opening_tag.rb +288 -0
  103. data/lib/html_tags/project/project_base_directory.rb +23 -0
  104. data/lib/html_tags/requires/require_the_html_tags_project.rb +9 -0
  105. data/lib/html_tags/requires/require_the_img_tag.rb +7 -0
  106. data/lib/html_tags/shared.rb +23 -0
  107. data/lib/html_tags/stag.rb +54 -0
  108. data/lib/html_tags/toplevel_methods/add.rb +22 -0
  109. data/lib/html_tags/toplevel_methods/full_output.rb +33 -0
  110. data/lib/html_tags/toplevel_methods/newline_or_empty.rb +21 -0
  111. data/lib/html_tags/toplevel_methods/strip_newlines.rb +27 -0
  112. data/lib/html_tags/version/version.rb +17 -0
  113. data/lib/html_tags/yaml/available_html_tags.yml +135 -0
  114. data/lib/html_tags/yaml/valid_tags_in_a_head_tag.yml +16 -0
  115. data/lib/html_tags.rb +5 -0
  116. data/test/testing_html_tags.rb +158 -0
  117. data/test/testing_the_a_tag.rb +162 -0
  118. data/test/testing_the_button_tag.rb +37 -0
  119. data/test/testing_the_details_tag.rb +38 -0
  120. metadata +171 -0
data/doc/README.gen ADDED
@@ -0,0 +1,256 @@
1
+ DEFAULT_HEADER
2
+
3
+ ## Introduction to the HtmlTags gem
4
+
5
+ <img src="https://i.imgur.com/A1MaV0i.png" style="margin: 1em">
6
+
7
+ The <b>HtmlTags gem</b> is a somewhat small gem that will try to
8
+ <b>autogenerate Strings</b> put into methods resembling the
9
+ available HTML tags.
10
+
11
+ Let's next have a look at a specific example supporting this statement.
12
+
13
+ Take the following method call in Ruby:
14
+
15
+ span('foo')
16
+
17
+ So, we call the method span() and pass the String 'foo' into it. The
18
+ method .span() can be found as part of the HtmlTags gem.
19
+
20
+ This will be expanded towards the following String:
21
+
22
+ <span>foo</span>
23
+
24
+ In other words: the HtmlTags gem can be used to autogenerate
25
+ HTML code.
26
+
27
+ This functionality is then made available to other projects, which
28
+ can tap into that functionality, in particular the gem <b>cyberweb</b>.
29
+ I use the latter gem for my custom cgi/sinatra/rails projects.
30
+
31
+ The code that was part in the html_tags gem originally used to
32
+ be part of the <b>cyberweb</b> gem in the past, until <b>html_tags</b>
33
+ became a standalone gem, in the year <b>2013</b>.
34
+
35
+ ## Goals and Objectives for the HtmlTags gem
36
+
37
+ The HtmlTags gem has various goals, some of which are more important
38
+ than others.
39
+
40
+ In no particular order, here are the different goals for this gem:
41
+
42
+ - Provide a way to generate all valid HTML tags, in particular for HTML5.
43
+ - Provide useful documentation as to how to use this project.
44
+ - Make the code as consistent as possible, unless the specific HTML tag at hand requires a different treatment
45
+ - Make the HtmlTags as self-contained as possible, e. g. no external dependencies.
46
+ - Make the HtmlTags as useful as possible, by also providing helper code unrelated to HTML-tags itself.
47
+ - Document the HTML that is supported by the gem.
48
+
49
+ ## New ideas (playground for new ideas)
50
+
51
+ We could replace code elements such as:
52
+
53
+ <button onclick="show_source()">Click me</button>
54
+
55
+ With:
56
+
57
+ button.text('Click me').onclick('show_source')
58
+
59
+ Or perhaps simple:
60
+
61
+ button('Click me').on_clicked {
62
+ show_source
63
+ }
64
+
65
+ This is currently not implemented, though. Need to think more about
66
+ it first.
67
+
68
+ ## Using HTML headers
69
+
70
+ The following example shows how to use the <b>h1 tag</b> via
71
+ HtmlTags:
72
+
73
+ HtmlTags.h1('Hello world!') # => "<h1>\nHello world!\n</h1>"
74
+
75
+ You can include the module HtmlTags. Then you can just type <b>h1()</b>
76
+ directly.
77
+
78
+ Another example, this time for the <b>div tag</b>:
79
+
80
+ name = 'Joe'
81
+ puts HtmlTags.div("Hello, #{name}!") # => <div>Hello, Joe!</div>
82
+
83
+ ## HtmlTags.a
84
+
85
+ The HTML <b>a</b> tag is for hyperlinks; typically it contains a
86
+ **href** entry.
87
+
88
+ You can pass in a Hash, too, including a few supported JavaScript
89
+ functions.
90
+
91
+ Example for the latter:
92
+
93
+ onclick: 'change_the_colour_to()'
94
+
95
+ Note that you still have to write the function somewhere and pull it
96
+ into the .html file (or .cgi file or whatever else you are using).
97
+
98
+ I added support for this in <b>October 2021</b>, as I needed to have clickable
99
+ links that change colour upon being clicked. I used that to memorize
100
+ which links I clicked, without having to depend on CSS.
101
+
102
+ ## Objectified HTML Tags
103
+
104
+ This is mostly for clarification. An objectified HTML tag is
105
+ a HTML tag that can be used like an object.
106
+
107
+ Example:
108
+
109
+ Span.new('Hello world!') # => <span>Hello world!</span>
110
+
111
+ The html_tags gem currently does not support this, but support for this
112
+ may be added in the future, depending on whether that use case turns
113
+ out to be sufficiently useful.
114
+
115
+ ## How to use HtmlTags.span()
116
+
117
+ The span-tag in HTML creates something like this:
118
+
119
+ <span>Hello world!</span>
120
+
121
+ To attach a CSS class to this, in HTML, one can use something such
122
+ as:
123
+
124
+ <span class="padl1em">Hello world!</span>
125
+
126
+ This is simple HTML.
127
+
128
+ The html_tags gem also allows these use cases.
129
+
130
+ For instance, consider the following:
131
+
132
+ e HtmlTags.span('Hey there')
133
+
134
+ This is equivalent to the first variant shown before.
135
+
136
+ The actual output will be:
137
+
138
+ <span>
139
+ Hey there</span>
140
+
141
+ So there is a newline after the starting span-tag. The
142
+ reason as to this is that I feel that, for readability,
143
+ it is better to have a newline show up if you want to
144
+ do a view-source action on the resulting .html file.
145
+
146
+ Not everyone may want this, so we may need to have to
147
+ add a toggle to strip newlines there. But for the time
148
+ being this has to suffice.
149
+
150
+ ## How to use HtmlTags.a()
151
+
152
+ Usage example for how to use <b>HtmlTags.a()</b>:
153
+
154
+ HtmlTags.a(
155
+ remote_url: remote_url,
156
+ text: title?.to_s,
157
+ css_style: 'font-weight: bold; color: darkblue'
158
+ )
159
+
160
+ ## The structure of opening and closing tags
161
+
162
+ This subsection just shows a tiny bit of the structure behind
163
+ opening and closing tags.
164
+
165
+ Consider a HTML a tag such as:
166
+
167
+ <a>
168
+
169
+ This has three components: <b><</b>, <b>a</b> and <b>></b>.
170
+
171
+ These <b>three components</b> are, in order, called:
172
+
173
+ - opening bracket
174
+ - element ID
175
+ - closing bracket
176
+
177
+ The closing tag, that is:
178
+
179
+ </a>
180
+
181
+ Has one more component, the /, also called the forward slash
182
+ (unsurprisingly so).
183
+
184
+ Note that an opening tag can contain attributes.
185
+
186
+ ## The bdo tag
187
+
188
+ <b>bdo</b> stands for <b>bi-directional override</b>.
189
+
190
+ The purpose of the bdo tag in HTML is to specify the text direction
191
+ or to override the current text direction. This is important
192
+ for languages such as <b>Arabic</b> or <b>Hebrew</b>.
193
+
194
+ Personally I do not really need this tag, but in the event that
195
+ other users of the <b>html_tag</b> gem need support for the bdo-tag,
196
+ support for it has been added to the html_tag gem in <b>June 2023</b>.
197
+
198
+ The <b>bdo tag</b> has a special attribute called <b>dir</b> - an
199
+ abbreviation standing for <b>direction</b>.
200
+
201
+ The dir attribute specifies the direction in which the text will
202
+ be displayed.
203
+
204
+ Only two values are permissive for the dir attribute:
205
+
206
+ (1) <b>ltr</b>: It means left to right. The text inside the bdo tag will
207
+ be rendered from left to right. This is the default value.
208
+
209
+ (2) <b>rtl</b>: It means right to left. The text inside the bdo tag
210
+ will be rendered from right to left.
211
+
212
+ Note that you can use the CSS class rtl-lang instead, so I am not
213
+ sure why that HTML tag is necessary.
214
+
215
+ At any rate, an invocation example follows:
216
+
217
+ HtmlTags.bdo()
218
+
219
+ ## Working with HTML tables
220
+
221
+ You can use <b>HtmlTags.table</b> to create a String that represents
222
+ a HTML table. In January 2024 this functionality was extended a bit,
223
+ in that you can pass an Array to this method, via the block form.
224
+ That Array will be used as content for the HTML table at hand.
225
+
226
+ Usage example is this API:
227
+
228
+ puts HtmlTags.table(nil,'mars1em','test_table','border:1px solid rand') {
229
+ %w( abc def ghi jkl )
230
+ }
231
+
232
+ This would generate the following String:
233
+
234
+ <table class="mars1em" id="test_table" style="border:1px solid rand">
235
+ <tr><td>
236
+ abc</td><td>
237
+ def</td></tr><tr><td>
238
+ ghi</td><td>
239
+ jkl</td></tr>
240
+ </table>
241
+
242
+ Quite convenient, isn't it?
243
+
244
+ ## Available HTML tags
245
+
246
+ The following HTML tags are valid, in <b>HTML5</b>:
247
+
248
+ DISPLAY_THIS_FILE /home/x/programming/ruby/src/html_tags/lib/html_tags/yaml/available_html_tags.yml
249
+
250
+ In the long run the HtmlTags project should offer support
251
+ for <b>all</b> these HTML tags. This applies mostly to HTML5-tags
252
+ though; for instance, the <b>acronym tag</b> is no longer valid
253
+ in HTML5, and will thus not be supported by the html_tags
254
+ project.
255
+
256
+ ADD_EMAIL
data/html_tags.gemspec ADDED
@@ -0,0 +1,48 @@
1
+ # =========================================================================== #
2
+ # Gemspec for Project HtmlTags.
3
+ # =========================================================================== #
4
+ require 'html_tags/version/version.rb'
5
+ require 'roebe/toplevel_methods/misc.rb'
6
+
7
+ Gem::Specification.new { |s|
8
+
9
+ s.name = 'html_tags'
10
+ s.version = HtmlTags::VERSION
11
+ s.date = Time.now.strftime('%Y-%m-%d')
12
+
13
+ DESCRIPTION = <<-EOF
14
+
15
+ This library is called html_tags.
16
+
17
+ Its fundamental core idea is to collect all valid html tags into
18
+ a single project, and then make this data available to other
19
+ projects.
20
+
21
+ Other ideas are to autogenerate closing tags (helper
22
+ methods), and of course to generate string representations
23
+ of these html tags. This can then be used by other
24
+ web-projects.
25
+
26
+ A simple usage example follows:
27
+
28
+ require 'html_tags'
29
+ HtmlTags.p 'hello world!' # => "<p>\nhello world!\n</p>"
30
+
31
+ EOF
32
+
33
+ s.summary = DESCRIPTION
34
+ s.description = DESCRIPTION
35
+ s.extra_rdoc_files = %w()
36
+
37
+ s.authors = ['Robert A. Heiler']
38
+ s.email = Roebe.email?
39
+ s.files = Dir['**/*']
40
+ s.files << 'USAGE.md'
41
+ s.license = 'MIT'
42
+ s.homepage = 'https://rubygems.org/gems/html_tags'
43
+
44
+ s.required_ruby_version = '>= '+Roebe.third_most_stable_version_of_ruby
45
+ s.required_rubygems_version = '>= '+Gem::VERSION
46
+ s.rubygems_version = '>= '+Gem::VERSION
47
+
48
+ }
@@ -0,0 +1,126 @@
1
+ module HtmlTags # require 'html_tags/array_registered_html_tags.rb'
2
+
3
+ # ========================================================================= #
4
+ # === ARRAY_REGISTERED_HTML_TAGS
5
+ #
6
+ # Please also add to this array whenever you add a new html tag.
7
+ #
8
+ # Sort alphabetically.
9
+ #
10
+ # For references, look at the periodic table for HTML tags to find out
11
+ # which ones are available:
12
+ #
13
+ # https://developer.mozilla.org/en-US/docs/Web/HTML/Element
14
+ # https://developer.mozilla.org/de/docs/Web/HTML/Element
15
+ #
16
+ # In January 2014 it stated that 107 Elements are known. However, the
17
+ # mozilla reference in March 2015 listed 136 HTML elements.
18
+ #
19
+ # <b> is no longer valid in HTML5 it seems.
20
+ # ========================================================================= #
21
+ ARRAY_REGISTERED_HTML_TAGS = %w(
22
+
23
+ a
24
+ abbr
25
+ audio
26
+
27
+ b
28
+ blockquote
29
+ body
30
+ br
31
+ button
32
+
33
+ canvas
34
+
35
+ div
36
+ dd
37
+ dl
38
+ dt
39
+
40
+ fieldset
41
+ figure
42
+ form
43
+
44
+ head
45
+ html
46
+ h1
47
+ h2
48
+ h3
49
+ h4
50
+ h5
51
+ h6
52
+ hr
53
+
54
+ i
55
+ img
56
+ input
57
+
58
+ label
59
+ legend
60
+ li
61
+
62
+ nav
63
+
64
+ object
65
+
66
+ p
67
+ pre
68
+
69
+ q
70
+
71
+ span
72
+ strong
73
+ style
74
+
75
+ table
76
+ tbody
77
+ td
78
+ textarea
79
+ th
80
+ thead
81
+ tr
82
+
83
+ ul
84
+
85
+ )#+ # The following elements I did not yet think about much at all
86
+ # We may add these one after the other eventually though.
87
+ # %w(
88
+ # html head span title # meta rt base rp link noscript
89
+ # style script dfn abbr q cite em time var samp i b
90
+ # sub sup small strong mark ruby ins del bdi bdo s
91
+ # kbd wbr code br hr figcaption figure p ol ul li
92
+ # div pre blockquote fieldset metr legend
93
+ # label input textarea form select opgroup option
94
+ # output button body aside address datalist keygen
95
+ # progress h1 h2 h3 h4 h5 h6 section header nav
96
+ # article footer hgroup col colgroup caption menu
97
+ # command summary details table tr td th tbody thead
98
+ # tfoot img area map embed object param source iframe
99
+ # canvas track audio video
100
+ #)
101
+
102
+ # ========================================================================= #
103
+ # === ARRAY_TAGS_WITHOUT_CLOSING_TAG
104
+ #
105
+ # The following array keeps track of which tags have no closing tag.
106
+ # Please sort alphabetically.
107
+ # ========================================================================= #
108
+ # The <img> tag is no longer a part of the above Array since as
109
+ # of June 2016.
110
+ # ========================================================================= #
111
+ ARRAY_TAGS_WITHOUT_CLOSING_TAG = %w(
112
+
113
+ br
114
+
115
+ )
116
+
117
+ # ========================================================================= #
118
+ # === registered_html_tags?
119
+ #
120
+ # Feedback all registered HTML tags next.
121
+ # ========================================================================= #
122
+ def registered_html_tags?
123
+ Kernel.p ARRAY_REGISTERED_HTML_TAGS
124
+ end
125
+
126
+ end
@@ -0,0 +1,2 @@
1
+ require 'html_tags'
2
+ include HtmlTags
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'html_tags'
6
+
7
+ include HtmlTags::BaseModule
@@ -0,0 +1,3 @@
1
+ Code in this directory can be used to subclass from a HtmlTags::Base
2
+ class that may allow you to make use of the registered html-tags in
3
+ this project.
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'html_tags/base/base.rb'
6
+ # =========================================================================== #
7
+ module HtmlTags
8
+
9
+ class Base
10
+
11
+ end; end