Sha256: f77de71edb6ce28e6a2259d1a8b3841364cd41bbded5c30e3e70e57e19afd466

Contents?: true

Size: 1.47 KB

Versions: 6

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0")
	using Overrides::Symbol::Name
end

module Phlex
	module 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
			RUBY
		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
			RUBY
		end
	end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
phlex-1.0.1 lib/phlex/elements.rb
phlex-1.1.1 lib/phlex/elements.rb
phlex-1.1.0 lib/phlex/elements.rb
phlex-1.0.0 lib/phlex/elements.rb
phlex-1.0.0.rc2 lib/phlex/elements.rb
phlex-1.0.0.rc1 lib/phlex/elements.rb