Sha256: 8ef7a7f55d4eee1c48b5b1e4b3db823006388eaadeab47ecba54ae5046f1c6fa
Contents?: true
Size: 1.47 KB
Versions: 3
Compression:
Stored size: 1.47 KB
Contents
# frozen_string_literal: true if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0") using Phlex::Overrides::Symbol::Name end module Phlex::Elements def register_element(element, tag: element.name.tr("_", "-")) class_eval(<<-RUBY, __FILE__, __LINE__ + 1) # frozen_string_literal: true def #{element}(**attributes, &block) if attributes.length > 0 if block_given? @_target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[attributes.hash] || __attributes__(**attributes)) << ">" yield_content(&block) @_target << "</#{tag}>" else @_target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[attributes.hash] || __attributes__(**attributes)) << "></#{tag}>" end else if block_given? @_target << "<#{tag}>" yield_content(&block) @_target << "</#{tag}>" else @_target << "<#{tag}></#{tag}>" end end nil end alias_method :_#{element}, :#{element} RUBY self::REGISTERED_ELEMENTS[element] = tag element end def register_void_element(element, tag: element.name.tr("_", "-")) class_eval(<<-RUBY, __FILE__, __LINE__ + 1) # frozen_string_literal: true def #{element}(**attributes) if attributes.length > 0 @_target << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[attributes.hash] || __attributes__(**attributes)) << ">" else @_target << "<#{tag}>" end nil end alias_method :_#{element}, :#{element} RUBY self::REGISTERED_ELEMENTS[element] = tag element end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
phlex-1.4.2 | lib/phlex/elements.rb |
phlex-1.4.1 | lib/phlex/elements.rb |
phlex-1.4.0 | lib/phlex/elements.rb |