Sha256: 874947aa30a947a2c2529f4b7bf5de77cf753a284eb5c23a684f6cb9c7896064

Contents?: true

Size: 1.92 KB

Versions: 235

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: false
#vim:ts=2 sw=2 noexpandtab:
require_relative 'child'
require_relative 'source'

module REXML
  # This class needs:
  # * Documentation
  # * Work!  Not all types of attlists are intelligently parsed, so we just
  # spew back out what we get in.  This works, but it would be better if
  # we formatted the output ourselves.
  #
  # AttlistDecls provide *just* enough support to allow namespace
  # declarations.  If you need some sort of generalized support, or have an
  # interesting idea about how to map the hideous, terrible design of DTD
  # AttlistDecls onto an intuitive Ruby interface, let me know.  I'm desperate
  # for anything to make DTDs more palateable.
  class AttlistDecl < Child
    include Enumerable

    # What is this?  Got me.
    attr_reader :element_name

    # Create an AttlistDecl, pulling the information from a Source.  Notice
    # that this isn't very convenient; to create an AttlistDecl, you basically
    # have to format it yourself, and then have the initializer parse it.
    # Sorry, but for the foreseeable future, DTD support in REXML is pretty
    # weak on convenience.  Have I mentioned how much I hate DTDs?
    def initialize(source)
      super()
      if (source.kind_of? Array)
        @element_name, @pairs, @contents = *source
      end
    end

    # Access the attlist attribute/value pairs.
    #  value = attlist_decl[ attribute_name ]
    def [](key)
      @pairs[key]
    end

    # Whether an attlist declaration includes the given attribute definition
    #  if attlist_decl.include? "xmlns:foobar"
    def include?(key)
      @pairs.keys.include? key
    end

    # Iterate over the key/value pairs:
    #  attlist_decl.each { |attribute_name, attribute_value| ... }
    def each(&block)
      @pairs.each(&block)
    end

    # Write out exactly what we got in.
    def write out, indent=-1
      out << @contents
    end

    def node_type
      :attlistdecl
    end
  end
end

Version data entries

235 entries across 228 versions & 33 rubygems

Version Path
rexml-3.3.9 lib/rexml/attlistdecl.rb
brakeman-6.2.2 bundle/ruby/3.1.0/gems/rexml-3.3.8/lib/rexml/attlistdecl.rb
brakeman-6.2.2.rc1 bundle/ruby/3.3.0/gems/rexml-3.3.8/lib/rexml/attlistdecl.rb
cloudsmith-api-2.0.15 vendor/bundle/ruby/2.6.0/gems/rexml-3.3.8/lib/rexml/attlistdecl.rb
cloudsmith-api-2.0.14 vendor/bundle/ruby/2.6.0/gems/rexml-3.3.8/lib/rexml/attlistdecl.rb
rexml-3.3.8 lib/rexml/attlistdecl.rb
rexml-3.3.7 lib/rexml/attlistdecl.rb
brakeman-6.2.1 bundle/ruby/3.1.0/gems/rexml-3.3.6/lib/rexml/attlistdecl.rb
brakeman-6.2.0 bundle/ruby/3.1.0/gems/rexml-3.3.6/lib/rexml/attlistdecl.rb
rexml-3.3.6 lib/rexml/attlistdecl.rb
rexml-3.3.5 lib/rexml/attlistdecl.rb
rexml-3.3.4 lib/rexml/attlistdecl.rb
rexml-3.3.3 lib/rexml/attlistdecl.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rexml-3.3.1/lib/rexml/attlistdecl.rb
rexml-3.3.2 lib/rexml/attlistdecl.rb
rexml-3.3.1 lib/rexml/attlistdecl.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rexml-3.2.5/lib/rexml/attlistdecl.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rexml-3.2.5/lib/rexml/attlistdecl.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rexml-3.2.5/lib/rexml/attlistdecl.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rexml-3.3.0/lib/rexml/attlistdecl.rb