* [ruby-core:119636] [Ruby master Feature#20852] Anonymous HEREDOC blocks
@ 2024-10-29 7:33 bradgessler (Brad Gessler) via ruby-core
2024-11-07 9:45 ` [ruby-core:119796] " matz (Yukihiro Matsumoto) via ruby-core
0 siblings, 1 reply; 2+ messages in thread
From: bradgessler (Brad Gessler) via ruby-core @ 2024-10-29 7:33 UTC (permalink / raw)
To: ruby-core; +Cc: bradgessler (Brad Gessler)
Issue #20852 has been reported by bradgessler (Brad Gessler).
----------------------------------------
Feature #20852: Anonymous HEREDOC blocks
https://bugs.ruby-lang.org/issues/20852
* Author: bradgessler (Brad Gessler)
* Status: Open
----------------------------------------
Consider the following code.
```ruby
# Consider the following code.
Markdown.render <<~MARKDOWN
# Hello there
This is a Markdown file. See?
1. This is a list
2. With items
3. And more items
MARKDOWN
```
There's a lot of "Markdown" that's repeated.
```ruby
# Or this
SQL.execute <<~SQL
SELECT * FROM users WHERE id = 1;
SQL
```
It's fine. It works. The key feature is that it understands the text in that block is indented.
Not requiring the name could make the syntax less redundant and free developers up from having to name the string. Here's what that could look like:
```ruby
# Now with 75% less markdown!
Markdown.render <<~
# Hello there
This is a Markdown file. See?
1. This is a list
2. With items
3. And more items
~>>
# We can't sell SQL symbols fast enough!
SQL.execute <<~
SELECT * FROM users WHERE id = 1;
~>>
```
I implement a lot of my application UI in Phlex. The dream is that I can build pages out that look like this:
```ruby
class Form < ApplicationForm
def view_template
input(type: "text", name: "name", placeholder: "Name")
fieldset{
h2 { "Agreement" }
article(class: "prose"){
markdown <<~
## Terms and Conditions
By submitting this form, you agree to the terms and conditions of this website.
# Privacy Policy
We will not share your information with anyone.
...
~>>
}
}
button{ "Submit" }
end
end
```
The closest I can get to that today is if I do this:
```ruby
SQL.execute <<~_
SELECT * FROM users WHERE id = 1;
_
```
I've proposed a similar feature a while back and chimed in on similar proposals, but after thinking about it for a bit I realized "Anonymous HEREDOC blocks" is a slightly different approach that could be a different possible path forward.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
* [ruby-core:119796] [Ruby master Feature#20852] Anonymous HEREDOC blocks
2024-10-29 7:33 [ruby-core:119636] [Ruby master Feature#20852] Anonymous HEREDOC blocks bradgessler (Brad Gessler) via ruby-core
@ 2024-11-07 9:45 ` matz (Yukihiro Matsumoto) via ruby-core
0 siblings, 0 replies; 2+ messages in thread
From: matz (Yukihiro Matsumoto) via ruby-core @ 2024-11-07 9:45 UTC (permalink / raw)
To: ruby-core; +Cc: matz (Yukihiro Matsumoto)
Issue #20852 has been updated by matz (Yukihiro Matsumoto).
Status changed from Open to Rejected
I don't think we should enhance here-doc syntax any further. It's too complex already.
Matz.
----------------------------------------
Feature #20852: Anonymous HEREDOC blocks
https://bugs.ruby-lang.org/issues/20852#change-110481
* Author: bradgessler (Brad Gessler)
* Status: Rejected
----------------------------------------
Consider the following code.
```ruby
# Consider the following code.
Markdown.render <<~MARKDOWN
# Hello there
This is a Markdown file. See?
1. This is a list
2. With items
3. And more items
MARKDOWN
```
There's a lot of "Markdown" that's repeated.
```ruby
# Or this
SQL.execute <<~SQL
SELECT * FROM users WHERE id = 1;
SQL
```
It's fine. It works. The key feature is that it understands the text in that block is indented.
Not requiring the name could make the syntax less redundant and free developers up from having to name the string. Here's what that could look like:
```ruby
# Now with 75% less markdown!
Markdown.render <<~
# Hello there
This is a Markdown file. See?
1. This is a list
2. With items
3. And more items
~>>
# We can't sell SQL symbols fast enough!
SQL.execute <<~
SELECT * FROM users WHERE id = 1;
~>>
```
I implement a lot of my application UI in Phlex. The dream is that I can build pages out that look like this:
```ruby
class Form < ApplicationForm
def view_template
input(type: "text", name: "name", placeholder: "Name")
fieldset{
h2 { "Agreement" }
article(class: "prose"){
markdown <<~
## Terms and Conditions
By submitting this form, you agree to the terms and conditions of this website.
# Privacy Policy
We will not share your information with anyone.
...
~>>
}
}
button{ "Submit" }
end
end
```
The closest I can get to that today is if I do this:
```ruby
SQL.execute <<~_
SELECT * FROM users WHERE id = 1;
_
```
I've proposed a similar feature a while back and chimed in on similar proposals, but after thinking about it for a bit I realized "Anonymous HEREDOC blocks" is a slightly different approach that could be a different possible path forward.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-11-07 9:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-29 7:33 [ruby-core:119636] [Ruby master Feature#20852] Anonymous HEREDOC blocks bradgessler (Brad Gessler) via ruby-core
2024-11-07 9:45 ` [ruby-core:119796] " matz (Yukihiro Matsumoto) via ruby-core
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).