Skip to content
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

Update node.rb required transitive.rb, so it can be found. #229

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Beagle123
Copy link

I recently tried to use REXML::Formatters::Transitive, and its not included in REXML.

I recently tried to use REXML::Formatters::Transitive, and its not included in REXML.
@naitoh
Copy link
Contributor

naitoh commented Jan 7, 2025

Thank you for this PR.

@kou

https://docs.ruby-lang.org/ja/latest/class/REXML=3a=3aFormatters=3a=3aTransitive.html (Sorry, this is a Japanese document only.)

require 'rexml/document'
require 'rexml/formatters/transitive'

This documentation explicitly requires 'rexml/formatters/transitive'.

Do you think we should be able to use REXML::Formatters::Transitive.new with require "rexml" as well as REXML::Formatters::Pretty.new?

irb(main):001> require 'rexml'
=> true
irb(main):002> REXML::Formatters::Pretty.new
=> #<REXML::Formatters::Pretty:0x000000012333db18 @compact=false, @ie_hack=false, @indentation=2, @level=0, @width=80>
irb(main):003> REXML::Formatters::Transitive.new
(irb):3:in '<main>': uninitialized constant REXML::Formatters::Transitive (NameError)
	from <internal:kernel>:168:in 'Kernel#loop'
	from /Users/naitoh/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/irb-1.14.3/exe/irb:9:in '<top (required)>'
	from /Users/naitoh/.rbenv/versions/3.4.1/bin/irb:25:in 'Kernel#load'
	from /Users/naitoh/.rbenv/versions/3.4.1/bin/irb:25:in '<main>'

See: #228

@kou
Copy link
Member

kou commented Jan 8, 2025

It's required lazy:

require_relative "formatters/transitive"

But the approach may be slow on JRuby. See also: #219

So, I'm OK with requiring it non-lazy. But it should be done in document.rb not node.rb because it's not used in node.rb.

@naitoh
Copy link
Contributor

naitoh commented Jan 8, 2025

It's required lazy:

require_relative "formatters/transitive"

But the approach may be slow on JRuby. See also: #219

So, I'm OK with requiring it non-lazy. But it should be done in document.rb not node.rb because it's not used in node.rb.

I see.
Thanks.

@Beagle123
Could you change this PR to conform to the above policy?

Specifically, they are as follows.

  1. Remove the following lazy require.
  1. Add non-lazy require in document.rb, not node.rb.

@kou
Copy link
Member

kou commented Jan 8, 2025

Ah, I didn't notice that we have a lazy require in element.rb too.
Then element.rb is better than document.rb because document.rb depends on element.rb.

@naitoh
Copy link
Contributor

naitoh commented Jan 8, 2025

Ah, I didn't notice that we have a lazy require in element.rb too. Then element.rb is better than document.rb because document.rb depends on element.rb.

OK, I see.

@Beagle123
Could you change this PR to conform to the above policy?

Specifically, they are as follows.

  1. Remove the following lazy require.
  1. Add non-lazy require in element.rb, not node.rb.

@Beagle123
Copy link
Author

Hi:

I think I've made the changes requested.

However, I don't think my original issue is resolved. My issue was that using Pretty.rb resulted in my text lines having a bunch of whitespace inserted so that the XML file looks indented, but all my text has drastically changed. I was not able to require REXML::Formatters::Transitive as it was not found. I downloaded Transitive.rb, but the output was totally disjointed. I had to hack Pretty.rb to make it not alter my text, and that works. But this is not a good situation for users. I assure you that nobody will be happy with the output from Transitive, and the only choice is to have their text nodes altered by Pretty.rb.

I've uploaded my new version of Transitive.rb. I concede that it is a change from the current version, but it does the desireable behavior that Transitive is supposed to do: Pretty output with preserved text lines.

Thanks,
Eric

Copy link
Contributor

@naitoh naitoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've made the changes requested.

Thanks.
Please make some more corrections.

@@ -1505,7 +1505,7 @@ def write(output=$stdout, indent=-1, transitive=false, ie_hack=false)
Kernel.warn("#{self.class.name}.write is deprecated. See REXML::Formatters", uplevel: 1)
formatter = if indent > -1
if transitive
require_relative "formatters/transitive"
require_relative "formatters/transitive"
Copy link
Contributor

@naitoh naitoh Jan 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This position is lazy require.
Please move this line at the beginning position of this file so that it is non-lazy require.

See:

# frozen_string_literal: false
require_relative "parent"
require_relative "namespace"
require_relative "attribute"
require_relative "cdata"
require_relative "xpath"
require_relative "parseexception"

@@ -388,7 +388,7 @@ def write(*arguments)
end
formatter = if indent > -1
if transitive
require_relative "formatters/transitive"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this empty line.

@naitoh
Copy link
Contributor

naitoh commented Jan 11, 2025

However, I don't think my original issue is resolved.

I would like to discuss that issue in #230.

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

Successfully merging this pull request may close these issues.

3 participants