module HtmlTags
#¶ ↑
require ‘html_tags/base/base.rb’
#¶ ↑
#¶ ↑
require ‘html_tags/closing_tag/closing_tag.rb’
#¶ ↑
#¶ ↑
require ‘html_tags/constants/array_strip_newlines.rb’
#¶ ↑
#¶ ↑
require ‘html_tags/constants/misc.rb’
#¶ ↑
#¶ ↑
#¶ ↑
require ‘html_tags/individual_tags/a.rb’
#¶ ↑
#¶ ↑
Documentation for the <abbr> tag can be found here:
http://www.w3schools.com/tags/tag_abbr.asp
#¶ ↑
#¶ ↑
#¶ ↑
require ‘html_tags/individual_tags/details.rb’
#¶ ↑
#¶ ↑
#¶ ↑
Documentation for the <figure> tag can be viewed here:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figure
The HTML <figure> Element represents self-contained content, frequently with a caption (<figcaption>), and is typically referenced as a single unit. While it is related to the main flow, its position is independent of the main flow.
Usually this is an image, an illustration, a diagram, a code snippet, or a schema that is referenced in the main text, but that can be moved to another page or to an appendix without affecting the main flow.
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
require ‘html_tags/individual_tags/h1.rb’
#¶ ↑
#¶ ↑
require ‘html_tags/individual_tags/h2.rb’
#¶ ↑
#¶ ↑
require ‘html_tags/individual_tags/h3.rb’
#¶ ↑
#¶ ↑
require ‘html_tags/individual_tags/h4.rb’
#¶ ↑
#¶ ↑
require ‘html_tags/individual_tags/h5.rb’
#¶ ↑
#¶ ↑
require ‘html_tags/individual_tags/h6.rb’
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
require ‘html_tags/individual_tags/img.rb’
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
require ‘html_tags/individual_tags/p.rb’
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
#¶ ↑
require ‘html_tags/opening_tag/opening_tag.rb’
#¶ ↑
#¶ ↑
#¶ ↑
require ‘html_tags/toplevel_methods/add.rb’
#¶ ↑
#¶ ↑
require ‘html_tags/toplevel_methods/full_output.rb’
#¶ ↑
#¶ ↑
require ‘html_tags/toplevel_methods/newline_or_empty.rb’
#¶ ↑
#¶ ↑
require ‘html_tags/toplevel_methods/strip_newlines.rb’
#¶ ↑
#¶ ↑
Constants
- ARRAY_REGISTERED_HTML_TAGS
#¶ ↑
ARRAY_REGISTERED_HTML_TAGS
¶ ↑Please also add to this array whenever you add a new html tag.
Sort alphabetically.
For references, look at the periodic table for HTML tags to find out which ones are available:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element https://developer.mozilla.org/de/docs/Web/HTML/Element
In January 2014 it stated that 107 Elements are known. However, the mozilla reference in March 2015 listed 136 HTML elements.
<b> is no longer valid in HTML5 it seems.
#¶ ↑
- ARRAY_STRIP_NEWLINES
#¶ ↑
HtmlTags::ARRAY_STRIP_NEWLINES
¶ ↑#¶ ↑
- ARRAY_TAGS_WITHOUT_CLOSING_TAG
#¶ ↑
ARRAY_TAGS_WITHOUT_CLOSING_TAG
¶ ↑The following array keeps track of which tags have no closing tag. Please sort alphabetically.
#¶ ↑
The <img> tag is no longer a part of the above Array since as of June 2016.
#¶ ↑
- BR
- DOCTYPE_HTML
#¶ ↑
DOCTYPE_HTML
¶ ↑#¶ ↑
- FILE_VALID_TAGS_IN_A_HEAD_TAG
#¶ ↑
FILE_VALID_TAGS_IN_A_HEAD_TAG
¶ ↑This specifies the path to a yaml-file that keeps an Array.
#¶ ↑
- LAST_UPDATE
#¶ ↑
LAST_UPDATE
¶ ↑#¶ ↑
- NL
#¶ ↑
NL
¶ ↑#¶ ↑
- PROJECT_BASE_DIR
- PROJECT_BASE_DIRECTORY
#¶ ↑
HtmlTags::PROJECT_BASE_DIRECTORY
¶ ↑#¶ ↑
- PROJECT_YAML_DIR
#¶ ↑
PROJECT_YAML_DIR
¶ ↑#¶ ↑
- TABLE
#¶ ↑
Some hardcoded HTML-constants will be defined here.
#¶ ↑
- TD
- TR
- VALID_TAGS_IN_A_HEAD_TAG
- VERSION
#¶ ↑
VERSION
¶ ↑#¶ ↑
Public Class Methods
#¶ ↑
HtmlTags.a
(a tag)¶ ↑
This tag will attempt to create a HTML link. It follows all other conventions as well. The first argument called ‘i` is the target URL to use.
In plain HTML, this would be create a string such as the following one:
<a href="url">Test</a>
The first argument ‘i` is the hyperref-target.
Usage examples:
a('connect') a('connect', :make_newline) a('connect', 'marl1em','great_link','color: blue') a('LINUX_DESIGNING.cgi', :copy_description) a('https://de.wikipedia.org/wiki/Lampensockel#Edisonsockel', 'SELF', :make_newline) a('local_ruby_c', description: 'Ruby C Seite', css_style: 'margin-left: 2em') a( remote_url: remote_url, text: title?.to_s, css_style: 'font-weight: bold; color: darkblue' )
#¶ ↑
# File lib/html_tags/individual_tags/a.rb, line 40 def self.a( hyperref_target = '', link_description = :use_hyperref_as_the_target, css_class = '', the_id = '', css_style = '', javascript = '' ) # ======================================================================= # # The following Hash can be used to store data into, such as :tooltip. # ======================================================================= # internal_hash = {} # ======================================================================= # # Store the generated String in the local variable called result. # ======================================================================= # result = ''.dup # ======================================================================= # # If make_newline is set to true then we will append a <br> tag. # ======================================================================= # make_newline = false close_me = close(__method__) # Default. Must come before case css_class. # ======================================================================= # # Since as of December 2015 we will check whether we have passed an # Array. # # This may look like that way: # # ["https://de.wikipedia.org/wiki/Lampensockel#Edisonsockel", # {:content=>"SELF", :css_class=>"mars2em"}] # # or # # ["http://geizhals.at/philips-voice-tracer-dvt3600-digitales-diktiergeraet-a992644.html?hloc=at", "SELF", 1] # # So we have to stay flexible here. # ======================================================================= # if hyperref_target.is_a? Array if hyperref_target.size > 1 hash = hyperref_target[1] # This may not have to be a Hash, though. if hash.is_a? Hash link_description = hash hyperref_target = hyperref_target[0] elsif hash.is_a? Array if hash[1] link_description = hash[1] end if hash[2] and (hash[2] == 1) make_newline = true end # ================================================================= # # Finally, assign the first entry to hyperref_target. # ================================================================= # hyperref_target = hyperref_target.first end end if hyperref_target.is_a? Array hyperref_target = hyperref_target.first end end case css_class # ======================================================================= # # === :copy_description # ======================================================================= # when :copy_description css_class = '' link_description = hyperref_target # ======================================================================= # # === :make_newline # ======================================================================= # when :make_newline css_class = '' close_me = close(__method__) {{ make_newline: true }} # ======================================================================= # # === :no_newline # ======================================================================= # when :no_newline css_class = '' close_me = close(__method__) {{ make_newline: false }} else # Else do not make a newline, simply pass through.. end # ======================================================================= # # === Check for hyperref_target being a Hash # ======================================================================= # if hyperref_target.is_a? Hash # ===================================================================== # # === :link_description # ===================================================================== # if hyperref_target.has_key? :link_description link_description = hyperref_target.delete(:link_description) # ===================================================================== # # === :description # ===================================================================== # elsif hyperref_target.has_key? :description link_description = hyperref_target.delete(:description) end # ===================================================================== # # === :id # ===================================================================== # if hyperref_target.has_key? :id the_id = hyperref_target.delete(:id) # ===================================================================== # # === :the_id # ===================================================================== # elsif hyperref_target.has_key? :the_id the_id = hyperref_target.delete(:the_id) end # ===================================================================== # # === :make_newline # ===================================================================== # if hyperref_target.has_key? :make_newline make_newline = hyperref_target.delete(:make_newline) # ===================================================================== # # === :linebreak # ===================================================================== # elsif hyperref_target.has_key? :linebreak make_newline = hyperref_target.delete(:linebreak) end # ===================================================================== # # === :css_class # # Handle :css_class early on, as it is a very unproblematic entry. # ===================================================================== # if hyperref_target.has_key? :css_class css_class = hyperref_target.delete(:css_class) end # ===================================================================== # # === :css_style # # This entry point allows us to handle css-styles for a given # HTML tag. # ===================================================================== # if hyperref_target.has_key? :css_style css_style = hyperref_target.delete(:css_style) end # ===================================================================== # # === :content # # Rewrite :content to the more correctly named :link_description. # ===================================================================== # if hyperref_target.has_key? :content link_description = hyperref_target.delete(:content) # ===================================================================== # # === :text # ===================================================================== # elsif hyperref_target.has_key? :text link_description = hyperref_target.delete(:text) end # ===================================================================== # # === :link_description # # This entry point ought to come last. # ===================================================================== # if hyperref_target.has_key?(:link_description) and (hyperref_target[:link_description] == 'SELF') link_description = hyperref_target.delete(:link_description) end # ===================================================================== # # The next two checks should come last, since they will modify # hyperref_target. # ===================================================================== # # ===================================================================== # # === :remote_url # ===================================================================== # if hyperref_target.has_key? :remote_url hyperref_target = hyperref_target.delete(:remote_url) # ===================================================================== # # === :href # ===================================================================== # elsif hyperref_target.has_key? :href hyperref_target = hyperref_target.delete(:href) end if hyperref_target.is_a?(Hash) end # ======================================================================= # # === Intercept Hash for the link_description variable # # The hash can contain entries such as linebreak: true, but also # entries such as content: :self. # ======================================================================= # if link_description.is_a? Hash # ===================================================================== # # === :tooltip # ===================================================================== # if link_description.has_key? :tooltip internal_hash[:tooltip] = link_description.delete(:tooltip) end # ===================================================================== # # === :onclick # # This may look like so: # # onclick: 'change_the_colour_to()' # # ===================================================================== # if link_description.has_key? :onclick javascript = ' onclick="'+link_description.delete(:onclick)+'"' end # ===================================================================== # # === :css_style # ===================================================================== # if link_description.has_key? :css_style css_style = link_description.delete(:css_style) end # ===================================================================== # # === :id # ===================================================================== # if link_description.has_key? :id the_id = link_description.delete(:id) # ===================================================================== # # === :the_id # ===================================================================== # elsif link_description.has_key? :the_id the_id = link_description.delete(:the_id) end # ===================================================================== # # === css_class # ===================================================================== # if link_description.has_key? :css_class css_class = link_description.delete(:css_class) end # ===================================================================== # # Rewrite :link_description into :description. # ===================================================================== # if link_description.has_key? :description link_description = link_description.delete(:description) # ===================================================================== # # Rewrite :link_description into :link_description. # ===================================================================== # elsif link_description.has_key? :link_description link_description = link_description.delete(:link_description) # ===================================================================== # # Rewrite :title into :description. # # This entry point is for input such as: # # a('http://rubyreports.org/', title: 'Ruport') # # ===================================================================== # elsif link_description.has_key? :title link_description = link_description.delete :title # ===================================================================== # # === :content # # Rewrite :content into :link_description. # # This entry point is for input such as: # # a('http://rubyreports.org/', content: '<b>Link</b>') # # ===================================================================== # elsif link_description.has_key? :content link_description = link_description.delete(:content).to_s if link_description and link_description.start_with?('→ ') hyperref_target.sub!(/^→ /,'') end # =================================================================== # # Next, we must both check for 'SELF' 'self', second variant # could also be the Symbol :self. # =================================================================== # if link_description.include?('SELF') or (link_description.to_s == 'self') if link_description.frozen? link_description = link_description.dup end # ================================================================= # # Must replace it with the proper target next. # ================================================================= # link_description = link_description.to_s.sub( # Ensure we have a String. /^SELF/i, hyperref_target ) end else # =================================================================== # # We don't have a link_description entry, so we will simply use # the value from hyperref_target.. # =================================================================== # if link_description.is_a?(Hash) and link_description.empty? link_description = hyperref_target.to_s.dup end end # ===================================================================== # # ==== :content # # This should come last, since it will overwrite link_description. # ===================================================================== # if link_description.is_a?(Hash) and link_description.has_key?(:content) link_description = link_description.delete(:content) end end # ======================================================================= # # Work on link_description next, assuming it is a String at this point. # ======================================================================= # case link_description.to_s when /^→ / # If it starts with a right-arrow. if link_description.to_s == :self link_description = hyperref_target.dup.sub(/^→ /,'') end when /^SELF$/i link_description = link_description.dup if link_description.frozen? link_description = link_description.to_s.sub!( /^SELF/i, hyperref_target.dup # .sub(/^→ /,'') ) end case hyperref_target # Remove leading right-arrows. when /^→ / hyperref_target = hyperref_target.dup if hyperref_target.frozen? hyperref_target.sub!(/^→ /,'') end # ======================================================================= # # === :make_newline is treated in a special manner, as the id. # Same for the number 1, which stands for newline too, due # to historic reasons. # ======================================================================= # case the_id when :make_newline, 1 make_newline = true the_id = '' # Reset it here in this case. end if css_class and css_class.is_a?(String) and (css_class == 'SELF') css_class = ''.dup end if css_class.is_a? Hash # ===================================================================== # # === Intercept key :css_style next, on the css_class variable # # This entry point is for input such as: # # a(@target, css_style: 'color:red; margin-left:2em') # # ===================================================================== # if css_class.has_key? :css_style css_style = css_class.delete :css_style end if css_class.is_a? Hash # Must check again due to the earlier resetting. # ===================================================================== # # === Intercept key :css_class next # ===================================================================== # if css_class.has_key? :css_class # =================================================================== # # Must assign to css_class variable in this case: # =================================================================== # css_class = css_class.delete :css_class end if css_class.is_a? Hash # See above explanation. # ===================================================================== # # === Intercept key :url next # ===================================================================== # if css_class.has_key? :url i = css_class.delete :url end if css_class.is_a? Hash # See above explanation. # ===================================================================== # # === Intercept key :linebreak next # ===================================================================== # if css_class.has_key? :linebreak i = css_class.delete :linebreak close_me = close(__method__) {{ make_newline: i }} end if css_class.is_a? Hash # See above explanation. if css_class.is_a?(Hash) and css_class.empty? css_class = '' end end # ======================================================================= # # === Handle blocks next # # Append a pre-defined content to it, unless we also use a block. # ======================================================================= # if block_given? yielded = yield case yielded # Intercept some Symbols. when :strip hyperref_target.strip! close_me.strip! if close_me when :only_basename if hyperref_target.has_key? :link_description link_description = File.basename(hyperref_target[:link_description]) end when :smaller _ = link_description link_description = '<span style="font-size:smaller">'+_+'</span>' else # =================================================================== # # Assume that it could be a HTML colour, such as :slateblue: # =================================================================== # if yielded.is_a? Symbol begin require 'colours/html/html_colours.rb' if Colours.is_this_html_colour_included?(yielded) if css_style.nil? css_style = ''.dup end css_style = css_style.dup if css_style.frozen? css_style << " color: #{yielded};" end rescue LoadError end end end hyperref_target.merge!(yielded) unless yielded.is_a? Symbol end # ======================================================================= # # === Copy the content of hyperref_target onto link_description # # This should come fairly late, though. # ======================================================================= # case link_description when :use_hyperref_as_the_target link_description = hyperref_target.dup end # ======================================================================= # # Finally we will build-up the result-String next. # ======================================================================= # result = '<a'.dup if hyperref_target.is_a?(Hash) and hyperref_target.empty? and !link_description.empty? hyperref_target = link_description.dup end hyperref_target = hyperref_target.to_s result << ' href="'+hyperref_target+'"' if css_class and !css_class.to_s.empty? result << ' class="'+css_class.to_s+'"' end if the_id and !the_id.empty? result << ' id="'+the_id.to_s+'"' end if css_style and !css_style.empty? result << ' style="'+css_style.to_s+'"' end if javascript and !javascript.empty? # The next lines exist to use "onclick" javascript directly. unless javascript.lstrip.start_with? 'onclick' result << ' javascript="' end result << javascript unless javascript.lstrip.start_with? 'onclick' result << '"' end end if internal_hash.is_a?(Hash) and internal_hash.has_key?(:tooltip) result << " data-tip=\"#{internal_hash[:tooltip]}\"" end result << '>' # result << N result << link_description.to_s # Could be a Symbol after all. result << close_me if make_newline result << '<br>' end # ======================================================================= # # Must add it onto the main String too. # ======================================================================= # return HtmlTags.add(result) end
#¶ ↑
HtmlTags.abbr
¶ ↑
To test this method, try:
HtmlTags.abbr 'WHO','World Health Organization'
#¶ ↑
# File lib/html_tags/individual_tags/abbr.rb, line 14 def self.abbr(abbreviation_to_use = '', long_name = '') if long_name.empty? and !abbreviation_to_use.empty? # ===================================================================== # # In this case, we simply copy to the long name. # ===================================================================== # long_name = abbreviation_to_use.to_s.dup end if block_given? return HtmlTags.add( opening_tag(__method__, title: long_name.to_s)+ abbreviation_to_use+ yield+ close(__method__) ) else return HtmlTags.add( opening_tag(__method__, title: long_name.to_s)+ abbreviation_to_use+ close(__method__) ) end end
#¶ ↑
HtmlTags.audio
¶ ↑
Use a HTML5 audio tag.
#¶ ↑
# File lib/html_tags/individual_tags/audio.rb, line 8 def self.audio(url = '', optional_autoplay = false) case File.extname(url).delete('.') when '','ogg' use_this_audio_type = 'ogg' when 'mp3' use_this_audio_type = 'mpeg' when 'wav' use_this_audio_type = 'wav' else use_this_audio_type = nil # Else we will not play it. end if use_this_audio_type result = '<audio controls' result << ' autoplay="autoplay"' if optional_autoplay result << '>'+N result << '<source src="'+url.to_s+'" type="audio/'+use_this_audio_type.to_s+'">'+N result << 'Your browser does not support the audio element.' result << close(__method__) else nil end return HtmlTags.add(result) end
#¶ ↑
HtmlTags.close
¶ ↑
This method creates the closing tag. It will return that tag as a string.
This method also accepts a block, which can be a hash that could have keys such as { :make_newline => true }.
Usage example:
HtmlTags.close('span')
#¶ ↑
# File lib/html_tags/closing_tag/closing_tag.rb, line 24 def self.close(i, &block) append_newline = true # ======================================================================= # # If we strip newlines, then we won't append them logically. # ======================================================================= # append_newline = false if HtmlTags.strip_newlines? i = i.to_s.dup # It should remain a String. # ======================================================================= # # Next, sanitize some wrongful/shortcut tags here. # ======================================================================= # case i when 'link' i = 'a' when 'field', 'mini_header' i = 'fieldset' end end_string = ''.dup # This will be be appended. # ======================================================================= # # Intercept blocks passed to the method here. # ======================================================================= # if block_given? yielded = yield # Tap into the block. if yielded.is_a? Hash if yielded.has_key? :make_newline end_string << br if yielded[:make_newline] == true end elsif yielded == :make_newline end_string << br elsif yielded == :no_newline append_newline = false # Do not append a newline in this case here. end end result = ''.dup # result << "\n" if append_newline # This one was disabled in April 2022. result << '</'+i.to_s.dup+'>' result << "\n" if append_newline result << end_string # This is the result we will return. A String. return result end
#¶ ↑
HtmlTags.details
¶ ↑
#¶ ↑
# File lib/html_tags/individual_tags/details.rb, line 15 def self.details( i = '', css_class = '', the_id = '', css_style = '', optional_javascript = '', &block ) # ======================================================================= # # === Handle Hashes first # ======================================================================= # if css_class.is_a? Hash # ===================================================================== # # === :css_style # ===================================================================== # if css_class.has_key? :css_style css_style = css_class.delete(:css_style) if css_class.is_a?(Hash) and css_class.empty? css_class = '' end end end content = i.to_s.dup if block_given? content << yield.to_s end return HtmlTags.add( opening_tag(__method__, css_class, the_id, css_style, optional_javascript)+ content+ close(__method__) ) end
#¶ ↑
HtmlTags.h2
(h2 tag)¶ ↑
This method will ultimately generate a <h2></h2> tag.
#¶ ↑
# File lib/html_tags/individual_tags/h2.rb, line 17 def self.h2( i = '', css_class = '', the_id = '', css_style = '', javascript_code = '' ) return HtmlTags.add( opening_tag(__method__, css_class, the_id, css_style, javascript_code)+ i.to_s+ close(__method__) ) end
#¶ ↑
HtmlTags.h3
¶ ↑
To test this method, try:
HtmlTags.h3(text, css_class, the_id, css_style, javascript = ''); n
Keep in mind that this method can be used like this:
h3('Hello world!', css_style: 'margin-top: 2px')
#¶ ↑
# File lib/html_tags/individual_tags/h3.rb, line 24 def self.h3( i = '', css_class = '', the_id = '', css_style = '', optional_javascript = '', &block ) # ======================================================================= # # === Handle Hashes first # ======================================================================= # if css_class.is_a? Hash # ===================================================================== # # === :css_style # ===================================================================== # if css_class.has_key? :css_style css_style = css_class.delete(:css_style) if css_class.is_a?(Hash) and css_class.empty? css_class = '' end end end content = i.to_s if block_given? content << yield.to_s end return HtmlTags.add( opening_tag(__method__, css_class, the_id, css_style, optional_javascript)+ content+ close(__method__) ) end
#¶ ↑
HtmlTags.img
¶ ↑
The img() method creates an <img> tag.
Documentation can be found at:
https://www.w3schools.com/tags/tag_img.asp https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img
The “end result” will be a String such as this here:
<img src="foo.png" alt="Some image">
Note that we make use of the block variant, by specifying a hash which has a :src attribute.
If the first argument to this method is a Hash then that Hash will be checked for certain keys, such as :src or :css_class
If the argument called the_id is a symbol such as :infer_the_id_from_the_filename then it will be evaluated in a special manner.
#¶ ↑
# File lib/html_tags/individual_tags/img.rb, line 37 def self.img( i = 'foo.png', css_class = '', the_id = '', css_style = '' ) # ======================================================================= # # === Handle blocks next # ======================================================================= # if block_given? yielded = yield # ===================================================================== # # === Handle Hashes given via block syntax next # ===================================================================== # if yielded.is_a? Hash if i.is_a? String i = { src: i } # Add this string as the :src key in that case. i.update(yielded) end end end if i.is_a? Hash # ===================================================================== # # === :css_style # ===================================================================== # if i.has_key? :css_style css_style = i.delete(:css_style) end # ===================================================================== # # === :css_class # ===================================================================== # if i.has_key? :css_class css_class = i.delete(:css_class) end # ===================================================================== # # === :id # ===================================================================== # if i.has_key? :id the_id = i.delete(:id) # ===================================================================== # # === :the_id # ===================================================================== # elsif i.has_key? :the_id the_id = i.delete(:the_id) end # ===================================================================== # # === :src # # This entry point should come last, that is, after other checks were # already done. The reason for this is due to the deliberate # self-assignment being done here. # ===================================================================== # if i.has_key? :src i = i.delete(:src) end end case the_id # case tag # ======================================================================= # # === :drag_infer_the_id_from_the_filename # ======================================================================= # when :drag_infer_the_id_from_the_filename, :drag the_id = 'drag_'+File.basename(i). sub(/#{File.extname(i)}/,'') # ======================================================================= # # === :infer_the_id_from_the_filename # ======================================================================= # when :infer_the_id_from_the_filename the_id = File.basename(i). sub(/#{File.extname(i)}/,'') end return HtmlTags.add( opening_tag(__method__, css_class, the_id, css_style) {{ src: i }}+ HtmlTags.newline_or_empty.to_s # i.to_s # Disabled adding the content. <img> tags do not have any content. ) end
#¶ ↑
HtmlTags.opening_tag
(opening_tag
tag)¶ ↑
If we pass a block to this method, we treat it as a special hash.
This can be used to make use of src.
Note that arguments to this method can become quite complicated.
For instance, consider this here:
e p 'Good Bye', :css_class => 'border: 1px solid red', :id => 'goodbye'
#¶ ↑
# File lib/html_tags/opening_tag/opening_tag.rb, line 31 def self.opening_tag( i, # The name of the tag comes here. optional_css_class = '', # 2nd parameter optional_the_id = '', # 3rd parameter optional_css_style = '', # 4th parameter optional_javascript = '', # 5th parameter &block ) append_newline = true i = i.to_s.dup # Must use .dup here, to prevent cascading string-taint. original_tag_name = i.to_s.dup case i when 's','' # Sanitize in these two cases. i = 'span' end content = ''.dup # This here will be appended always. end_string = ''.dup i = i.dup if i.frozen? # ======================================================================= # # === optional_css_class # # Next we must intercept when the second argument is a Hash. # ======================================================================= # if optional_css_class.is_a? Hash # ===================================================================== # # === :id # ===================================================================== # if optional_css_class.has_key? :id optional_the_id = optional_css_class.delete(:id) end # ===================================================================== # # === :css_style # ===================================================================== # if optional_css_class.has_key? :css_style optional_css_style = optional_css_class.delete(:css_style) # ===================================================================== # # === :style # ===================================================================== # elsif optional_css_class.has_key? :style optional_css_style = optional_css_class.delete(:style) end # ===================================================================== # # Intercept javascript keys. Several aliases could be used, so # we have to check for them. # ===================================================================== # if optional_css_class.has_key? :javascript optional_javascript = optional_css_class.delete(:javascript) elsif optional_css_class.has_key? :javascript_code optional_javascript = optional_css_class.delete(:javascript_code) elsif optional_css_class.has_key? :desc content << optional_css_class.delete(:desc).to_s end if optional_css_class.has_key? :css_class # This here must come last. optional_css_class = optional_css_class.delete(:css_class).to_s.dup elsif optional_css_class.has_key? :title i << ' title="'+optional_css_class.delete(:title).to_s+'"' optional_css_class = '' end if optional_css_class.empty? optional_css_class = '' end if optional_css_class.is_a? Hash end # ======================================================================= # # === optional_javascript # # Intercept optional_javascript if it is a Hash. # ======================================================================= # if optional_javascript.is_a? Hash if optional_javascript.has_key? :on_click # Redirect optional_javascript[:onclick] = optional_javascript.delete(:on_click) end if optional_javascript.has_key? :onclick js_temp_string = optional_javascript[:onclick].to_s if js_temp_string.include? 'background-color' optional_javascript = 'onclick="set_background_color('+ js_temp_string.gsub(/background-color\:/,'').delete(';')+ ', this)"' elsif js_temp_string == 'go back in history' # Sanitize it. optional_javascript = 'history.back(-1)' end elsif optional_javascript.has_key? :javascript_hover # The following code works on: # :javascript_hover => 'color: lightblue' js_temp_string = optional_javascript[:javascript_hover].to_s if js_temp_string.include? 'color' optional_javascript = ' onmouseover="colourize(this, '+ js_temp_string.gsub(/color\:/,'').to_s.delete(' ')+')"' end end # ======================================================================= # # Next handle special String-input given to the javascript component. # ======================================================================= # elsif optional_javascript.is_a? String if optional_javascript.include?('on_click:') # Input may be: 'on_click: show_image(:axe))' if optional_javascript.frozen? optional_javascript = optional_javascript.dup end optional_javascript.gsub!(/on_click: /, '') if optional_javascript.include? 'show_image' optional_javascript =~ /\((.+)\)/ optional_javascript = $1.to_s.dup.delete(')') optional_javascript = WebObject.obtain(optional_javascript) optional_javascript = 'onclick="reveal('+"'"+optional_javascript+"'"+')"' end end end # ======================================================================= # # Next we require the four input-objects to be Strings. # ======================================================================= # optional_css_class = optional_css_class.to_s.dup optional_the_id = optional_the_id.to_s case optional_css_style when :bold # ===================================================================== # # === Intercept key :bold next # # This is a special key in the sense that we will "translate" it # into the corresponding CSS value. So :bold really just means # to be replaced with the string 'font-weight: bold'. # ===================================================================== # optional_css_style = 'font-weight: bold;' end optional_css_style = optional_css_style.to_s optional_javascript = optional_javascript.to_s if optional_css_style.include? "\n" # Get rid of newlines and multiple ' '. optional_css_style = beautify_string(optional_css_style) end # ======================================================================= # # === Handle blocks next # # Intercept blocks passed to this method. Typically blocks will, # in some form, be appended to the opening-tag at hand. # ======================================================================= # if block_given? # If we passed a block yielded = yield # Tap into the block. if yielded.is_a? Hash # =================================================================== # # === :src # =================================================================== # if yielded.has_key? :src i << ' src="'+yielded.delete(:src).to_s+'"' end # =================================================================== # # === :href # =================================================================== # if yielded.has_key? :href i << ' href="'+yielded.delete(:href).to_s+'"' end # =================================================================== # # === :type # =================================================================== # if yielded.has_key? :type i << ' type="'+yielded.delete(:type).to_s+'"' end # =================================================================== # # === :value # # This entry point should come after :type, as I think it looks # a bit prettier that way. # =================================================================== # if yielded.has_key? :value i << ' value="'+yielded.delete(:value).to_s+'"' end # =================================================================== # # === :link_description or :description # =================================================================== # if yielded.has_key?(:link_description) or yielded.has_key?(:description) or yielded.has_key?(:content) # if content.empty? # We only append to content if is empty. Disabled this in Jun 2015. if yielded.has_key? :link_description content << yielded.delete(:link_description).to_s elsif yielded.has_key? :description content << yielded.delete(:description).to_s elsif yielded.has_key? :content content << yielded.delete(:content).to_s end #end # =================================================================== # # === :desc # =================================================================== # elsif yielded.has_key? :desc content << yielded.delete(:desc).to_s end # =================================================================== # # === :make_newline # =================================================================== # if yielded.has_key? :make_newline end_string << br end # ===================================================================== # # === Handle Symbols directly past this point # ===================================================================== # elsif yielded.is_a? Symbol case yielded when :no_newline append_newline = false end end end # ======================================================================= # # Next, add the class, id, style, and javascript entries to our tag. # ======================================================================= # i << ' class="'+optional_css_class+'"' unless optional_css_class.empty? i << ' id="'+optional_the_id+'"' unless optional_the_id.empty? i << ' style="'+optional_css_style+'"' unless optional_css_style.empty? unless optional_javascript.empty? # ===================================================================== # # Always prepend ' ' if it is not empty. # ===================================================================== # if optional_javascript.frozen? optional_javascript = optional_javascript.dup end optional_javascript.prepend ' ' # ===================================================================== # # Add some exceptions: currently the exceptions include # "onclick" and "onmouse". # ===================================================================== # unless optional_javascript.strip.start_with?('onclick') or optional_javascript.strip.start_with?('onmouse') optional_javascript = 'javascript="'+optional_javascript+'"' end i << optional_javascript end # ======================================================================= # # === Append '/' to a few tags. # ======================================================================= # if ARRAY_TAGS_WITHOUT_CLOSING_TAG.include? original_tag_name i << '/' # Add exception for <br/> tags and some others. end i = "<#{i}>#{end_string}" i = i.dup if i.frozen? i << "\n" if append_newline i << content return i end
#¶ ↑
HtmlTags.p
¶ ↑
This method can be used to create the html <p> tag.
#¶ ↑
# File lib/html_tags/individual_tags/p.rb, line 14 def self.p( i = '', css_class = '', the_id = '', css_style = '' ) if i.is_a? Hash # ===================================================================== # # === Handle entries such as p(css_style: 'padding:2em') # ===================================================================== # if i.has_key? :css_style css_style = i.delete(:css_style) i = '' if i.empty? end if i.is_a?(Hash) and i.has_key?(:css_class) css_class = i.delete(:css_class) i = '' if i.empty? end end result = opening_tag(__method__, css_class, the_id, css_style).dup if block_given? result << yield.to_s end result << i.to_s+close(__method__).to_s return HtmlTags.add(result) end
Public Instance Methods
#¶ ↑
a¶ ↑
#¶ ↑
# File lib/html_tags/individual_tags/a.rb, line 495 def a( hyperref_target = '', link_description = :use_hyperref_as_the_target, css_class = '', the_id = '', css_style = '', javascript = '', &block ) HtmlTags.a( hyperref_target, link_description, css_class, the_id, css_style, javascript, &block ) end
#¶ ↑
b¶ ↑
This is the same as bold. Note that since HTML 5, it is recommended to use <strong> instead.
#¶ ↑
# File lib/html_tags/individual_tags/b.rb, line 9 def b( i = '', css_class = '', the_id = '', css_style = '' ) return HtmlTags.add( opening_tag(__method__, css_class, the_id, css_style)+ i.to_s+ close(__method__) ) end
#¶ ↑
close (close tag)¶ ↑
This is a wrapper towards HtmlTags.close()
, which will close a given HTML tag.
#¶ ↑
# File lib/html_tags/closing_tag/closing_tag.rb, line 71 def close(i, &block) return HtmlTags.close(i, &block) # Delegate to the above class-method. end
#¶ ↑
div¶ ↑
This method will make a html <div> tag.
Invocation example:
HtmlTags.div(i = '', css_class = '', the_id = '', css_style = '')
#¶ ↑
# File lib/html_tags/individual_tags/div.rb, line 17 def div( i = '', css_class = '', the_id = '', css_style = '', javascript = nil ) if i.is_a? Hash # ===================================================================== # # Next support elements such as: # div(css_class: 'default') { # ===================================================================== # if i.has_key? :css_class css_class = i.delete(:css_class) end if i.has_key? :id the_id = i.delete(:id) end if i.has_key? :css_style css_style = i.delete(:css_style) end i = '' # For now, we remove this. end result = opening_tag(__method__, css_class, the_id, css_style) # ======================================================================= # # === Handle blocks next # ======================================================================= # result << yield.to_s if block_given? result << i # Add the content here. result << close(__method__) result << "\n" HtmlTags.add(result) end
#¶ ↑
figure¶ ↑
To test this, try:
include HtmlTags; figure '<img src="/home/x/DATA/IMG/FOTOS/CATS/03.09.2003_Babykatze.jpg" alt="An awesome picture"> <figcaption>Aisha ist noch immer müde, und sehr, sehr satt.</figcaption>'
#¶ ↑
# File lib/html_tags/individual_tags/figure.rb, line 29 def figure( i = '', css_class = '', the_id = '', css_style = '' ) return HtmlTags.add( opening_tag(__method__, css_class, the_id, css_style)+ i.to_s+ close(__method__) ) end
#¶ ↑
form¶ ↑
This method will generate a HTML <form> tag, ultimately. The form tag is used for user-generated content, such as during a POST action during a HTTP communication.
The HTML <form> element only supports GET and POST as available actions.
Do note that a <form> tag is a bit more complicated than, say, a <div> tag or a <p> tag, because we may need to attach additional information towards the <form> tag, such as “id”, “name” or “action” entries.
Invocation examples:
form(css_style: 'margin-left:2em; margin-top:2px'){ form(action: 'bla.cgi', name: 'some_name', css_style: 'margin-left:2em; margin-top:2px'){
#¶ ↑
# File lib/html_tags/individual_tags/form.rb, line 27 def form( i = '', css_class = '', the_id = '', css_style = '', &block ) # ======================================================================= # # === Handle Hashes as input given # ======================================================================= # if i.is_a? Hash # ===================================================================== # # === :action # # :action is presently not implemented. # ===================================================================== # # if i.has_key? :action # end # ===================================================================== # # === :css_style # ===================================================================== # if i.has_key? :css_style css_style = i.delete(:css_style) end end the_opening_tag = opening_tag( __method__, css_class, the_id, css_style ) # ======================================================================= # # Next, add ad-hoc support for "id", "name" and "action". # ======================================================================= # if i.is_a? Hash if i.has_key? :id the_opening_tag[the_opening_tag.index('>'),0] = ' id="'+i.delete(:id).to_s+'"' end if i.has_key? :action the_opening_tag[the_opening_tag.index('>'),0] = ' action="'+i.delete(:action).to_s+'"' end if i.has_key? :name the_opening_tag[the_opening_tag.index('>'),0] = ' name="'+i.delete(:name).to_s+'"' end if i.has_key? :method the_opening_tag[the_opening_tag.index('>'),0] = ' method="'+i.delete(:method).to_s+'"' end # ===================================================================== # # Finally, if that hash is empty, turn it into an empty String. # ===================================================================== # if i.is_a?(Hash) and i.empty? i = ''.dup end end # ======================================================================= # # Past the next step, the variable `i` will be guaranted to be a String. # ======================================================================= # i = i.to_s if block_given? yielded = "#{yield}" i << yielded end return HtmlTags.add( the_opening_tag+ i+ close(__method__) ) end
#¶ ↑
header¶ ↑
Usage example:
HtmlTags.header('<h1>APP NAME</h1><nav></nav>') => '<header><h1>APP NAME</h1><nav></nav></header>'
#¶ ↑
# File lib/html_tags/individual_tags/header.rb, line 15 def header( i = '', css_class = '', the_id = '', css_style = '', &block ) content = i.to_s if block_given? content = content.to_s+yield.to_s end return HtmlTags.add( opening_tag(__method__, css_class, the_id, css_style)+ content+ close(__method__) ) end
#¶ ↑
html¶ ↑
A <html> tag in HTML5 may have some attributes such as:
<html lang="en">
See www.w3schools.com/tags/ref_language_codes.asp for more information pertaining to the <html> tag.
For now, we will use lang=“en” all the time.
To test this standalone, try:
HtmlTags.html
#¶ ↑
# File lib/html_tags/individual_tags/html.rb, line 24 def html( i = '', css_class = '', the_id = '', css_style = '', &block ) opening = HtmlTags.open_html # Delegate to the method below. _ = ''.dup if block_given? yielded = yield case yielded when :use_unicode_as_encoding opening << "<meta charset=\"UTF-8\">\n" else _ << yielded end end return HtmlTags.add( opening+ i.to_s+ _.to_s+ close(__method__) ) end
#¶ ↑
html_comment
¶ ↑
This method will make a html comment - as in, make a valid comment within the source of a html file. This is done by putting <!– –> around the content in question.
Specific Usage Examples:
HtmlTags.html_comment 'yup' ee HtmlTags.html_comment 'yup' ee html_comment 'this is for displaying some data'
Resources for Comments in HTML:
http://www.tutorialspoint.com/html/html_comments.htm
#¶ ↑
# File lib/html_tags/html_comment.rb, line 25 def html_comment(your_comment = '') HtmlTags.html_comment(your_comment) end
#¶ ↑
input¶ ↑
Do note that input can include complex variants, such as the following:
input(type: :submit, value: 'Create Article')
#¶ ↑
# File lib/html_tags/individual_tags/input.rb, line 16 def input( i = '', css_class = '', the_id = '', css_style = '', &block ) block = nil if i.is_a? Hash block = i.dup i = '' end the_open_tag = opening_tag( __method__, css_class, the_id, css_style ) { block } return HtmlTags.add( the_open_tag.strip ) end
#¶ ↑
is_this_an_allowed_tag_in_head_element?¶ ↑
This method will return true or false depending on whether the given tag may be part of a <head> tag.
#¶ ↑
# File lib/html_tags/html_tags.rb, line 50 def is_this_an_allowed_tag_in_head_element?(i) i = i.to_s # Ought to be a String. # ======================================================================= # # Get rid of <> tags. # ======================================================================= # i.delete!('<') i.delete!('>') VALID_TAGS_IN_A_HEAD_TAG.include? i end
#¶ ↑
is_valid_html?¶ ↑
This method will check whether the given input is a valid html tag or whether it is not. It will delegate towards the class method HtmlTags.is_valid_html?
#¶ ↑
# File lib/html_tags/checks.rb, line 12 def is_valid_html?(i = '</br>') return HtmlTags.is_valid_html? i end
#¶ ↑
label¶ ↑
The html <label> tag is useful to specify text before an <input> field.
The <label> tag defines a label for an <input> element.
The <label> element does not render as anything special for the user. However, it provides a usability improvement for mouse users, because if the user clicks on the text within the <label> element, it toggles the control.
The “for” attribute of the <label> tag should be equal to the id attribute of the related element to bind them together.
This may be best explained through an example:
<label for="male">Male</label> <input type="radio" name="sex" id="male" value="male">
Documentation can be seen here:
http://www.w3schools.com/tags/tag_label.asp
#¶ ↑
# File lib/html_tags/individual_tags/label.rb, line 27 def label( i = '', css_class = '', the_id = '', css_style = '' ) start = opening_tag(__method__, css_class, the_id, css_style) for_label = i.to_s.downcase.strip # Right now the for-label is deduced from the input. start[-2,0] = ' for="'+for_label+'"' # -2 because we also have a trailing newline. return HtmlTags.add( start+ i.to_s+ close(__method__) ) end
#¶ ↑
li (li tag)¶ ↑
This is essentially a HTML representation for the <li> tag.
The first input argument to this method will constitute the content of said <li> tag. Note that the block form to li {} can also be used for content, so use whichever way you prefer.
#¶ ↑
# File lib/html_tags/individual_tags/li.rb, line 16 def li( i = '', # <- This is the content. css_class = '', the_id = '', css_style = '', optional_javascript = '', &block ) if i.is_a? Hash if i.has_key? :css_class css_class = i.delete(:css_class) end i = '' end i = i.to_s.dup # And avoid frozen-errors. # ======================================================================= # # Blocks will be assumed to be used for the first argument, `i`. # ======================================================================= # if block_given? i << yield.to_s end return HtmlTags.add( opening_tag(__method__, css_class, the_id, css_style, optional_javascript)+ i+ close(__method__) ) end
#¶ ↑
main¶ ↑
Usage example:
HtmlTags.main('<h1>APP NAME</h1><nav></nav>') => '<header><h1>APP NAME</h1><nav></nav></header>'
#¶ ↑
# File lib/html_tags/individual_tags/main.rb, line 15 def main( i = '', css_class = '', the_id = '', css_style = '', &block ) content = i.to_s if block_given? content = content.to_s+yield.to_s end return HtmlTags.add( opening_tag(__method__, css_class, the_id, css_style)+ content+ close(__method__) ) end
#¶ ↑
ol (ol tag)¶ ↑
This is essentially a HTML representation for the <ol> tag.
The <ol> tag defines an ordered list. An ordered list can be either numerical or it can be alphabetical.
The <li> tag can be used to define list items.
Documentation for the <ol> tag can be seen here:
https://www.w3schools.com/tags/tag_ol.asp
#¶ ↑
# File lib/html_tags/individual_tags/ol.rb, line 22 def ol( i = '', # <- This is the content. css_class = '', the_id = '', css_style = '', optional_javascript = '', &block ) if i.is_a? Hash if i.has_key? :css_class css_class = i.delete(:css_class) end i = '' end i = i.to_s.dup # And avoid frozen-errors. # ======================================================================= # # Blocks will be assumed to be used for the first argument, `i`. # ======================================================================= # if block_given? i << yield.to_s end return HtmlTags.add( opening_tag(__method__, css_class, the_id, css_style, optional_javascript)+ i+ close(__method__) ) end
#¶ ↑
opening_tag
¶ ↑
# ¶ ↑
# File lib/html_tags/opening_tag/opening_tag.rb, line 273 def opening_tag( i, optional_css_class = '', optional_the_id = '', optional_css_style = '', optional_javascript = '' ) HtmlTags.opening_tag(i, optional_css_class, optional_the_id, optional_css_style, optional_javascript ) end
#¶ ↑
q¶ ↑
The quote tag, <q>.
#¶ ↑
# File lib/html_tags/html_tags.rb, line 78 def q(i = '', css_class = '', the_id = '', css_style = '') return HtmlTags.add( opening_tag(__method__, css_class, the_id, css_style)+ i.to_s+ close(__method__) ) end
#¶ ↑
span¶ ↑
This method will generate HTML <span> tags.
It will first invoke the method called opening_tag
(), then add the content that was given to it (the first parameter), and then close the whole tag via the close() method.
Do note that you can eliminate newlines by invoking the method in something like this, via :strip:
HtmlTags.span('Hello world!','s1') { :strip } HtmlTags.span(i, css_class: 'bord1px', css_style: 'margin-left: 1em')
#¶ ↑
# File lib/html_tags/individual_tags/span.rb, line 23 def span( i = '', css_class = '', the_id = '', css_style = '', javascript = '', &block ) i = i.to_s start_the_method = opening_tag( __method__, css_class, the_id, css_style, javascript ) close_the_method = close(__method__) if block_given? yielded = yield case yielded when :strip # Unfreeze, if frozen: i = i.dup if i.frozen? close_the_method = close_the_method.dup if close_the_method.frozen? start_the_method = start_the_method.dup if start_the_method.frozen? i.strip! close_the_method.strip! start_the_method.strip! end end return HtmlTags.add( start_the_method+ i+ close_the_method ) end
#¶ ↑
stag¶ ↑
This method returns a proper HTML tag, including css class, possible javascript, id, and css style, and then return this as a string.
By default we will use the <span> tag, hence why we have assigned the default argument “span” as the first argument to this method.
“stag” is an alias to this method, a shortcut for “string_tag”.
Note that stag() itself will not return the closing tag.
Specific Usage Examples for this method:
HtmlTags.stag('span','marl1em') puts HtmlTags.stag('span','','','margin-left:0.92em; padding-left:6px')
Would return:
<span class="marl1em">
#¶ ↑
# File lib/html_tags/stag.rb, line 30 def stag( name_of_the_tag = 'span', optional_css_class = '', optional_the_id = '', optional_css_style = '', optional_javascript = '', &block ) if optional_css_class.is_a? Hash _ = otag(name_of_the_tag, optional_css_class) # otag() is defined in opening_tag.rb else # We assume a string here. optional_css_class = optional_css_class.to_s.chomp.dup _ = otag( name_of_the_tag, css_class: optional_css_class, id: optional_the_id, css_style: optional_css_style, javascript: optional_javascript, &block ) end _.to_s end
#¶ ↑
strong¶ ↑
For most purposes, this can be treated as the old (pre-html5) bold html tag.
#¶ ↑
# File lib/html_tags/individual_tags/strong.rb, line 9 def strong(i = '', css_class = '', the_id = '', css_style = '') return HtmlTags.add( opening_tag(__method__, css_class, the_id, css_style)+ i.to_s+ close(__method__) ) end
#¶ ↑
style¶ ↑
We first call the opening_tag
() method, then add the content, and then close the whole thing again via close().
This is essentially a way to add CSS style to a HTML-page.
#¶ ↑
# File lib/html_tags/individual_tags/style.rb, line 15 def style( i = '', css_class = '', the_id = '', css_style = '', javascript = '' ) return HtmlTags.add( opening_tag(__method__, css_class, the_id, css_style, javascript)+ i.to_s+ close(__method__) ) end
#¶ ↑
table¶ ↑
#¶ ↑
# File lib/html_tags/individual_tags/table.rb, line 10 def table( i = '', css_class = '', the_id = '', css_style = '' ) if block_given? yielded = yield if yielded.is_a? Array yielded.each {|entry| i << entry } else i << yielded end end return HtmlTags.add( opening_tag(__method__, css_class, the_id, css_style)+ i.to_s+ close(__method__) ) end
#¶ ↑
td¶ ↑
#¶ ↑
# File lib/html_tags/individual_tags/td.rb, line 10 def td( i = '', css_class = '', the_id = '', css_style = '', &block ) content = i.to_s if block_given? content = content.to_s+yield.to_s end return HtmlTags.add( opening_tag(__method__, css_class, the_id, css_style)+ content+ close(__method__) ) end
#¶ ↑
textarea¶ ↑
Do note that the <textarea> tag also has an entry called spellcheck.
Example:
<textarea spellcheck="true"></textarea>
This appears to be true by default on palemoon, firefox and chrome, but I am not sure that it is too terribly useful, so as far as the HtmlTags
project is concerned, it will be set to false by default.
Invocation example:
HtmlTags.textarea('Hello world!') # => <textarea spellcheck="true">Hello world!</textarea>
#¶ ↑
# File lib/html_tags/individual_tags/textarea.rb, line 25 def textarea( i = '', css_class = '', the_id = '', css_style = '', spellcheck = false ) start = opening_tag(__method__, css_class, the_id, css_style) index = start.index('textarea>')+'textarea>'.size - 1 if spellcheck start[index,0] = ' spellcheck="true"' else start[index,0] = ' spellcheck="false"' end return HtmlTags.add( start+ i.to_s+ close(__method__) ) end
#¶ ↑
video (video tag)¶ ↑
The goal of this method is to create a String such as ‘<video src=“movie.webm”></video>’.
#¶ ↑
# File lib/html_tags/individual_tags/video.rb, line 13 def video( i = '', # ← This is the content. css_class = '', the_id = '', css_style = '', optional_javascript = '', &block ) if i.is_a? Hash # ===================================================================== # # === :css_class # ===================================================================== # if i.has_key? :css_class css_class = i.delete(:css_class) end i = '' end i = i.to_s.dup # And avoid frozen-errors. # ======================================================================= # # Blocks will be assumed to be used for the first argument, `i`. # ======================================================================= # if block_given? i << yield.to_s end video_tag = opening_tag(__method__, css_class, the_id, css_style, optional_javascript).dup video_tag[-2,0] = ' controls' return HtmlTags.add( video_tag+ "<source src=\"#{i}\">"+ close(__method__) ) end