Shorthands and validation (built-ins vs refinements) #3588
Replies: 8 comments 1 reply
-
|
@flavorjones: The general syntax for creating a DOM from a terse function tree was kindly answered in #3587 (comment), but questions 1-5 actually still remain. Will await response as not to re-invent the wheel. |
Beta Was this translation helpful? Give feedback.
-
|
I'm choosing not to respond, so don't wait for me. If what you have works for you, my advice would be to stick with it. |
Beta Was this translation helpful? Give feedback.
-
|
I was wondering simply, is there built-in short forms for ...
4-5. I'll just roll my own, no problem. |
Beta Was this translation helpful? Give feedback.
-
|
You're right! Just sometimes one's state of mind does the unthinkable and asks a human. Thanks for the copy-paste and alluding how you're managing the gem. Which makes you one. (Just had to.) |
Beta Was this translation helpful? Give feedback.
-
|
OK, so the AI suggestions had to be wrangled to work as usual, but results are quite satisfying. Assuming the Questions:
require 'nokogiri'
# XML builder
Nokogiri::XML::Builder.new do
root do
child 'text'
end
end.then { puts it.class, it.to_xml, '-' * 70 } # RunTimeError wo/to_xml
# Nokogiri -> Nokogiri::XML::Element
Nokogiri do
html do
body do
h1 'Hello world'
end
end
end.then { puts it.class, it, '-' * 70 }
# HTML5 builder
Nokogiri::HTML5::Builder.new do
html do
body do
h1 'Hello world'
p 'This little p' # Invokes Kernel.p
ul do
li 'Item 1'
li 'Item 2'
end
table do
tr do
td 'Cell 1'
td 'Cell 2'
end
end
end
end
end.then do
puts it.class, it.to_html, '-' * 70
it.write_xml_to $stdout, indent: 2 # RunTimeError
end |
Beta Was this translation helpful? Give feedback.
-
|
@flavorjones: Little help? |
Beta Was this translation helpful? Give feedback.
-
|
@forthrin Please stop tagging me when you have questions that can be answered with a little of your own research or by asking questions in a more general forum. I will not spend more time answering questions than you spend on asking them. To directly address the bug claims, however:
Not a bug. You're calling write_xml_to on the Builder object, not the Document.
Not a bug. This is documented in the Builder class under "Special Tags". |
Beta Was this translation helpful? Give feedback.
-
|
It's an unfortunate, but recurring phenomenon in popular open source projects where the ratio between developers and users grows disproportional to a point where maintainers end up lashing out at its users for asking questions. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
During time with Nokogiri, making some convenient refinements have been found necessary (see below):
<!DOCTYPE>and<title>, should<meta charset>, nice<meta property="og:image">)<br>as newlines)But maybe comparable features are built-in? Examples much appreciated if so.
Beta Was this translation helpful? Give feedback.
All reactions