Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Beagle123 opened this issue Jan 7, 2025 · 1 comment · May be fixed by #230
Open

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

Beagle123 opened this issue Jan 7, 2025 · 1 comment · May be fixed by #230

Comments

@Beagle123
Copy link

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

@Beagle123
Copy link
Author

This is what the output of @doc.write(transitive: true) looks like now:


<interface
><requires lib='gtk+' version='3.24'
  /><object class='GtkWindow' id='window1'
  ><property name='default-height'
    >1000</property
    ><property name='default-width'
    >1400</property
    ><property name='modal'
    >False</property
    ><child
    ><object class='GtkBox' id='main_box'
      ><property name='margin-top'
        >20</property
        ><property name='margin-bottom'
        >20</property
        ><property name='margin-start'
        >20</property
        ><property name='margin-end'
        >19</property
        ><property name='spacing'
        >10</property
        ><property name='orientation'
        >vertical</property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant