Skip to content

REXML::Formatters::Transitive not found. #228

@Beagle123

Description

@Beagle123

Hi:

I tried to use REXML::Formatters::Transitive in my code, but it wasn't found in the package.

Here is the output of irb:

eric@trig:~$ irb
irb(main):001:0> require "rexml"
=> true
irb(main):002:0> REXML::Formatters::Transitive
(irb):2:in `<main>': uninitialized constant REXML::Formatters::Transitive (NameError)
        from /home/eric/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'                                                                                                       
        from /home/eric/.rbenv/versions/3.1.6/bin/irb:25:in `load'                                        
        from /home/eric/.rbenv/versions/3.1.6/bin/irb:25:in `<main>'                                      
irb(main):003:0> 
^C                                                                                                        
irb(main):003:0> 

I tried using the code from github, Transitive.rb, but the output was bad. All the tags were broken onto two lines.

However, I had great success with subclassing Pretty.rb, and outputting the text nodes without formatting which is the result that I wanted. I would suggest making this Formatter:

class PrettyPreserveText < REXML::Formatters::Pretty
  def write_text( node, output )
    output << node.to_s()
  end
end

This is a great result. It has all the benefits of Pretty.rb while preserving long text nodes. It seems like a good idea to preserve text nodes "as-is." In fact, I would suggest changing the Pretty formater to output the unaltered text. When I used Pretty, it worked great except that it would indent every line of a long text string to make it look good. This obviously is rarely a good idea. The users need to be able to control the content of text strings. That's not the job of a formatter.

Thanks for all your work.

Eric

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions