html_tags 0.1.183
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +456 -0
- data/USAGE.md +17 -0
- data/doc/README.gen +256 -0
- data/html_tags.gemspec +48 -0
- data/images/logo_for_the_html_tags_project.png +0 -0
- data/lib/html_tags/array_registered_html_tags.rb +126 -0
- data/lib/html_tags/autoinclude.rb +2 -0
- data/lib/html_tags/autoinclude_base_module.rb +7 -0
- data/lib/html_tags/base/README.md +3 -0
- data/lib/html_tags/base/base.rb +11 -0
- data/lib/html_tags/base/base_module.rb +271 -0
- data/lib/html_tags/base/prototype.rb +19 -0
- data/lib/html_tags/checks.rb +58 -0
- data/lib/html_tags/closing_tag/closing_tag.rb +76 -0
- data/lib/html_tags/constants/array_strip_newlines.rb +14 -0
- data/lib/html_tags/constants/misc.rb +21 -0
- data/lib/html_tags/constants.rb +26 -0
- data/lib/html_tags/html_closing_tags.rb +36 -0
- data/lib/html_tags/html_comment.rb +29 -0
- data/lib/html_tags/html_tags.rb +118 -0
- data/lib/html_tags/html_tags_constants.rb +14 -0
- data/lib/html_tags/individual_tags/a.rb +646 -0
- data/lib/html_tags/individual_tags/abbr.rb +44 -0
- data/lib/html_tags/individual_tags/address.rb +50 -0
- data/lib/html_tags/individual_tags/area.rb +60 -0
- data/lib/html_tags/individual_tags/article.rb +48 -0
- data/lib/html_tags/individual_tags/aside.rb +80 -0
- data/lib/html_tags/individual_tags/audio.rb +54 -0
- data/lib/html_tags/individual_tags/b.rb +22 -0
- data/lib/html_tags/individual_tags/bdo.rb +50 -0
- data/lib/html_tags/individual_tags/blockquote.rb +19 -0
- data/lib/html_tags/individual_tags/body.rb +19 -0
- data/lib/html_tags/individual_tags/br.rb +28 -0
- data/lib/html_tags/individual_tags/button.rb +143 -0
- data/lib/html_tags/individual_tags/canvas.rb +19 -0
- data/lib/html_tags/individual_tags/caption.rb +107 -0
- data/lib/html_tags/individual_tags/cite.rb +78 -0
- data/lib/html_tags/individual_tags/code.rb +105 -0
- data/lib/html_tags/individual_tags/del.rb +112 -0
- data/lib/html_tags/individual_tags/details.rb +79 -0
- data/lib/html_tags/individual_tags/dialog.rb +108 -0
- data/lib/html_tags/individual_tags/div.rb +99 -0
- data/lib/html_tags/individual_tags/em.rb +99 -0
- data/lib/html_tags/individual_tags/fieldset.rb +88 -0
- data/lib/html_tags/individual_tags/figure.rb +42 -0
- data/lib/html_tags/individual_tags/footer.rb +61 -0
- data/lib/html_tags/individual_tags/form.rb +93 -0
- data/lib/html_tags/individual_tags/h1.rb +48 -0
- data/lib/html_tags/individual_tags/h2.rb +46 -0
- data/lib/html_tags/individual_tags/h3.rb +78 -0
- data/lib/html_tags/individual_tags/h4.rb +36 -0
- data/lib/html_tags/individual_tags/h5.rb +36 -0
- data/lib/html_tags/individual_tags/h6.rb +40 -0
- data/lib/html_tags/individual_tags/head.rb +47 -0
- data/lib/html_tags/individual_tags/header.rb +54 -0
- data/lib/html_tags/individual_tags/hgroup.rb +78 -0
- data/lib/html_tags/individual_tags/html.rb +61 -0
- data/lib/html_tags/individual_tags/i.rb +47 -0
- data/lib/html_tags/individual_tags/iframe.rb +131 -0
- data/lib/html_tags/individual_tags/img.rb +135 -0
- data/lib/html_tags/individual_tags/input.rb +96 -0
- data/lib/html_tags/individual_tags/ins.rb +102 -0
- data/lib/html_tags/individual_tags/kbd.rb +109 -0
- data/lib/html_tags/individual_tags/keygen.rb +90 -0
- data/lib/html_tags/individual_tags/label.rb +77 -0
- data/lib/html_tags/individual_tags/legend.rb +48 -0
- data/lib/html_tags/individual_tags/li.rb +74 -0
- data/lib/html_tags/individual_tags/link.rb +58 -0
- data/lib/html_tags/individual_tags/main.rb +29 -0
- data/lib/html_tags/individual_tags/map.rb +95 -0
- data/lib/html_tags/individual_tags/mark.rb +78 -0
- data/lib/html_tags/individual_tags/menu.rb +79 -0
- data/lib/html_tags/individual_tags/nav.rb +64 -0
- data/lib/html_tags/individual_tags/object.rb +76 -0
- data/lib/html_tags/individual_tags/ol.rb +50 -0
- data/lib/html_tags/individual_tags/p.rb +92 -0
- data/lib/html_tags/individual_tags/pre.rb +16 -0
- data/lib/html_tags/individual_tags/progress.rb +114 -0
- data/lib/html_tags/individual_tags/script.rb +22 -0
- data/lib/html_tags/individual_tags/source.rb +42 -0
- data/lib/html_tags/individual_tags/span.rb +95 -0
- data/lib/html_tags/individual_tags/strong.rb +17 -0
- data/lib/html_tags/individual_tags/style.rb +29 -0
- data/lib/html_tags/individual_tags/summary.rb +77 -0
- data/lib/html_tags/individual_tags/sup.rb +57 -0
- data/lib/html_tags/individual_tags/table.rb +90 -0
- data/lib/html_tags/individual_tags/tbody.rb +19 -0
- data/lib/html_tags/individual_tags/td.rb +30 -0
- data/lib/html_tags/individual_tags/textarea.rb +72 -0
- data/lib/html_tags/individual_tags/th.rb +50 -0
- data/lib/html_tags/individual_tags/thead.rb +53 -0
- data/lib/html_tags/individual_tags/time.rb +50 -0
- data/lib/html_tags/individual_tags/title.rb +59 -0
- data/lib/html_tags/individual_tags/tr.rb +50 -0
- data/lib/html_tags/individual_tags/track.rb +59 -0
- data/lib/html_tags/individual_tags/u.rb +47 -0
- data/lib/html_tags/individual_tags/ul.rb +23 -0
- data/lib/html_tags/individual_tags/var.rb +46 -0
- data/lib/html_tags/individual_tags/video.rb +70 -0
- data/lib/html_tags/module.rb +5 -0
- data/lib/html_tags/opening_tag/opening_tag.rb +288 -0
- data/lib/html_tags/project/project_base_directory.rb +23 -0
- data/lib/html_tags/requires/require_the_html_tags_project.rb +9 -0
- data/lib/html_tags/requires/require_the_img_tag.rb +7 -0
- data/lib/html_tags/shared.rb +23 -0
- data/lib/html_tags/stag.rb +54 -0
- data/lib/html_tags/toplevel_methods/add.rb +22 -0
- data/lib/html_tags/toplevel_methods/full_output.rb +33 -0
- data/lib/html_tags/toplevel_methods/newline_or_empty.rb +21 -0
- data/lib/html_tags/toplevel_methods/strip_newlines.rb +27 -0
- data/lib/html_tags/version/version.rb +17 -0
- data/lib/html_tags/yaml/available_html_tags.yml +135 -0
- data/lib/html_tags/yaml/valid_tags_in_a_head_tag.yml +16 -0
- data/lib/html_tags.rb +5 -0
- data/test/testing_html_tags.rb +158 -0
- data/test/testing_the_a_tag.rb +162 -0
- data/test/testing_the_button_tag.rb +37 -0
- data/test/testing_the_details_tag.rb +38 -0
- metadata +171 -0
@@ -0,0 +1,646 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'html_tags/individual_tags/a.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module HtmlTags
|
8
|
+
|
9
|
+
require 'html_tags/closing_tag/closing_tag.rb'
|
10
|
+
require 'html_tags/toplevel_methods/add.rb'
|
11
|
+
|
12
|
+
# ========================================================================= #
|
13
|
+
# === HtmlTags.a (a tag)
|
14
|
+
#
|
15
|
+
# This tag will attempt to create a HTML link. It follows all other
|
16
|
+
# conventions as well. The first argument called `i` is the target
|
17
|
+
# URL to use.
|
18
|
+
#
|
19
|
+
# In plain HTML, this would be create a string such as the following one:
|
20
|
+
#
|
21
|
+
# <a href="url">Test</a>
|
22
|
+
#
|
23
|
+
# The first argument `i` is the hyperref-target.
|
24
|
+
#
|
25
|
+
# Usage examples:
|
26
|
+
#
|
27
|
+
# a('connect')
|
28
|
+
# a('connect', :make_newline)
|
29
|
+
# a('connect', 'marl1em','great_link','color: blue')
|
30
|
+
# a('LINUX_DESIGNING.cgi', :copy_description)
|
31
|
+
# a('https://de.wikipedia.org/wiki/Lampensockel#Edisonsockel', 'SELF', :make_newline)
|
32
|
+
# a('local_ruby_c', description: 'Ruby C Seite', css_style: 'margin-left: 2em')
|
33
|
+
# a(
|
34
|
+
# remote_url: remote_url,
|
35
|
+
# text: title?.to_s,
|
36
|
+
# css_style: 'font-weight: bold; color: darkblue'
|
37
|
+
# )
|
38
|
+
# HtmlTags.a('https://en.wikipedia.org/wiki/Gramicidin', { :remote_URL=>'gramicidin' })
|
39
|
+
# HtmlTags.a('https://en.wikipedia.org/wiki/Gramicidin', { remote_URL: 'gramicidin', open_new_tab: true })
|
40
|
+
#
|
41
|
+
# ========================================================================= #
|
42
|
+
def self.a(
|
43
|
+
hyperref_target = '',
|
44
|
+
link_description = :use_hyperref_as_the_target,
|
45
|
+
css_class = '',
|
46
|
+
the_id = '',
|
47
|
+
css_style = '',
|
48
|
+
javascript = ''
|
49
|
+
)
|
50
|
+
# ======================================================================= #
|
51
|
+
# The following Hash can be used to store data into, such as :tooltip.
|
52
|
+
# ======================================================================= #
|
53
|
+
internal_hash = {}
|
54
|
+
title = nil
|
55
|
+
# ======================================================================= #
|
56
|
+
# The next variable determines whether we will use target="_blank" or
|
57
|
+
# whether we will not.
|
58
|
+
# ======================================================================= #
|
59
|
+
target_is_blank = false
|
60
|
+
# ======================================================================= #
|
61
|
+
# Store the generated String in the local variable called result.
|
62
|
+
# ======================================================================= #
|
63
|
+
result = ''.dup
|
64
|
+
# ======================================================================= #
|
65
|
+
# If make_newline is set to true then we will append a <br> tag.
|
66
|
+
# ======================================================================= #
|
67
|
+
make_newline = false
|
68
|
+
close_me = close(__method__) # Default. Must come before case css_class.
|
69
|
+
# ======================================================================= #
|
70
|
+
# Since as of December 2015 we will check whether we have passed an
|
71
|
+
# Array.
|
72
|
+
#
|
73
|
+
# This may look like that way:
|
74
|
+
#
|
75
|
+
# ["https://de.wikipedia.org/wiki/Lampensockel#Edisonsockel",
|
76
|
+
# {:content=>"SELF", :css_class=>"mars2em"}]
|
77
|
+
#
|
78
|
+
# or
|
79
|
+
#
|
80
|
+
# ["http://geizhals.at/philips-voice-tracer-dvt3600-digitales-diktiergeraet-a992644.html?hloc=at", "SELF", 1]
|
81
|
+
#
|
82
|
+
# So we have to stay flexible here.
|
83
|
+
# ======================================================================= #
|
84
|
+
if hyperref_target.is_a? Array
|
85
|
+
if hyperref_target.size > 1
|
86
|
+
hash = hyperref_target[1] # This may not have to be a Hash, though.
|
87
|
+
if hash.is_a? Hash
|
88
|
+
link_description = hash
|
89
|
+
hyperref_target = hyperref_target[0]
|
90
|
+
elsif hash.is_a? Array
|
91
|
+
if hash[1]
|
92
|
+
link_description = hash[1]
|
93
|
+
end
|
94
|
+
if hash[2] and (hash[2] == 1)
|
95
|
+
make_newline = true
|
96
|
+
end
|
97
|
+
# ================================================================= #
|
98
|
+
# Finally, assign the first entry to hyperref_target.
|
99
|
+
# ================================================================= #
|
100
|
+
hyperref_target = hyperref_target.first
|
101
|
+
end
|
102
|
+
end
|
103
|
+
if hyperref_target.is_a? Array
|
104
|
+
hyperref_target = hyperref_target.first
|
105
|
+
end
|
106
|
+
end
|
107
|
+
case css_class
|
108
|
+
# ======================================================================= #
|
109
|
+
# === :copy_description
|
110
|
+
# ======================================================================= #
|
111
|
+
when :copy_description
|
112
|
+
css_class = ''
|
113
|
+
link_description = hyperref_target
|
114
|
+
# ======================================================================= #
|
115
|
+
# === :make_newline
|
116
|
+
# ======================================================================= #
|
117
|
+
when :make_newline
|
118
|
+
css_class = ''
|
119
|
+
close_me = close(__method__) {{ make_newline: true }}
|
120
|
+
# ======================================================================= #
|
121
|
+
# === :no_newline
|
122
|
+
# ======================================================================= #
|
123
|
+
when :no_newline
|
124
|
+
css_class = ''
|
125
|
+
close_me = close(__method__) {{ make_newline: false }}
|
126
|
+
else # Else do not make a newline, simply pass through..
|
127
|
+
end
|
128
|
+
# ======================================================================= #
|
129
|
+
# === Check for hyperref_target being a Hash
|
130
|
+
# ======================================================================= #
|
131
|
+
if hyperref_target.is_a? Hash
|
132
|
+
# ===================================================================== #
|
133
|
+
# === :open_new_tab
|
134
|
+
# ===================================================================== #
|
135
|
+
if hyperref_target.has_key? :open_new_tab
|
136
|
+
target_is_blank = hyperref_target.delete(:open_new_tab)
|
137
|
+
# ===================================================================== #
|
138
|
+
# === :new_tab
|
139
|
+
# ===================================================================== #
|
140
|
+
elsif hyperref_target.has_key? :new_tab
|
141
|
+
target_is_blank = hyperref_target.delete(:new_tab)
|
142
|
+
# ===================================================================== #
|
143
|
+
# === :open_in_new_tab
|
144
|
+
# ===================================================================== #
|
145
|
+
elsif hyperref_target.has_key? :open_in_new_tab
|
146
|
+
target_is_blank = hyperref_target.delete(:open_in_new_tab)
|
147
|
+
# ===================================================================== #
|
148
|
+
# === :open_in_a_new_tab
|
149
|
+
#
|
150
|
+
# This is an "alias" to the above entry point.
|
151
|
+
# ===================================================================== #
|
152
|
+
elsif hyperref_target.has_key? :open_in_a_new_tab
|
153
|
+
target_is_blank = hyperref_target.delete(:open_in_a_new_tab)
|
154
|
+
# ===================================================================== #
|
155
|
+
# === :new_tab
|
156
|
+
# ===================================================================== #
|
157
|
+
elsif hyperref_target.has_key? :new_tab
|
158
|
+
target_is_blank = hyperref_target.delete(:new_tab)
|
159
|
+
# ===================================================================== #
|
160
|
+
# === :open_new_tab
|
161
|
+
# ===================================================================== #
|
162
|
+
elsif hyperref_target.has_key? :open_new_tab
|
163
|
+
target_is_blank = hyperref_target.delete(:open_new_tab)
|
164
|
+
end
|
165
|
+
# ===================================================================== #
|
166
|
+
# === :link_description
|
167
|
+
# ===================================================================== #
|
168
|
+
if hyperref_target.has_key? :link_description
|
169
|
+
link_description = hyperref_target.delete(:link_description)
|
170
|
+
# ===================================================================== #
|
171
|
+
# === :description
|
172
|
+
# ===================================================================== #
|
173
|
+
elsif hyperref_target.has_key? :description
|
174
|
+
link_description = hyperref_target.delete(:description)
|
175
|
+
end
|
176
|
+
# ===================================================================== #
|
177
|
+
# === :id
|
178
|
+
# ===================================================================== #
|
179
|
+
if hyperref_target.has_key? :id
|
180
|
+
the_id = hyperref_target.delete(:id)
|
181
|
+
# ===================================================================== #
|
182
|
+
# === :the_id
|
183
|
+
# ===================================================================== #
|
184
|
+
elsif hyperref_target.has_key? :the_id
|
185
|
+
the_id = hyperref_target.delete(:the_id)
|
186
|
+
end
|
187
|
+
# ===================================================================== #
|
188
|
+
# === :make_newline
|
189
|
+
# ===================================================================== #
|
190
|
+
if hyperref_target.has_key? :make_newline
|
191
|
+
make_newline = hyperref_target.delete(:make_newline)
|
192
|
+
# ===================================================================== #
|
193
|
+
# === :linebreak
|
194
|
+
# ===================================================================== #
|
195
|
+
elsif hyperref_target.has_key? :linebreak
|
196
|
+
make_newline = hyperref_target.delete(:linebreak)
|
197
|
+
end
|
198
|
+
# ===================================================================== #
|
199
|
+
# === :css_class
|
200
|
+
#
|
201
|
+
# Handle :css_class early on, as it is a very unproblematic entry.
|
202
|
+
# ===================================================================== #
|
203
|
+
if hyperref_target.has_key? :css_class
|
204
|
+
css_class = hyperref_target.delete(:css_class)
|
205
|
+
end
|
206
|
+
# ===================================================================== #
|
207
|
+
# === :css_style
|
208
|
+
#
|
209
|
+
# This entry point allows us to handle css-styles for a given
|
210
|
+
# HTML tag.
|
211
|
+
# ===================================================================== #
|
212
|
+
if hyperref_target.has_key? :css_style
|
213
|
+
css_style = hyperref_target.delete(:css_style)
|
214
|
+
end
|
215
|
+
# ===================================================================== #
|
216
|
+
# === :content
|
217
|
+
#
|
218
|
+
# Rewrite :content to the more correctly named :link_description.
|
219
|
+
# ===================================================================== #
|
220
|
+
if hyperref_target.has_key? :content
|
221
|
+
link_description = hyperref_target.delete(:content)
|
222
|
+
# ===================================================================== #
|
223
|
+
# === :text
|
224
|
+
# ===================================================================== #
|
225
|
+
elsif hyperref_target.has_key? :text
|
226
|
+
link_description = hyperref_target.delete(:text)
|
227
|
+
end
|
228
|
+
# ===================================================================== #
|
229
|
+
# === :link_description
|
230
|
+
#
|
231
|
+
# This entry point ought to come last.
|
232
|
+
# ===================================================================== #
|
233
|
+
if hyperref_target.has_key?(:link_description) and
|
234
|
+
(hyperref_target[:link_description] == 'SELF')
|
235
|
+
link_description = hyperref_target.delete(:link_description)
|
236
|
+
end
|
237
|
+
# ===================================================================== #
|
238
|
+
# The next four checks should come last, since they will modify
|
239
|
+
# hyperref_target.
|
240
|
+
# ===================================================================== #
|
241
|
+
# ===================================================================== #
|
242
|
+
# === :remote_url
|
243
|
+
# ===================================================================== #
|
244
|
+
if hyperref_target.has_key? :remote_url
|
245
|
+
hyperref_target = hyperref_target.delete(:remote_url)
|
246
|
+
# ===================================================================== #
|
247
|
+
# === :remote_URL
|
248
|
+
# ===================================================================== #
|
249
|
+
elsif hyperref_target.has_key? :remote_URL
|
250
|
+
hyperref_target = hyperref_target.delete(:remote_URL)
|
251
|
+
# ===================================================================== #
|
252
|
+
# === :href
|
253
|
+
# ===================================================================== #
|
254
|
+
elsif hyperref_target.has_key? :href
|
255
|
+
hyperref_target = hyperref_target.delete(:href)
|
256
|
+
# ===================================================================== #
|
257
|
+
# === :href_target
|
258
|
+
# ===================================================================== #
|
259
|
+
elsif hyperref_target.has_key? :href_target
|
260
|
+
hyperref_target = hyperref_target.delete(:href_target)
|
261
|
+
end if hyperref_target.is_a?(Hash)
|
262
|
+
end
|
263
|
+
# ======================================================================= #
|
264
|
+
# === Intercept Hash for the link_description variable
|
265
|
+
#
|
266
|
+
# The hash can contain entries such as linebreak: true, but also
|
267
|
+
# entries such as content: :self.
|
268
|
+
# ======================================================================= #
|
269
|
+
if link_description.is_a? Hash
|
270
|
+
# ===================================================================== #
|
271
|
+
# === :remote_url
|
272
|
+
# ===================================================================== #
|
273
|
+
if link_description.has_key? :remote_url
|
274
|
+
hyperref_target = link_description.delete(:remote_url)
|
275
|
+
# ===================================================================== #
|
276
|
+
# === :remote_URL
|
277
|
+
# ===================================================================== #
|
278
|
+
elsif link_description.has_key? :remote_URL
|
279
|
+
hyperref_target = link_description.delete(:remote_URL)
|
280
|
+
end
|
281
|
+
# ===================================================================== #
|
282
|
+
# === :tooltip
|
283
|
+
# ===================================================================== #
|
284
|
+
if link_description.has_key? :tooltip
|
285
|
+
internal_hash[:tooltip] = link_description.delete(:tooltip)
|
286
|
+
end
|
287
|
+
# ===================================================================== #
|
288
|
+
# === :onclick
|
289
|
+
#
|
290
|
+
# This may look like so:
|
291
|
+
#
|
292
|
+
# onclick: 'change_the_colour_to()'
|
293
|
+
#
|
294
|
+
# ===================================================================== #
|
295
|
+
if link_description.has_key? :onclick
|
296
|
+
javascript = ' onclick="'+link_description.delete(:onclick)+'"'
|
297
|
+
end
|
298
|
+
# ===================================================================== #
|
299
|
+
# === :css_style
|
300
|
+
# ===================================================================== #
|
301
|
+
if link_description.has_key? :css_style
|
302
|
+
css_style = link_description.delete(:css_style)
|
303
|
+
end
|
304
|
+
# ===================================================================== #
|
305
|
+
# === :id
|
306
|
+
# ===================================================================== #
|
307
|
+
if link_description.has_key? :id
|
308
|
+
the_id = link_description.delete(:id)
|
309
|
+
# ===================================================================== #
|
310
|
+
# === :the_id
|
311
|
+
# ===================================================================== #
|
312
|
+
elsif link_description.has_key? :the_id
|
313
|
+
the_id = link_description.delete(:the_id)
|
314
|
+
end
|
315
|
+
# ===================================================================== #
|
316
|
+
# === :open_new_tab
|
317
|
+
# ===================================================================== #
|
318
|
+
if link_description.has_key? :open_new_tab
|
319
|
+
target_is_blank = link_description.delete(:open_new_tab)
|
320
|
+
# ===================================================================== #
|
321
|
+
# === :open_in_new_tab
|
322
|
+
# ===================================================================== #
|
323
|
+
elsif link_description.has_key? :open_in_new_tab
|
324
|
+
target_is_blank = link_description.delete(:open_in_new_tab)
|
325
|
+
# ===================================================================== #
|
326
|
+
# === :open_in_a_new_tab
|
327
|
+
#
|
328
|
+
# This is an "alias" to the above entry point.
|
329
|
+
# ===================================================================== #
|
330
|
+
elsif link_description.has_key? :open_in_a_new_tab
|
331
|
+
target_is_blank = link_description.delete(:open_in_a_new_tab)
|
332
|
+
# ===================================================================== #
|
333
|
+
# === :new_tab
|
334
|
+
# ===================================================================== #
|
335
|
+
elsif link_description.has_key? :new_tab
|
336
|
+
target_is_blank = link_description.delete(:new_tab)
|
337
|
+
# ===================================================================== #
|
338
|
+
# === :open_new_tab
|
339
|
+
# ===================================================================== #
|
340
|
+
elsif link_description.has_key? :open_new_tab
|
341
|
+
target_is_blank = link_description.delete(:open_new_tab)
|
342
|
+
end
|
343
|
+
# ===================================================================== #
|
344
|
+
# === css_class
|
345
|
+
# ===================================================================== #
|
346
|
+
if link_description.has_key? :css_class
|
347
|
+
css_class = link_description.delete(:css_class)
|
348
|
+
end
|
349
|
+
# ===================================================================== #
|
350
|
+
# === :css_style
|
351
|
+
# ===================================================================== #
|
352
|
+
if link_description.has_key? :css_style
|
353
|
+
css_style = link_description.delete(:css_style)
|
354
|
+
end
|
355
|
+
# ===================================================================== #
|
356
|
+
# === :title
|
357
|
+
#
|
358
|
+
# Support the :title attribute here.
|
359
|
+
#
|
360
|
+
# The :title attribute is to enable a short tooltip, on our
|
361
|
+
# <a> tag.
|
362
|
+
# ===================================================================== #
|
363
|
+
if link_description.has_key? :title
|
364
|
+
title = link_description.delete(:title)
|
365
|
+
end
|
366
|
+
# ===================================================================== #
|
367
|
+
# Rewrite :link_description into :description.
|
368
|
+
# ===================================================================== #
|
369
|
+
if link_description.has_key? :description
|
370
|
+
link_description = link_description.delete(:description)
|
371
|
+
# ===================================================================== #
|
372
|
+
# Rewrite :link_description into :text.
|
373
|
+
# ===================================================================== #
|
374
|
+
elsif link_description.has_key? :text
|
375
|
+
link_description = link_description.delete(:text)
|
376
|
+
# ===================================================================== #
|
377
|
+
# ==== :content
|
378
|
+
# ===================================================================== #
|
379
|
+
elsif link_description.has_key? :content
|
380
|
+
link_description = link_description.delete(:content)
|
381
|
+
# ===================================================================== #
|
382
|
+
# Rewrite :link_description into :link_description.
|
383
|
+
# ===================================================================== #
|
384
|
+
elsif link_description.has_key? :link_description
|
385
|
+
link_description = link_description.delete(:link_description)
|
386
|
+
# ===================================================================== #
|
387
|
+
# === :content
|
388
|
+
#
|
389
|
+
# Rewrite :content into :link_description.
|
390
|
+
#
|
391
|
+
# This entry point is for input such as:
|
392
|
+
#
|
393
|
+
# a('http://rubyreports.org/', content: '<b>Link</b>')
|
394
|
+
#
|
395
|
+
# ===================================================================== #
|
396
|
+
elsif link_description.has_key? :content
|
397
|
+
link_description = link_description.delete(:content).to_s
|
398
|
+
hyperref_target = hyperref_target.to_s.dup
|
399
|
+
if link_description and link_description.start_with?('→ ')
|
400
|
+
hyperref_target.sub!(/^→ /,'')
|
401
|
+
end
|
402
|
+
# =================================================================== #
|
403
|
+
# Next, we must both check for 'SELF' 'self', second variant
|
404
|
+
# could also be the Symbol :self.
|
405
|
+
# =================================================================== #
|
406
|
+
if link_description.include?('SELF') or (link_description.to_s == 'self')
|
407
|
+
if link_description.frozen?
|
408
|
+
link_description = link_description.dup
|
409
|
+
end
|
410
|
+
# ================================================================= #
|
411
|
+
# Must replace it with the proper target next.
|
412
|
+
# ================================================================= #
|
413
|
+
link_description = link_description.to_s.sub( # Ensure we have a String.
|
414
|
+
/^SELF/i, hyperref_target
|
415
|
+
)
|
416
|
+
end
|
417
|
+
else
|
418
|
+
# =================================================================== #
|
419
|
+
# We don't have a link_description entry, so we will simply use
|
420
|
+
# the value from hyperref_target..
|
421
|
+
# =================================================================== #
|
422
|
+
if link_description.is_a?(Hash) and link_description.empty?
|
423
|
+
link_description = hyperref_target.to_s.dup
|
424
|
+
end
|
425
|
+
end
|
426
|
+
end
|
427
|
+
if link_description.empty?
|
428
|
+
link_description = hyperref_target # This simulates "abr_self".
|
429
|
+
end
|
430
|
+
# ======================================================================= #
|
431
|
+
# Work on link_description next, assuming it is a String at this point.
|
432
|
+
# ======================================================================= #
|
433
|
+
case link_description.to_s
|
434
|
+
when /^→ / # If it starts with a right-arrow.
|
435
|
+
if link_description.to_s == :self
|
436
|
+
link_description = hyperref_target.dup.sub(/^→ /,'')
|
437
|
+
end
|
438
|
+
when /^SELF$/i
|
439
|
+
link_description = link_description.dup if link_description.frozen?
|
440
|
+
link_description = link_description.to_s.sub!(
|
441
|
+
/^SELF/i, hyperref_target.dup # .sub(/^→ /,'')
|
442
|
+
)
|
443
|
+
end
|
444
|
+
case hyperref_target
|
445
|
+
# Remove leading right-arrows.
|
446
|
+
when /^→ /
|
447
|
+
hyperref_target = hyperref_target.dup if hyperref_target.frozen?
|
448
|
+
hyperref_target.sub!(/^→ /,'')
|
449
|
+
end
|
450
|
+
# ======================================================================= #
|
451
|
+
# === :make_newline is treated in a special manner, as the id.
|
452
|
+
# Same for the number 1, which stands for newline too, due
|
453
|
+
# to historic reasons.
|
454
|
+
# ======================================================================= #
|
455
|
+
case the_id
|
456
|
+
when :make_newline, 1
|
457
|
+
make_newline = true
|
458
|
+
the_id = '' # Reset it here in this case.
|
459
|
+
end
|
460
|
+
if css_class and css_class.is_a?(String) and (css_class == 'SELF')
|
461
|
+
css_class = ''.dup
|
462
|
+
end
|
463
|
+
if css_class.is_a? Hash
|
464
|
+
# ===================================================================== #
|
465
|
+
# === Intercept key :css_style next, on the css_class variable
|
466
|
+
#
|
467
|
+
# This entry point is for input such as:
|
468
|
+
#
|
469
|
+
# a(@target, css_style: 'color:red; margin-left:2em')
|
470
|
+
#
|
471
|
+
# ===================================================================== #
|
472
|
+
if css_class.has_key? :css_style
|
473
|
+
css_style = css_class.delete :css_style
|
474
|
+
end if css_class.is_a? Hash # Must check again due to the earlier resetting.
|
475
|
+
# ===================================================================== #
|
476
|
+
# === Intercept key :css_class next
|
477
|
+
# ===================================================================== #
|
478
|
+
if css_class.has_key? :css_class
|
479
|
+
# =================================================================== #
|
480
|
+
# Must assign to css_class variable in this case:
|
481
|
+
# =================================================================== #
|
482
|
+
css_class = css_class.delete :css_class
|
483
|
+
end if css_class.is_a? Hash # See above explanation.
|
484
|
+
# ===================================================================== #
|
485
|
+
# === Intercept key :url next
|
486
|
+
# ===================================================================== #
|
487
|
+
if css_class.has_key? :url
|
488
|
+
i = css_class.delete :url
|
489
|
+
end if css_class.is_a? Hash # See above explanation.
|
490
|
+
# ===================================================================== #
|
491
|
+
# === Intercept key :linebreak next
|
492
|
+
# ===================================================================== #
|
493
|
+
if css_class.has_key? :linebreak
|
494
|
+
i = css_class.delete :linebreak
|
495
|
+
close_me = close(__method__) {{ make_newline: i }}
|
496
|
+
end if css_class.is_a? Hash # See above explanation.
|
497
|
+
if css_class.is_a?(Hash) and css_class.empty?
|
498
|
+
css_class = ''
|
499
|
+
end
|
500
|
+
end
|
501
|
+
# ======================================================================= #
|
502
|
+
# === Handle blocks next
|
503
|
+
#
|
504
|
+
# Append a pre-defined content to it, unless we also use a block.
|
505
|
+
# ======================================================================= #
|
506
|
+
if block_given?
|
507
|
+
yielded = yield
|
508
|
+
case yielded # Intercept some Symbols.
|
509
|
+
when :strip
|
510
|
+
hyperref_target.strip!
|
511
|
+
close_me.strip! if close_me
|
512
|
+
when :only_basename
|
513
|
+
if hyperref_target.has_key? :link_description
|
514
|
+
link_description = File.basename(hyperref_target[:link_description])
|
515
|
+
end
|
516
|
+
when :smaller
|
517
|
+
_ = link_description
|
518
|
+
link_description = '<span style="font-size:smaller">'+_+'</span>'
|
519
|
+
else
|
520
|
+
# =================================================================== #
|
521
|
+
# Assume that it could be a HTML colour, such as :slateblue:
|
522
|
+
# =================================================================== #
|
523
|
+
if yielded.is_a? Symbol
|
524
|
+
begin
|
525
|
+
require 'colours/html/html_colours.rb'
|
526
|
+
if Colours.is_this_html_colour_included?(yielded)
|
527
|
+
if css_style.nil?
|
528
|
+
css_style = ''.dup
|
529
|
+
end
|
530
|
+
css_style = css_style.dup if css_style.frozen?
|
531
|
+
css_style << " color: #{yielded};"
|
532
|
+
end
|
533
|
+
rescue LoadError
|
534
|
+
end
|
535
|
+
end
|
536
|
+
end
|
537
|
+
hyperref_target.merge!(yielded) unless yielded.is_a? Symbol
|
538
|
+
end
|
539
|
+
# ======================================================================= #
|
540
|
+
# === Copy the content of hyperref_target onto link_description
|
541
|
+
#
|
542
|
+
# This should come fairly late, though.
|
543
|
+
# ======================================================================= #
|
544
|
+
case link_description
|
545
|
+
when :use_hyperref_as_the_target
|
546
|
+
link_description = hyperref_target.dup
|
547
|
+
end
|
548
|
+
# ======================================================================= #
|
549
|
+
# Finally we will build-up the result-String next.
|
550
|
+
# ======================================================================= #
|
551
|
+
result = '<a'.dup
|
552
|
+
if hyperref_target.is_a?(Hash) and hyperref_target.empty? and
|
553
|
+
!link_description.empty?
|
554
|
+
hyperref_target = link_description.dup
|
555
|
+
end
|
556
|
+
hyperref_target = hyperref_target.to_s
|
557
|
+
result << ' href="'+hyperref_target+'"'
|
558
|
+
if css_class and !css_class.to_s.empty?
|
559
|
+
result << ' class="'+css_class.to_s+'"'
|
560
|
+
end
|
561
|
+
if the_id and !the_id.empty?
|
562
|
+
result << ' id="'+the_id.to_s+'"'
|
563
|
+
end
|
564
|
+
if css_style and !css_style.empty?
|
565
|
+
result << ' style="'+css_style.to_s+'"'
|
566
|
+
end
|
567
|
+
if javascript and !javascript.empty?
|
568
|
+
# The next lines exist to use "onclick" javascript directly.
|
569
|
+
unless javascript.lstrip.start_with? 'onclick'
|
570
|
+
result << ' javascript="'
|
571
|
+
end
|
572
|
+
result << javascript
|
573
|
+
unless javascript.lstrip.start_with? 'onclick'
|
574
|
+
result << '"'
|
575
|
+
end
|
576
|
+
end
|
577
|
+
# ======================================================================= #
|
578
|
+
# === Handle tooltips next, via data-tip
|
579
|
+
# ======================================================================= #
|
580
|
+
if internal_hash.is_a?(Hash) and internal_hash.has_key?(:tooltip)
|
581
|
+
result << " data-tip=\"#{internal_hash[:tooltip]}\""
|
582
|
+
end
|
583
|
+
if target_is_blank
|
584
|
+
result << ' target="_blank"'
|
585
|
+
end
|
586
|
+
if title
|
587
|
+
result << ' title="'+title.to_s+'"'
|
588
|
+
end
|
589
|
+
result << '>' # Close that tag here.
|
590
|
+
# result << N
|
591
|
+
result << link_description.to_s # Could be a Symbol after all.
|
592
|
+
result << close_me
|
593
|
+
if make_newline
|
594
|
+
result << '<br>'
|
595
|
+
end
|
596
|
+
# ======================================================================= #
|
597
|
+
# Must add it onto the main String too.
|
598
|
+
# ======================================================================= #
|
599
|
+
return HtmlTags.add(result)
|
600
|
+
end; self.instance_eval { alias slink a } # === HtmlTags.slink
|
601
|
+
self.instance_eval { alias link a } # === HtmlTags.link
|
602
|
+
|
603
|
+
# ========================================================================= #
|
604
|
+
# === a
|
605
|
+
#
|
606
|
+
# Wrapper towards HtmlTags.a().
|
607
|
+
# ========================================================================= #
|
608
|
+
def a(
|
609
|
+
hyperref_target = '',
|
610
|
+
link_description = :use_hyperref_as_the_target,
|
611
|
+
css_class = '',
|
612
|
+
the_id = '',
|
613
|
+
css_style = '',
|
614
|
+
javascript = '',
|
615
|
+
&block
|
616
|
+
)
|
617
|
+
HtmlTags.a(
|
618
|
+
hyperref_target,
|
619
|
+
link_description,
|
620
|
+
css_class,
|
621
|
+
the_id,
|
622
|
+
css_style,
|
623
|
+
javascript,
|
624
|
+
&block
|
625
|
+
)
|
626
|
+
end; alias slink a # === slink
|
627
|
+
alias link a # === link
|
628
|
+
|
629
|
+
end
|
630
|
+
|
631
|
+
if __FILE__ == $PROGRAM_NAME
|
632
|
+
alias e puts
|
633
|
+
e HtmlTags.a(
|
634
|
+
'https://geizhals.at/diverse-cr2032-knopfzelle-a134716.html',
|
635
|
+
css_style: 'margin-left: 4em',
|
636
|
+
# The title attribute on an <a> tag adds a tooltip with title
|
637
|
+
# text to the anchor tag.
|
638
|
+
title: 'This is a tooltip.'
|
639
|
+
)
|
640
|
+
e
|
641
|
+
e HtmlTags.a(
|
642
|
+
'https://foobar.com',
|
643
|
+
css_style: 'font-size: 1.1em;',
|
644
|
+
description: 'https://foobar com'
|
645
|
+
)
|
646
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# =========================================================================== #
|
2
|
+
# Documentation for the <abbr> tag can be found here:
|
3
|
+
# http://www.w3schools.com/tags/tag_abbr.asp
|
4
|
+
# =========================================================================== #
|
5
|
+
module HtmlTags
|
6
|
+
|
7
|
+
# ========================================================================= #
|
8
|
+
# === HtmlTags.abbr
|
9
|
+
#
|
10
|
+
# To test this method, try:
|
11
|
+
#
|
12
|
+
# HtmlTags.abbr 'WHO','World Health Organization'
|
13
|
+
# ========================================================================= #
|
14
|
+
def self.abbr(abbreviation_to_use = '', long_name = '')
|
15
|
+
if long_name.empty? and !abbreviation_to_use.empty?
|
16
|
+
# ===================================================================== #
|
17
|
+
# In this case, we simply copy to the long name.
|
18
|
+
# ===================================================================== #
|
19
|
+
long_name = abbreviation_to_use.to_s.dup
|
20
|
+
end
|
21
|
+
if block_given?
|
22
|
+
return HtmlTags.add(
|
23
|
+
opening_tag(__method__, title: long_name.to_s)+
|
24
|
+
abbreviation_to_use+
|
25
|
+
yield+
|
26
|
+
close(__method__)
|
27
|
+
)
|
28
|
+
else
|
29
|
+
return HtmlTags.add(
|
30
|
+
opening_tag(__method__, title: long_name.to_s)+
|
31
|
+
abbreviation_to_use+
|
32
|
+
close(__method__)
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# ========================================================================= #
|
38
|
+
# === abbr
|
39
|
+
# ========================================================================= #
|
40
|
+
def abbr(abbreviation_to_use = '', long_name = '')
|
41
|
+
HtmlTags.abbr(abbreviation_to_use, long_name)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|