ruby / ruby/rexml

REXML::Formatters::Transitive not found.

Open
#228 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
182
Forks
99
Avg merge
2d 23h
Merged PRs (30d)
8

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading Transitive.rb and Pretty.rb to compare the available formatter behavior and how text nodes are handled. Check how REXML exposes formatters, then determine the expected behavior for preserving long text nodes and confirm it with focused coverage before considering the issue done.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.