html_tags 0.1.120

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of html_tags might be problematic. Click here for more details.

Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +110 -0
  3. data/USAGE.md +17 -0
  4. data/doc/README.gen +69 -0
  5. data/html_tags.gemspec +53 -0
  6. data/lib/html_tags/array_registered_html_tags.rb +125 -0
  7. data/lib/html_tags/autoinclude.rb +2 -0
  8. data/lib/html_tags/autoinclude_base_module.rb +7 -0
  9. data/lib/html_tags/base/README.md +3 -0
  10. data/lib/html_tags/base/base.rb +11 -0
  11. data/lib/html_tags/base/base_module.rb +224 -0
  12. data/lib/html_tags/base/prototype.rb +19 -0
  13. data/lib/html_tags/checks.rb +58 -0
  14. data/lib/html_tags/closing_tag/closing_tag.rb +76 -0
  15. data/lib/html_tags/constants/array_strip_newlines.rb +14 -0
  16. data/lib/html_tags/constants/misc.rb +21 -0
  17. data/lib/html_tags/constants.rb +26 -0
  18. data/lib/html_tags/html_closing_tags.rb +36 -0
  19. data/lib/html_tags/html_comment.rb +29 -0
  20. data/lib/html_tags/html_tags.rb +131 -0
  21. data/lib/html_tags/html_tags_constants.rb +14 -0
  22. data/lib/html_tags/individual_tags/a.rb +524 -0
  23. data/lib/html_tags/individual_tags/abbr.rb +44 -0
  24. data/lib/html_tags/individual_tags/audio.rb +32 -0
  25. data/lib/html_tags/individual_tags/b.rb +22 -0
  26. data/lib/html_tags/individual_tags/blockquote.rb +19 -0
  27. data/lib/html_tags/individual_tags/body.rb +19 -0
  28. data/lib/html_tags/individual_tags/br.rb +28 -0
  29. data/lib/html_tags/individual_tags/button.rb +30 -0
  30. data/lib/html_tags/individual_tags/canvas.rb +19 -0
  31. data/lib/html_tags/individual_tags/details.rb +69 -0
  32. data/lib/html_tags/individual_tags/div.rb +51 -0
  33. data/lib/html_tags/individual_tags/figure.rb +39 -0
  34. data/lib/html_tags/individual_tags/footer.rb +26 -0
  35. data/lib/html_tags/individual_tags/form.rb +93 -0
  36. data/lib/html_tags/individual_tags/h1.rb +36 -0
  37. data/lib/html_tags/individual_tags/h2.rb +42 -0
  38. data/lib/html_tags/individual_tags/h3.rb +73 -0
  39. data/lib/html_tags/individual_tags/h4.rb +36 -0
  40. data/lib/html_tags/individual_tags/h5.rb +36 -0
  41. data/lib/html_tags/individual_tags/h6.rb +40 -0
  42. data/lib/html_tags/individual_tags/head.rb +36 -0
  43. data/lib/html_tags/individual_tags/header.rb +29 -0
  44. data/lib/html_tags/individual_tags/html.rb +61 -0
  45. data/lib/html_tags/individual_tags/i.rb +14 -0
  46. data/lib/html_tags/individual_tags/img.rb +135 -0
  47. data/lib/html_tags/individual_tags/input.rb +32 -0
  48. data/lib/html_tags/individual_tags/label.rb +43 -0
  49. data/lib/html_tags/individual_tags/legend.rb +14 -0
  50. data/lib/html_tags/individual_tags/li.rb +44 -0
  51. data/lib/html_tags/individual_tags/main.rb +29 -0
  52. data/lib/html_tags/individual_tags/nav.rb +14 -0
  53. data/lib/html_tags/individual_tags/object.rb +18 -0
  54. data/lib/html_tags/individual_tags/ol.rb +50 -0
  55. data/lib/html_tags/individual_tags/p.rb +50 -0
  56. data/lib/html_tags/individual_tags/pre.rb +16 -0
  57. data/lib/html_tags/individual_tags/span.rb +60 -0
  58. data/lib/html_tags/individual_tags/strong.rb +17 -0
  59. data/lib/html_tags/individual_tags/style.rb +29 -0
  60. data/lib/html_tags/individual_tags/table.rb +33 -0
  61. data/lib/html_tags/individual_tags/tbody.rb +19 -0
  62. data/lib/html_tags/individual_tags/td.rb +24 -0
  63. data/lib/html_tags/individual_tags/textarea.rb +46 -0
  64. data/lib/html_tags/individual_tags/th.rb +14 -0
  65. data/lib/html_tags/individual_tags/thead.rb +14 -0
  66. data/lib/html_tags/individual_tags/title.rb +18 -0
  67. data/lib/html_tags/individual_tags/tr.rb +20 -0
  68. data/lib/html_tags/individual_tags/ul.rb +23 -0
  69. data/lib/html_tags/individual_tags/video.rb +54 -0
  70. data/lib/html_tags/module.rb +5 -0
  71. data/lib/html_tags/opening_tag/opening_tag.rb +288 -0
  72. data/lib/html_tags/project/project_base_directory.rb +23 -0
  73. data/lib/html_tags/requires/require_the_html_tags_project.rb +9 -0
  74. data/lib/html_tags/requires/require_the_img_tag.rb +7 -0
  75. data/lib/html_tags/shared.rb +23 -0
  76. data/lib/html_tags/stag.rb +54 -0
  77. data/lib/html_tags/toplevel_methods/add.rb +22 -0
  78. data/lib/html_tags/toplevel_methods/full_output.rb +33 -0
  79. data/lib/html_tags/toplevel_methods/newline_or_empty.rb +21 -0
  80. data/lib/html_tags/toplevel_methods/strip_newlines.rb +27 -0
  81. data/lib/html_tags/version/version.rb +17 -0
  82. data/lib/html_tags/yaml/valid_tags_in_a_head_tag.yml +16 -0
  83. data/lib/html_tags.rb +5 -0
  84. data/test/testing_html_tags.rb +158 -0
  85. data/test/testing_the_a_tag.rb +113 -0
  86. metadata +141 -0
@@ -0,0 +1,58 @@
1
+ require 'html_tags/array_registered_html_tags.rb'
2
+
3
+ module HtmlTags # require 'html_tags/checks.rb'
4
+
5
+ # ========================================================================= #
6
+ # === is_valid_html?
7
+ #
8
+ # This method will check whether the given input is a valid html tag
9
+ # or whether it is not. It will delegate towards the class method
10
+ # HtmlTags.is_valid_html?
11
+ # ========================================================================= #
12
+ def is_valid_html?(i = '</br>')
13
+ return HtmlTags.is_valid_html? i
14
+ end; alias is_valid? is_valid_html?
15
+ alias is_valid_html_tag? is_valid_html?
16
+
17
+ # ========================================================================= #
18
+ # === HtmlTags.is_valid_html?
19
+ #
20
+ # This is the real method that does the check.
21
+ # ========================================================================= #
22
+ def self.is_valid_html?(i)
23
+ i = i.delete('<')
24
+ i = i.delete('>')
25
+ i = i.delete('/')
26
+ return ARRAY_REGISTERED_HTML_TAGS.include? i
27
+ end
28
+
29
+ # ========================================================================= #
30
+ # === HtmlTags.string_contains_only_valid_html_tags?
31
+ #
32
+ # This method will test if a whole string will have only valid html
33
+ # tags.
34
+ # ========================================================================= #
35
+ def self.string_contains_only_valid_html_tags?(i)
36
+ all_matches = i.scan(/\<.+\>/)
37
+ return all_matches.all? {|entry| is_valid_html? entry }
38
+ end
39
+
40
+ # ========================================================================= #
41
+ # === string_contains_only_valid_html_tags?(i)
42
+ # ========================================================================= #
43
+ def string_contains_only_valid_html_tags?(i)
44
+ return HtmlTags.string_contains_only_valid_html_tags?(i)
45
+ end
46
+
47
+ end
48
+
49
+ # =========================================================================== #
50
+ # Here we test the above.
51
+ # =========================================================================== #
52
+ if __FILE__ == $PROGRAM_NAME
53
+ puts HtmlTags.is_valid_html? '<br>'
54
+ puts HtmlTags.is_valid_html? '<div>'
55
+ puts HtmlTags.is_valid_html? '<dav>'
56
+ puts HtmlTags.string_contains_only_valid_html_tags? 'hello ruby </br>'
57
+ puts HtmlTags.string_contains_only_valid_html_tags? 'hello ruby<haha>'
58
+ end # rb checks.rb
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'html_tags/closing_tag/closing_tag.rb'
6
+ # =========================================================================== #
7
+ module HtmlTags
8
+
9
+ require 'html_tags/toplevel_methods/strip_newlines.rb'
10
+ # ========================================================================= #
11
+ # === HtmlTags.close
12
+ #
13
+ # This method creates the closing tag. It will return that tag as
14
+ # a string.
15
+ #
16
+ # This method also accepts a block, which can be a hash that could
17
+ # have keys such as { :make_newline => true }.
18
+ #
19
+ # Usage example:
20
+ #
21
+ # HtmlTags.close('span')
22
+ #
23
+ # ========================================================================= #
24
+ def self.close(i, &block)
25
+ append_newline = true
26
+ # ======================================================================= #
27
+ # If we strip newlines, then we won't append them logically.
28
+ # ======================================================================= #
29
+ append_newline = false if HtmlTags.strip_newlines?
30
+ i = i.to_s.dup # It should remain a String.
31
+ # ======================================================================= #
32
+ # Next, sanitize some wrongful/shortcut tags here.
33
+ # ======================================================================= #
34
+ case i
35
+ when 'link'
36
+ i = 'a'
37
+ when 'field',
38
+ 'mini_header'
39
+ i = 'fieldset'
40
+ end
41
+ end_string = ''.dup # This will be be appended.
42
+ # ======================================================================= #
43
+ # Intercept blocks passed to the method here.
44
+ # ======================================================================= #
45
+ if block_given?
46
+ yielded = yield # Tap into the block.
47
+ if yielded.is_a? Hash
48
+ if yielded.has_key? :make_newline
49
+ end_string << br if yielded[:make_newline] == true
50
+ end
51
+ elsif yielded == :make_newline
52
+ end_string << br
53
+ elsif yielded == :no_newline
54
+ append_newline = false # Do not append a newline in this case here.
55
+ end
56
+ end
57
+ result = ''.dup
58
+ # result << "\n" if append_newline # This one was disabled in April 2022.
59
+ result << '</'+i.to_s.dup+'>'
60
+ result << "\n" if append_newline
61
+ result << end_string # This is the result we will return. A String.
62
+ return result
63
+ end
64
+
65
+ # ========================================================================= #
66
+ # === close (close tag)
67
+ #
68
+ # This is a wrapper towards HtmlTags.close(), which will close a
69
+ # given HTML tag.
70
+ # ========================================================================= #
71
+ def close(i, &block)
72
+ return HtmlTags.close(i, &block) # Delegate to the above class-method.
73
+ end; alias ctag close # === ctag
74
+ # alias c close <- Not sure about that alias yet.
75
+
76
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'html_tags/constants/array_strip_newlines.rb'
6
+ # =========================================================================== #
7
+ module HtmlTags
8
+
9
+ # ========================================================================= #
10
+ # === HtmlTags::ARRAY_STRIP_NEWLINES
11
+ # ========================================================================= #
12
+ ARRAY_STRIP_NEWLINES = [false]
13
+
14
+ end
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'html_tags/constants/misc.rb'
6
+ # =========================================================================== #
7
+ module HtmlTags
8
+
9
+ # ========================================================================= #
10
+ # === DOCTYPE_HTML
11
+ # ========================================================================= #
12
+ DOCTYPE_HTML = '<!DOCTYPE html>'
13
+
14
+ # ========================================================================= #
15
+ # === HtmlTags.doctype_html
16
+ # ========================================================================= #
17
+ def self.doctype_html
18
+ DOCTYPE_HTML
19
+ end
20
+
21
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'yaml'
6
+ require 'html_tags/project/project_base_directory.rb'
7
+
8
+ module HtmlTags
9
+
10
+ # ========================================================================= #
11
+ # === FILE_VALID_TAGS_IN_A_HEAD_TAG
12
+ #
13
+ # This specifies the path to a yaml-file that keeps an Array.
14
+ # ========================================================================= #
15
+ FILE_VALID_TAGS_IN_A_HEAD_TAG = "#{PROJECT_YAML_DIR}valid_tags_in_a_head_tag.yml"
16
+
17
+ # ========================================================================= #
18
+ # === VALID_TAGS_IN_A_HEAD_TAG
19
+ # ========================================================================= #
20
+ if File.exist? FILE_VALID_TAGS_IN_A_HEAD_TAG
21
+ VALID_TAGS_IN_A_HEAD_TAG = YAML.load_file(FILE_VALID_TAGS_IN_A_HEAD_TAG)
22
+ else
23
+ VALID_TAGS_IN_A_HEAD_TAG = []
24
+ end
25
+
26
+ end
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # =========================================================================== #
4
+ # All html closing tags are autogenerated here.
5
+ # =========================================================================== #
6
+ require 'html_tags/array_registered_html_tags.rb'
7
+ require 'html_tags/html_tags_constants.rb'
8
+ require 'html_tags/closing_tag/closing_tag.rb'
9
+
10
+ module HtmlTags
11
+
12
+ # ========================================================================= #
13
+ # Next, generate all closing html tags. A respective closing tag is
14
+ # the name of the tag, and a 'c' preprended.
15
+ #
16
+ # Example:
17
+ # The closing tag for h1() method call will be ch1(). Of course the
18
+ # () can be omitted in Ruby, so we can use:
19
+ # ch1
20
+ # chtml
21
+ #
22
+ # Some html tags do not have a closing tag though.
23
+ # ========================================================================= #
24
+ ( ARRAY_REGISTERED_HTML_TAGS - ARRAY_TAGS_WITHOUT_CLOSING_TAG ).each {|entry|
25
+ define_method('c'+entry.to_s) {
26
+ close(entry.to_s.dup) # This method is defined in the file close.rb
27
+ }
28
+ }
29
+
30
+ end
31
+
32
+ if __FILE__ == $PROGRAM_NAME
33
+ include HtmlTags
34
+ p HtmlTags::methods
35
+ p ch6 # Close a <h6> tag that way.
36
+ end # html_closing_tags
@@ -0,0 +1,29 @@
1
+ module HtmlTags # require 'html_tags/html_comment.rb'
2
+
3
+ # ========================================================================= #
4
+ # === HtmlTags.html_comment
5
+ # ========================================================================= #
6
+ def self.html_comment(your_comment = '')
7
+ return '<!-- '+your_comment.to_s+' --> '+NL
8
+ end; self.instance_eval { alias comment html_comment } # HtmlTags.comment
9
+
10
+ # ========================================================================= #
11
+ # === html_comment
12
+ #
13
+ # This method will make a html comment - as in, make a valid comment within
14
+ # the source of a html file. This is done by putting <!-- --> around
15
+ # the content in question.
16
+ #
17
+ # Specific Usage Examples:
18
+ # HtmlTags.html_comment 'yup'
19
+ # ee HtmlTags.html_comment 'yup'
20
+ # ee html_comment 'this is for displaying some data'
21
+ #
22
+ # Resources for Comments in HTML:
23
+ # http://www.tutorialspoint.com/html/html_comments.htm
24
+ # ========================================================================= #
25
+ def html_comment(your_comment = '')
26
+ HtmlTags.html_comment(your_comment)
27
+ end; alias comment html_comment
28
+
29
+ end
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === HtmlTags
6
+ #
7
+ # This project can generate HTML tags. We will also create the corresponding
8
+ # closing tags to said actions - see the file html_closing_tags.rb for
9
+ # close-related actions.
10
+ #
11
+ # If you want to autoinclude this project, do this:
12
+ # require 'html_tags/autoinclude'
13
+ # =========================================================================== #
14
+ require 'pathname'
15
+ require 'html_tags/array_registered_html_tags.rb' # bl $HTML_TAGS/array_registered_html_tags.rb
16
+ require 'html_tags/constants/array_strip_newlines.rb'
17
+ require 'html_tags/constants.rb'
18
+ require 'html_tags/html_closing_tags.rb'
19
+ require 'html_tags/html_comment.rb'
20
+ require 'html_tags/html_tags_constants.rb'
21
+ require 'html_tags/opening_tag/opening_tag.rb'
22
+ require 'html_tags/shared.rb'
23
+ require 'html_tags/stag.rb'
24
+ require 'html_tags/version/version.rb'
25
+ require 'html_tags/toplevel_methods/full_output.rb'
26
+ require 'html_tags/toplevel_methods/strip_newlines.rb'
27
+
28
+ # =========================================================================== #
29
+ # Next, require the individual tags from the individual_tags/ directory.
30
+ # =========================================================================== #
31
+ Dir[RbConfig::CONFIG['sitelibdir']+'/html_tags/individual_tags/*.rb'].each {|file|
32
+ require file
33
+ }
34
+
35
+ module HtmlTags # require 'html_tags'
36
+
37
+ include HtmlTags::Shared
38
+
39
+ # ========================================================================= #
40
+ # === NL
41
+ # ========================================================================= #
42
+ NL = "\n"
43
+
44
+ # ========================================================================= #
45
+ # === is_this_an_allowed_tag_in_head_element?
46
+ #
47
+ # This method will return true or false depending on whether the given
48
+ # tag may be part of a <head> tag.
49
+ # ========================================================================= #
50
+ def is_this_an_allowed_tag_in_head_element?(i)
51
+ i = i.to_s # Ought to be a String.
52
+ # ======================================================================= #
53
+ # Get rid of <> tags.
54
+ # ======================================================================= #
55
+ i.delete!('<')
56
+ i.delete!('>')
57
+ VALID_TAGS_IN_A_HEAD_TAG.include? i
58
+ end
59
+
60
+ # ========================================================================= #
61
+ # === fieldset
62
+ # ========================================================================= #
63
+ def fieldset(
64
+ i = '', css_class = '', the_id = '', css_style = ''
65
+ )
66
+ return HtmlTags.add(
67
+ opening_tag(__method__, css_class, the_id, css_style)+
68
+ i.to_s+
69
+ close(__method__)
70
+ )
71
+ end
72
+
73
+ # ========================================================================= #
74
+ # === q
75
+ #
76
+ # The quote tag, <q>.
77
+ # ========================================================================= #
78
+ def q(i = '', css_class = '', the_id = '', css_style = '')
79
+ return HtmlTags.add(
80
+ opening_tag(__method__, css_class, the_id, css_style)+
81
+ i.to_s+
82
+ close(__method__)
83
+ )
84
+ end; alias quote q # === quote
85
+
86
+ # ========================================================================= #
87
+ # === hr
88
+ # ========================================================================= #
89
+ def hr
90
+ return HtmlTags.add(
91
+ otag(__method__)
92
+ )
93
+ end
94
+
95
+ # ========================================================================= #
96
+ # === sbody
97
+ #
98
+ # Start of body tag.
99
+ # ========================================================================= #
100
+ def sbody
101
+ unless string?.include?('</head>')
102
+ HtmlTags.add('</head><body>')
103
+ end
104
+ end
105
+
106
+ extend self
107
+
108
+ end
109
+
110
+ # =========================================================================== #
111
+ # Now some testing of the HTML components:
112
+ # =========================================================================== #
113
+ if __FILE__ == $PROGRAM_NAME
114
+ include HtmlTags
115
+ puts li 'Hi there.'
116
+ puts 'Now testing some components:'
117
+ ARRAY_REGISTERED_HTML_TAGS.each {|entry|
118
+ puts send(entry.to_sym)
119
+ }
120
+ puts head {'Ok'}
121
+ puts button 'ack','s1em'
122
+ ARRAY_REGISTERED_HTML_TAGS.each {|entry|
123
+ begin
124
+ puts send(entry.to_sym, 'Test','bblack1')
125
+ rescue Exception => error
126
+ pp error
127
+ end
128
+ }
129
+ puts h4 'Test','bblack1'
130
+ puts h4 'Test','bblack1','foo','border:1px solid black'
131
+ end # htmltags
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # =========================================================================== #
4
+ module HtmlTags # require 'html_tags/html_tags_constants.rb'
5
+
6
+ # ========================================================================= #
7
+ # Some hardcoded HTML-constants will be defined here.
8
+ # ========================================================================= #
9
+ TABLE = '<table>'
10
+ TR = '<tr>'
11
+ TD = '<td>'
12
+ BR = '<br/>'
13
+
14
+ end