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,59 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
module HtmlTags
|
6
|
+
|
7
|
+
require 'html_tags/opening_tag/opening_tag.rb'
|
8
|
+
require 'html_tags/toplevel_methods/add.rb'
|
9
|
+
|
10
|
+
# ========================================================================= #
|
11
|
+
# === HtmlTags.title (title tag)
|
12
|
+
# ========================================================================= #
|
13
|
+
def self.title(
|
14
|
+
i = '',
|
15
|
+
&block
|
16
|
+
)
|
17
|
+
# ======================================================================= #
|
18
|
+
# === Handle blocks given to this method next
|
19
|
+
# ======================================================================= #
|
20
|
+
if block_given?
|
21
|
+
yielded = yield
|
22
|
+
case yielded
|
23
|
+
# ===================================================================== #
|
24
|
+
# === :newline
|
25
|
+
# ===================================================================== #
|
26
|
+
when :newline
|
27
|
+
i = "#{i}\n"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
i = i.to_s
|
31
|
+
return HtmlTags.add(
|
32
|
+
opening_tag(__method__)+
|
33
|
+
i+
|
34
|
+
close(__method__)
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
# ========================================================================= #
|
39
|
+
# === title
|
40
|
+
# ========================================================================= #
|
41
|
+
def title(
|
42
|
+
i = '',
|
43
|
+
&block
|
44
|
+
)
|
45
|
+
return HtmlTags.title(
|
46
|
+
i,
|
47
|
+
css_class,
|
48
|
+
the_id,
|
49
|
+
css_style,
|
50
|
+
&block
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
if __FILE__ == $PROGRAM_NAME
|
57
|
+
alias e puts
|
58
|
+
e HtmlTags.title('Just a random title.')
|
59
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
module HtmlTags
|
6
|
+
|
7
|
+
require 'html_tags/opening_tag/opening_tag.rb'
|
8
|
+
require 'html_tags/toplevel_methods/add.rb'
|
9
|
+
|
10
|
+
# ========================================================================= #
|
11
|
+
# === HtmlTags.tr
|
12
|
+
# ========================================================================= #
|
13
|
+
def self.tr(
|
14
|
+
i = '',
|
15
|
+
css_class = '',
|
16
|
+
the_id = '',
|
17
|
+
css_style = ''
|
18
|
+
)
|
19
|
+
return HtmlTags.add(
|
20
|
+
opening_tag(__method__, css_class, the_id, css_style)+
|
21
|
+
i.to_s+"\n"+
|
22
|
+
close(__method__)
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
# ========================================================================= #
|
27
|
+
# === tr
|
28
|
+
# ========================================================================= #
|
29
|
+
def tr(
|
30
|
+
i = '',
|
31
|
+
css_class = '',
|
32
|
+
the_id = '',
|
33
|
+
css_style = '',
|
34
|
+
&block
|
35
|
+
)
|
36
|
+
return HtmlTags.tr(
|
37
|
+
i,
|
38
|
+
css_class,
|
39
|
+
the_id,
|
40
|
+
css_style,
|
41
|
+
&block
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
if __FILE__ == $PROGRAM_NAME
|
48
|
+
alias e puts
|
49
|
+
e HtmlTags.tr("<th>Month</th>\n<th>Savings</th>")
|
50
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'html_tags/individual_tags/track.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module HtmlTags
|
8
|
+
|
9
|
+
require 'html_tags/opening_tag/opening_tag.rb'
|
10
|
+
require 'html_tags/toplevel_methods/add.rb'
|
11
|
+
|
12
|
+
# ========================================================================= #
|
13
|
+
# === HtmlTags.track
|
14
|
+
#
|
15
|
+
# This method should yield a String such as:
|
16
|
+
#
|
17
|
+
# <track src="fgsubtitles_en.vtt" kind="subtitles" srclang="en" label="English">
|
18
|
+
#
|
19
|
+
# ========================================================================= #
|
20
|
+
def self.track(
|
21
|
+
src = 'fgsubtitles_en.vtt',
|
22
|
+
kind = 'subtitles',
|
23
|
+
srclang = 'en',
|
24
|
+
label = 'English'
|
25
|
+
)
|
26
|
+
_ = opening_tag(__method__).dup
|
27
|
+
if src
|
28
|
+
_[-2,0] = ' src="'+src+'"'
|
29
|
+
end
|
30
|
+
if kind
|
31
|
+
_[-2,0] = ' kind="'+kind+'"'
|
32
|
+
end
|
33
|
+
if srclang
|
34
|
+
_[-2,0] = ' srclang="'+srclang+'"'
|
35
|
+
end
|
36
|
+
if label
|
37
|
+
_[-2,0] = ' label="'+label+'"'
|
38
|
+
end
|
39
|
+
return HtmlTags.add(_)
|
40
|
+
end
|
41
|
+
|
42
|
+
# ========================================================================= #
|
43
|
+
# === track
|
44
|
+
# ========================================================================= #
|
45
|
+
def track(
|
46
|
+
src = 'fgsubtitles_en.vtt',
|
47
|
+
kind = 'subtitles',
|
48
|
+
srclang = 'en',
|
49
|
+
label = 'English'
|
50
|
+
)
|
51
|
+
return HtmlTags.track(src, kind, srclang, label)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
if __FILE__ == $PROGRAM_NAME
|
57
|
+
alias e puts
|
58
|
+
e HtmlTags.track('fgsubtitles_en.vtt','subtitles','en','English')
|
59
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
module HtmlTags
|
6
|
+
|
7
|
+
require 'html_tags/opening_tag/opening_tag.rb'
|
8
|
+
require 'html_tags/toplevel_methods/add.rb'
|
9
|
+
|
10
|
+
# ========================================================================= #
|
11
|
+
# === HtmlTags.u
|
12
|
+
# ========================================================================= #
|
13
|
+
def self.u(
|
14
|
+
i = '', css_class = '', the_id = '', css_style = ''
|
15
|
+
)
|
16
|
+
return HtmlTags.add(
|
17
|
+
opening_tag(__method__, css_class, the_id, css_style)+
|
18
|
+
i.to_s+
|
19
|
+
close(__method__)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
# ========================================================================= #
|
24
|
+
# === u
|
25
|
+
# ========================================================================= #
|
26
|
+
def u(
|
27
|
+
i = '',
|
28
|
+
css_class = '',
|
29
|
+
the_id = '',
|
30
|
+
css_style = '',
|
31
|
+
&block
|
32
|
+
)
|
33
|
+
return HtmlTags.u(
|
34
|
+
i,
|
35
|
+
css_class,
|
36
|
+
the_id,
|
37
|
+
css_style,
|
38
|
+
&block
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
if __FILE__ == $PROGRAM_NAME
|
45
|
+
alias e puts
|
46
|
+
e HtmlTags.u('foobar')
|
47
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
module HtmlTags
|
6
|
+
|
7
|
+
# ========================================================================= #
|
8
|
+
# === ul
|
9
|
+
# ========================================================================= #
|
10
|
+
def ul(
|
11
|
+
i = '', css_class = '', the_id = '', css_style = ''
|
12
|
+
)
|
13
|
+
_ = ''.dup
|
14
|
+
_ << yield if block_given?
|
15
|
+
return HtmlTags.add(
|
16
|
+
opening_tag(__method__, css_class, the_id, css_style)+
|
17
|
+
_+
|
18
|
+
i.to_s+
|
19
|
+
close(__method__)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'html_tags/individual_tags/var.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module HtmlTags
|
8
|
+
|
9
|
+
require 'html_tags/opening_tag/opening_tag.rb'
|
10
|
+
require 'html_tags/toplevel_methods/add.rb'
|
11
|
+
require 'html_tags/toplevel_methods/newline_or_empty.rb'
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === HtmlTags.var
|
15
|
+
# ========================================================================= #
|
16
|
+
def self.var(
|
17
|
+
i = 'foo.png',
|
18
|
+
css_class = '',
|
19
|
+
the_id = '',
|
20
|
+
css_style = ''
|
21
|
+
)
|
22
|
+
return HtmlTags.add(
|
23
|
+
opening_tag(__method__, css_class, the_id, css_style)+
|
24
|
+
i.to_s+
|
25
|
+
close(__method__)
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
# ========================================================================= #
|
30
|
+
# === var
|
31
|
+
# ========================================================================= #
|
32
|
+
def var(
|
33
|
+
i = 'foo.png',
|
34
|
+
css_class = '',
|
35
|
+
the_id = '',
|
36
|
+
css_style = ''
|
37
|
+
)
|
38
|
+
::HtmlTags.var(i, css_class, the_id, css_style)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
if __FILE__ == $PROGRAM_NAME
|
44
|
+
alias e puts
|
45
|
+
e HtmlTags.var('x') # should yield: <var>x</var>
|
46
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
module HtmlTags
|
6
|
+
|
7
|
+
require 'html_tags/opening_tag/opening_tag.rb'
|
8
|
+
require 'html_tags/toplevel_methods/add.rb'
|
9
|
+
|
10
|
+
# ========================================================================= #
|
11
|
+
# === video (video tag)
|
12
|
+
#
|
13
|
+
# The goal of this method is to create a String such as
|
14
|
+
# '<video src="movie.webm"></video>'.
|
15
|
+
#
|
16
|
+
# To start a video automatically the "autoplay" attribute can be
|
17
|
+
# used.
|
18
|
+
# ========================================================================= #
|
19
|
+
def video(
|
20
|
+
i = '', # ← This is the content.
|
21
|
+
css_class = '',
|
22
|
+
the_id = '',
|
23
|
+
css_style = '',
|
24
|
+
optional_javascript = '',
|
25
|
+
&block
|
26
|
+
)
|
27
|
+
if i.is_a? Hash
|
28
|
+
# ===================================================================== #
|
29
|
+
# === :css_class
|
30
|
+
# ===================================================================== #
|
31
|
+
if i.has_key? :css_class
|
32
|
+
css_class = i.delete(:css_class)
|
33
|
+
end
|
34
|
+
i = ''
|
35
|
+
end
|
36
|
+
i = i.to_s.dup # And avoid frozen-errors.
|
37
|
+
video_tag = opening_tag(__method__, css_class, the_id, css_style, optional_javascript).dup
|
38
|
+
video_tag[-2,0] = ' controls'
|
39
|
+
# ======================================================================= #
|
40
|
+
# Blocks will be assumed to be used for the first argument, `i`, by
|
41
|
+
# default - except for some Symbols.
|
42
|
+
# ======================================================================= #
|
43
|
+
if block_given?
|
44
|
+
yielded = yield
|
45
|
+
case yielded # Past this point we handle special Symbols, such as :autoplay.
|
46
|
+
# ===================================================================== #
|
47
|
+
# === :autoplay
|
48
|
+
# ===================================================================== #
|
49
|
+
when :autoplay
|
50
|
+
video_tag[-2,0] = ' autoplay'
|
51
|
+
else
|
52
|
+
yielded = yielded.to_s
|
53
|
+
i << yielded
|
54
|
+
end
|
55
|
+
end
|
56
|
+
return HtmlTags.add(
|
57
|
+
video_tag+
|
58
|
+
"<source src=\"#{i}\">"+
|
59
|
+
close(__method__)
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
if __FILE__ == $PROGRAM_NAME
|
66
|
+
alias e puts
|
67
|
+
include HtmlTags
|
68
|
+
e video 'foobar.mp4'
|
69
|
+
e video('foobar.mp4') { :autoplay }
|
70
|
+
end
|
@@ -0,0 +1,288 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'html_tags/opening_tag/opening_tag.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
module HtmlTags
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'web_object/requires/require_web_images.rb'
|
11
|
+
rescue LoadError; end
|
12
|
+
|
13
|
+
require 'html_tags/array_registered_html_tags.rb'
|
14
|
+
require 'html_tags/closing_tag/closing_tag.rb'
|
15
|
+
|
16
|
+
# ========================================================================= #
|
17
|
+
# === HtmlTags.opening_tag (opening_tag tag)
|
18
|
+
#
|
19
|
+
# If we pass a block to this method, we treat it as a special hash.
|
20
|
+
#
|
21
|
+
# This can be used to make use of src.
|
22
|
+
#
|
23
|
+
# Note that arguments to this method can become quite complicated.
|
24
|
+
#
|
25
|
+
# For instance, consider this here:
|
26
|
+
#
|
27
|
+
# e p 'Good Bye', :css_class => 'border: 1px solid red',
|
28
|
+
# :id => 'goodbye'
|
29
|
+
#
|
30
|
+
# ========================================================================= #
|
31
|
+
def self.opening_tag(
|
32
|
+
i, # The name of the tag comes here.
|
33
|
+
optional_css_class = '', # 2nd parameter
|
34
|
+
optional_the_id = '', # 3rd parameter
|
35
|
+
optional_css_style = '', # 4th parameter
|
36
|
+
optional_javascript = '', # 5th parameter
|
37
|
+
&block
|
38
|
+
)
|
39
|
+
append_newline = true
|
40
|
+
i = i.to_s.dup # Must use .dup here, to prevent cascading string-taint.
|
41
|
+
original_tag_name = i.to_s.dup
|
42
|
+
case i
|
43
|
+
when 's','' # Sanitize in these two cases.
|
44
|
+
i = 'span'
|
45
|
+
end
|
46
|
+
content = ''.dup # This here will be appended always.
|
47
|
+
end_string = ''.dup
|
48
|
+
i = i.dup if i.frozen?
|
49
|
+
# ======================================================================= #
|
50
|
+
# === optional_css_class
|
51
|
+
#
|
52
|
+
# Next we must intercept when the second argument is a Hash.
|
53
|
+
# ======================================================================= #
|
54
|
+
if optional_css_class.is_a? Hash
|
55
|
+
# ===================================================================== #
|
56
|
+
# === :id
|
57
|
+
# ===================================================================== #
|
58
|
+
if optional_css_class.has_key? :id
|
59
|
+
optional_the_id = optional_css_class.delete(:id)
|
60
|
+
end
|
61
|
+
# ===================================================================== #
|
62
|
+
# === :css_style
|
63
|
+
# ===================================================================== #
|
64
|
+
if optional_css_class.has_key? :css_style
|
65
|
+
optional_css_style = optional_css_class.delete(:css_style)
|
66
|
+
# ===================================================================== #
|
67
|
+
# === :style
|
68
|
+
# ===================================================================== #
|
69
|
+
elsif optional_css_class.has_key? :style
|
70
|
+
optional_css_style = optional_css_class.delete(:style)
|
71
|
+
end
|
72
|
+
# ===================================================================== #
|
73
|
+
# Intercept javascript keys. Several aliases could be used, so
|
74
|
+
# we have to check for them.
|
75
|
+
# ===================================================================== #
|
76
|
+
if optional_css_class.has_key? :javascript
|
77
|
+
optional_javascript = optional_css_class.delete(:javascript)
|
78
|
+
elsif optional_css_class.has_key? :javascript_code
|
79
|
+
optional_javascript = optional_css_class.delete(:javascript_code)
|
80
|
+
elsif optional_css_class.has_key? :desc
|
81
|
+
content << optional_css_class.delete(:desc).to_s
|
82
|
+
end
|
83
|
+
if optional_css_class.has_key? :css_class # This here must come last.
|
84
|
+
optional_css_class = optional_css_class.delete(:css_class).to_s.dup
|
85
|
+
elsif optional_css_class.has_key? :title
|
86
|
+
i << ' title="'+optional_css_class.delete(:title).to_s+'"'
|
87
|
+
optional_css_class = ''
|
88
|
+
end
|
89
|
+
if optional_css_class.empty?
|
90
|
+
optional_css_class = ''
|
91
|
+
end if optional_css_class.is_a? Hash
|
92
|
+
end
|
93
|
+
# ======================================================================= #
|
94
|
+
# === optional_javascript
|
95
|
+
#
|
96
|
+
# Intercept optional_javascript if it is a Hash.
|
97
|
+
# ======================================================================= #
|
98
|
+
if optional_javascript.is_a? Hash
|
99
|
+
if optional_javascript.has_key? :on_click # Redirect
|
100
|
+
optional_javascript[:onclick] = optional_javascript.delete(:on_click)
|
101
|
+
end
|
102
|
+
if optional_javascript.has_key? :onclick
|
103
|
+
js_temp_string = optional_javascript[:onclick].to_s
|
104
|
+
if js_temp_string.include? 'background-color'
|
105
|
+
optional_javascript = 'onclick="set_background_color('+
|
106
|
+
js_temp_string.gsub(/background-color\:/,'').delete(';')+
|
107
|
+
', this)"'
|
108
|
+
elsif js_temp_string == 'go back in history' # Sanitize it.
|
109
|
+
optional_javascript = 'history.back(-1)'
|
110
|
+
end
|
111
|
+
elsif optional_javascript.has_key? :javascript_hover
|
112
|
+
# The following code works on:
|
113
|
+
# :javascript_hover => 'color: lightblue'
|
114
|
+
js_temp_string = optional_javascript[:javascript_hover].to_s
|
115
|
+
if js_temp_string.include? 'color'
|
116
|
+
optional_javascript = ' onmouseover="colourize(this, '+
|
117
|
+
js_temp_string.gsub(/color\:/,'').to_s.delete(' ')+')"'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
# ======================================================================= #
|
121
|
+
# Next handle special String-input given to the javascript component.
|
122
|
+
# ======================================================================= #
|
123
|
+
elsif optional_javascript.is_a? String
|
124
|
+
if optional_javascript.include?('on_click:') # Input may be: 'on_click: show_image(:axe))'
|
125
|
+
if optional_javascript.frozen?
|
126
|
+
optional_javascript = optional_javascript.dup
|
127
|
+
end
|
128
|
+
optional_javascript.gsub!(/on_click: /, '')
|
129
|
+
if optional_javascript.include? 'show_image'
|
130
|
+
optional_javascript =~ /\((.+)\)/
|
131
|
+
optional_javascript = $1.to_s.dup.delete(')')
|
132
|
+
optional_javascript = WebObject.obtain(optional_javascript)
|
133
|
+
optional_javascript = 'onclick="reveal('+"'"+optional_javascript+"'"+')"'
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
# ======================================================================= #
|
138
|
+
# Next we require the four input-objects to be Strings.
|
139
|
+
# ======================================================================= #
|
140
|
+
optional_css_class = optional_css_class.to_s.dup
|
141
|
+
optional_the_id = optional_the_id.to_s
|
142
|
+
case optional_css_style
|
143
|
+
when :bold
|
144
|
+
# ===================================================================== #
|
145
|
+
# === Intercept key :bold next
|
146
|
+
#
|
147
|
+
# This is a special key in the sense that we will "translate" it
|
148
|
+
# into the corresponding CSS value. So :bold really just means
|
149
|
+
# to be replaced with the string 'font-weight: bold'.
|
150
|
+
# ===================================================================== #
|
151
|
+
optional_css_style = 'font-weight: bold;'
|
152
|
+
end
|
153
|
+
optional_css_style = optional_css_style.to_s
|
154
|
+
optional_javascript = optional_javascript.to_s
|
155
|
+
|
156
|
+
if optional_css_style.include? "\n" # Get rid of newlines and multiple ' '.
|
157
|
+
optional_css_style = beautify_string(optional_css_style)
|
158
|
+
end
|
159
|
+
# ======================================================================= #
|
160
|
+
# === Handle blocks next
|
161
|
+
#
|
162
|
+
# Intercept blocks passed to this method. Typically blocks will,
|
163
|
+
# in some form, be appended to the opening-tag at hand.
|
164
|
+
# ======================================================================= #
|
165
|
+
if block_given? # If we passed a block
|
166
|
+
yielded = yield # Tap into the block.
|
167
|
+
if yielded.is_a? Hash
|
168
|
+
# =================================================================== #
|
169
|
+
# === :src
|
170
|
+
# =================================================================== #
|
171
|
+
if yielded.has_key? :src
|
172
|
+
i << ' src="'+yielded.delete(:src).to_s+'"'
|
173
|
+
end
|
174
|
+
# =================================================================== #
|
175
|
+
# === :href
|
176
|
+
# =================================================================== #
|
177
|
+
if yielded.has_key? :href
|
178
|
+
i << ' href="'+yielded.delete(:href).to_s+'"'
|
179
|
+
end
|
180
|
+
# =================================================================== #
|
181
|
+
# === :type
|
182
|
+
# =================================================================== #
|
183
|
+
if yielded.has_key? :type
|
184
|
+
i << ' type="'+yielded.delete(:type).to_s+'"'
|
185
|
+
end
|
186
|
+
# =================================================================== #
|
187
|
+
# === :value
|
188
|
+
#
|
189
|
+
# This entry point should come after :type, as I think it looks
|
190
|
+
# a bit prettier that way.
|
191
|
+
# =================================================================== #
|
192
|
+
if yielded.has_key? :value
|
193
|
+
i << ' value="'+yielded.delete(:value).to_s+'"'
|
194
|
+
end
|
195
|
+
# =================================================================== #
|
196
|
+
# === :link_description or :description
|
197
|
+
# =================================================================== #
|
198
|
+
if yielded.has_key?(:link_description) or
|
199
|
+
yielded.has_key?(:description) or
|
200
|
+
yielded.has_key?(:content)
|
201
|
+
# if content.empty? # We only append to content if is empty. Disabled this in Jun 2015.
|
202
|
+
if yielded.has_key? :link_description
|
203
|
+
content << yielded.delete(:link_description).to_s
|
204
|
+
elsif yielded.has_key? :description
|
205
|
+
content << yielded.delete(:description).to_s
|
206
|
+
elsif yielded.has_key? :content
|
207
|
+
content << yielded.delete(:content).to_s
|
208
|
+
end
|
209
|
+
#end
|
210
|
+
# =================================================================== #
|
211
|
+
# === :desc
|
212
|
+
# =================================================================== #
|
213
|
+
elsif yielded.has_key? :desc
|
214
|
+
content << yielded.delete(:desc).to_s
|
215
|
+
end
|
216
|
+
# =================================================================== #
|
217
|
+
# === :make_newline
|
218
|
+
# =================================================================== #
|
219
|
+
if yielded.has_key? :make_newline
|
220
|
+
end_string << br
|
221
|
+
end
|
222
|
+
# ===================================================================== #
|
223
|
+
# === Handle Symbols directly past this point
|
224
|
+
# ===================================================================== #
|
225
|
+
elsif yielded.is_a? Symbol
|
226
|
+
case yielded
|
227
|
+
when :no_newline
|
228
|
+
append_newline = false
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
# ======================================================================= #
|
233
|
+
# Next, add the class, id, style, and javascript entries to our tag.
|
234
|
+
# ======================================================================= #
|
235
|
+
i << ' class="'+optional_css_class+'"' unless optional_css_class.empty?
|
236
|
+
i << ' id="'+optional_the_id+'"' unless optional_the_id.empty?
|
237
|
+
i << ' style="'+optional_css_style+'"' unless optional_css_style.empty?
|
238
|
+
|
239
|
+
unless optional_javascript.empty?
|
240
|
+
# ===================================================================== #
|
241
|
+
# Always prepend ' ' if it is not empty.
|
242
|
+
# ===================================================================== #
|
243
|
+
if optional_javascript.frozen?
|
244
|
+
optional_javascript = optional_javascript.dup
|
245
|
+
end
|
246
|
+
optional_javascript.prepend ' '
|
247
|
+
# ===================================================================== #
|
248
|
+
# Add some exceptions: currently the exceptions include
|
249
|
+
# "onclick" and "onmouse".
|
250
|
+
# ===================================================================== #
|
251
|
+
unless optional_javascript.strip.start_with?('onclick') or
|
252
|
+
optional_javascript.strip.start_with?('onmouse')
|
253
|
+
optional_javascript = 'javascript="'+optional_javascript+'"'
|
254
|
+
end
|
255
|
+
i << optional_javascript
|
256
|
+
end
|
257
|
+
# ======================================================================= #
|
258
|
+
# === Append '/' to a few tags.
|
259
|
+
# ======================================================================= #
|
260
|
+
if ARRAY_TAGS_WITHOUT_CLOSING_TAG.include? original_tag_name
|
261
|
+
i << '/' # Add exception for <br/> tags and some others.
|
262
|
+
end
|
263
|
+
i = "<#{i}>#{end_string}"
|
264
|
+
i = i.dup if i.frozen?
|
265
|
+
i << "\n" if append_newline
|
266
|
+
i << content
|
267
|
+
return i
|
268
|
+
end; self.instance_eval { alias otag opening_tag } # === HtmlTags.otag
|
269
|
+
|
270
|
+
# ========================================================================= #
|
271
|
+
# === opening_tag
|
272
|
+
# ========================================================================= #
|
273
|
+
def opening_tag(
|
274
|
+
i,
|
275
|
+
optional_css_class = '',
|
276
|
+
optional_the_id = '',
|
277
|
+
optional_css_style = '',
|
278
|
+
optional_javascript = ''
|
279
|
+
)
|
280
|
+
HtmlTags.opening_tag(i,
|
281
|
+
optional_css_class,
|
282
|
+
optional_the_id,
|
283
|
+
optional_css_style,
|
284
|
+
optional_javascript
|
285
|
+
)
|
286
|
+
end; alias otag opening_tag # === otag
|
287
|
+
|
288
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'html_tags/project/project_base_directory.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'yaml'
|
8
|
+
|
9
|
+
module HtmlTags
|
10
|
+
|
11
|
+
# ========================================================================= #
|
12
|
+
# === HtmlTags::PROJECT_BASE_DIRECTORY
|
13
|
+
# ========================================================================= #
|
14
|
+
PROJECT_BASE_DIRECTORY =
|
15
|
+
File.absolute_path("#{__dir__}/..")+'/'
|
16
|
+
PROJECT_BASE_DIR = PROJECT_BASE_DIRECTORY # === PROJECT_BASE_DIR
|
17
|
+
|
18
|
+
# ========================================================================= #
|
19
|
+
# === PROJECT_YAML_DIR
|
20
|
+
# ========================================================================= #
|
21
|
+
PROJECT_YAML_DIR = "#{PROJECT_BASE_DIRECTORY}yaml/"
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'html_tags/requires/require_the_html_tags_project.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'html_tags/base/base_module.rb'
|
8
|
+
require 'html_tags/html_tags.rb'
|
9
|
+
require 'html_tags/constants/misc.rb'
|