Sha256: 267123f06317a5d78a9deee74789bd310b955790169f923c71c208b4aad0ec8e
Contents?: true
Size: 1.6 KB
Versions: 1
Compression:
Stored size: 1.6 KB
Contents
module BBLib module HTML TAGS = %w{a abbr address area article aside audio b base bdi bdo blockquote body br button canvas caption cite code col colgroup command datalist dd del details dfn div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup hr html i iframe img input ins kbd keygen label legend li link map mark menu meta meter nav noscript object ol optgroup option output p param pre progress q rp rt ruby s samp script section select small source span strong style sub summary sup table tbody td textarea tfoot th thead time title tr track u ul var video wbr} SELF_CLOSING_TAGS = %w{area base br col command embed hr img input keygen link meta param source track wbr} def self.self_close?(tag) SELF_CLOSING_TAGS.include?(tag.to_s.downcase) end module Builder BBLib::HTML::TAGS.each do |tag| define_method(tag) do |content = nil, **attributes, &block| context = attributes.delete(:context) || self.context t = Tag.new(type: tag, attributes: attributes, content: content, context: context) children << t t.instance_eval(&block) if block end end def build(&block) instance_eval(&block) self end def self.build(type, content = nil, **attributes, &block) raise ArgumentError, "Unknown element type '#{type}'." unless TAGS.include?(type.to_s.downcase) context = attributes.delete(:context) Tag.new(type: type, content: content, attributes: attributes, context: context, &block) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bblib-0.4.1 | lib/html/builder.rb |