html_tags 0.1.120
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of html_tags might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/README.md +110 -0
- data/USAGE.md +17 -0
- data/doc/README.gen +69 -0
- data/html_tags.gemspec +53 -0
- data/lib/html_tags/array_registered_html_tags.rb +125 -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 +224 -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 +131 -0
- data/lib/html_tags/html_tags_constants.rb +14 -0
- data/lib/html_tags/individual_tags/a.rb +524 -0
- data/lib/html_tags/individual_tags/abbr.rb +44 -0
- data/lib/html_tags/individual_tags/audio.rb +32 -0
- data/lib/html_tags/individual_tags/b.rb +22 -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 +30 -0
- data/lib/html_tags/individual_tags/canvas.rb +19 -0
- data/lib/html_tags/individual_tags/details.rb +69 -0
- data/lib/html_tags/individual_tags/div.rb +51 -0
- data/lib/html_tags/individual_tags/figure.rb +39 -0
- data/lib/html_tags/individual_tags/footer.rb +26 -0
- data/lib/html_tags/individual_tags/form.rb +93 -0
- data/lib/html_tags/individual_tags/h1.rb +36 -0
- data/lib/html_tags/individual_tags/h2.rb +42 -0
- data/lib/html_tags/individual_tags/h3.rb +73 -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 +36 -0
- data/lib/html_tags/individual_tags/header.rb +29 -0
- data/lib/html_tags/individual_tags/html.rb +61 -0
- data/lib/html_tags/individual_tags/i.rb +14 -0
- data/lib/html_tags/individual_tags/img.rb +135 -0
- data/lib/html_tags/individual_tags/input.rb +32 -0
- data/lib/html_tags/individual_tags/label.rb +43 -0
- data/lib/html_tags/individual_tags/legend.rb +14 -0
- data/lib/html_tags/individual_tags/li.rb +44 -0
- data/lib/html_tags/individual_tags/main.rb +29 -0
- data/lib/html_tags/individual_tags/nav.rb +14 -0
- data/lib/html_tags/individual_tags/object.rb +18 -0
- data/lib/html_tags/individual_tags/ol.rb +50 -0
- data/lib/html_tags/individual_tags/p.rb +50 -0
- data/lib/html_tags/individual_tags/pre.rb +16 -0
- data/lib/html_tags/individual_tags/span.rb +60 -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/table.rb +33 -0
- data/lib/html_tags/individual_tags/tbody.rb +19 -0
- data/lib/html_tags/individual_tags/td.rb +24 -0
- data/lib/html_tags/individual_tags/textarea.rb +46 -0
- data/lib/html_tags/individual_tags/th.rb +14 -0
- data/lib/html_tags/individual_tags/thead.rb +14 -0
- data/lib/html_tags/individual_tags/title.rb +18 -0
- data/lib/html_tags/individual_tags/tr.rb +20 -0
- data/lib/html_tags/individual_tags/ul.rb +23 -0
- data/lib/html_tags/individual_tags/video.rb +54 -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/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 +113 -0
- metadata +141 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
module HtmlTags
|
6
|
+
|
7
|
+
# ========================================================================= #
|
8
|
+
# === table
|
9
|
+
# ========================================================================= #
|
10
|
+
def table(
|
11
|
+
i = '',
|
12
|
+
css_class = '',
|
13
|
+
the_id = '',
|
14
|
+
css_style = ''
|
15
|
+
)
|
16
|
+
if block_given?
|
17
|
+
yielded = yield
|
18
|
+
if yielded.is_a? Array
|
19
|
+
yielded.each {|entry|
|
20
|
+
i << entry
|
21
|
+
}
|
22
|
+
else
|
23
|
+
i << yielded
|
24
|
+
end
|
25
|
+
end
|
26
|
+
return HtmlTags.add(
|
27
|
+
opening_tag(__method__, css_class, the_id, css_style)+
|
28
|
+
i.to_s+
|
29
|
+
close(__method__)
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module HtmlTags
|
2
|
+
|
3
|
+
# ========================================================================= #
|
4
|
+
# === HtmlTags.tbody
|
5
|
+
# ========================================================================= #
|
6
|
+
def self.tbody(i = '', css_class = '', the_id = '', css_style = '')
|
7
|
+
return HtmlTags.add(
|
8
|
+
opening_tag(__method__, css_class, the_id, css_style)+i.to_s+close(__method__)
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
# ========================================================================= #
|
13
|
+
# === tbody
|
14
|
+
# ========================================================================= #
|
15
|
+
def tbody(i = '', css_class = '', the_id = '', css_style = '')
|
16
|
+
HtmlTags.tbody(i, css_class, the_id, css_style)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
module HtmlTags
|
6
|
+
|
7
|
+
# ========================================================================= #
|
8
|
+
# === td
|
9
|
+
# ========================================================================= #
|
10
|
+
def td(
|
11
|
+
i = '', css_class = '', the_id = '', css_style = '', &block
|
12
|
+
)
|
13
|
+
content = i.to_s
|
14
|
+
if block_given?
|
15
|
+
content = content.to_s+yield.to_s
|
16
|
+
end
|
17
|
+
return HtmlTags.add(
|
18
|
+
opening_tag(__method__, css_class, the_id, css_style)+
|
19
|
+
content+
|
20
|
+
close(__method__)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
module HtmlTags
|
6
|
+
|
7
|
+
# ========================================================================= #
|
8
|
+
# === textarea
|
9
|
+
#
|
10
|
+
# Do note that the <textarea> tag also has an entry called spellcheck.
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
#
|
14
|
+
# <textarea spellcheck="true"></textarea>
|
15
|
+
#
|
16
|
+
# This appears to be true by default on palemoon, firefox and chrome,
|
17
|
+
# but I am not sure that it is too terribly useful, so as far as the
|
18
|
+
# HtmlTags project is concerned, it will be set to false by default.
|
19
|
+
#
|
20
|
+
# Invocation example:
|
21
|
+
#
|
22
|
+
# HtmlTags.textarea('Hello world!') # => <textarea spellcheck="true">Hello world!</textarea>
|
23
|
+
#
|
24
|
+
# ========================================================================= #
|
25
|
+
def textarea(
|
26
|
+
i = '',
|
27
|
+
css_class = '',
|
28
|
+
the_id = '',
|
29
|
+
css_style = '',
|
30
|
+
spellcheck = false
|
31
|
+
)
|
32
|
+
start = opening_tag(__method__, css_class, the_id, css_style)
|
33
|
+
index = start.index('textarea>')+'textarea>'.size - 1
|
34
|
+
if spellcheck
|
35
|
+
start[index,0] = ' spellcheck="true"'
|
36
|
+
else
|
37
|
+
start[index,0] = ' spellcheck="false"'
|
38
|
+
end
|
39
|
+
return HtmlTags.add(
|
40
|
+
start+
|
41
|
+
i.to_s+
|
42
|
+
close(__method__)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module HtmlTags
|
2
|
+
|
3
|
+
# ========================================================================= #
|
4
|
+
# === th
|
5
|
+
# ========================================================================= #
|
6
|
+
def th(i = '', css_class = '', the_id = '', css_style = '')
|
7
|
+
return HtmlTags.add(
|
8
|
+
opening_tag(__method__, css_class, the_id, css_style)+
|
9
|
+
i.to_s+
|
10
|
+
close(__method__)
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module HtmlTags
|
2
|
+
|
3
|
+
# ========================================================================= #
|
4
|
+
# === thead
|
5
|
+
# ========================================================================= #
|
6
|
+
def thead(i = '', css_class = '', the_id = '', css_style = '')
|
7
|
+
return HtmlTags.add(
|
8
|
+
opening_tag(__method__, css_class, the_id, css_style)+
|
9
|
+
i.to_s+
|
10
|
+
close(__method__)
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
module HtmlTags
|
6
|
+
|
7
|
+
# ========================================================================= #
|
8
|
+
# === HtmlTags.title
|
9
|
+
# ========================================================================= #
|
10
|
+
def self.title(i = '')
|
11
|
+
return HtmlTags.add(
|
12
|
+
opening_tag(__method__)+
|
13
|
+
i.to_s+
|
14
|
+
close(__method__)
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
module HtmlTags
|
6
|
+
|
7
|
+
# ========================================================================= #
|
8
|
+
# === tr
|
9
|
+
# ========================================================================= #
|
10
|
+
def tr(
|
11
|
+
i = '', css_class = '', the_id = '', css_style = ''
|
12
|
+
)
|
13
|
+
return HtmlTags.add(
|
14
|
+
opening_tag(__method__, css_class, the_id, css_style)+
|
15
|
+
i.to_s+
|
16
|
+
close(__method__)
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
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,54 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
module HtmlTags
|
6
|
+
|
7
|
+
# ========================================================================= #
|
8
|
+
# === video (video tag)
|
9
|
+
#
|
10
|
+
# The goal of this method is to create a String such as
|
11
|
+
# '<video src="movie.webm"></video>'.
|
12
|
+
# ========================================================================= #
|
13
|
+
def video(
|
14
|
+
i = '', # ← This is the content.
|
15
|
+
css_class = '',
|
16
|
+
the_id = '',
|
17
|
+
css_style = '',
|
18
|
+
optional_javascript = '',
|
19
|
+
&block
|
20
|
+
)
|
21
|
+
if i.is_a? Hash
|
22
|
+
# ===================================================================== #
|
23
|
+
# === :css_class
|
24
|
+
# ===================================================================== #
|
25
|
+
if i.has_key? :css_class
|
26
|
+
css_class = i.delete(:css_class)
|
27
|
+
end
|
28
|
+
i = ''
|
29
|
+
end
|
30
|
+
i = i.to_s.dup # And avoid frozen-errors.
|
31
|
+
# ======================================================================= #
|
32
|
+
# Blocks will be assumed to be used for the first argument, `i`.
|
33
|
+
# ======================================================================= #
|
34
|
+
if block_given?
|
35
|
+
i << yield.to_s
|
36
|
+
end
|
37
|
+
video_tag = opening_tag(__method__, css_class, the_id, css_style, optional_javascript).dup
|
38
|
+
video_tag[-2,0] = ' controls'
|
39
|
+
return HtmlTags.add(
|
40
|
+
video_tag+
|
41
|
+
"<source src=\"#{i}\">"+
|
42
|
+
close(__method__)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
if __FILE__ == $PROGRAM_NAME
|
49
|
+
alias e puts
|
50
|
+
require 'html_tags/opening_tag/opening_tag.rb'
|
51
|
+
require 'html_tags/toplevel_methods/add.rb'
|
52
|
+
include HtmlTags
|
53
|
+
e video 'foobar.mp4'
|
54
|
+
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'
|
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
4
|
+
# =========================================================================== #
|
5
|
+
# require 'html_tags/requires/require_the_image_tag.rb'
|
6
|
+
# =========================================================================== #
|
7
|
+
require 'html_tags/individual_tags/img.rb'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# Encoding: UTF-8
|
3
|
+
# =========================================================================== #
|
4
|
+
require 'html_tags/checks.rb'
|
5
|
+
require 'html_tags/toplevel_methods/newline_or_empty.rb'
|
6
|
+
|
7
|
+
module HtmlTags # HtmlTags::Shared
|
8
|
+
|
9
|
+
module Shared # require 'html_tags/shared.rb'
|
10
|
+
|
11
|
+
N = "\n"
|
12
|
+
|
13
|
+
# ========================================================================= #
|
14
|
+
# === beautify_string
|
15
|
+
#
|
16
|
+
# First run .squeeze(' '), then delete newlines, to make a string more
|
17
|
+
# beautiful.
|
18
|
+
# ========================================================================= #
|
19
|
+
def beautify_string(i)
|
20
|
+
i.squeeze(' ').delete("\n")
|
21
|
+
end
|
22
|
+
|
23
|
+
end; end
|