Project

General

Profile

Actions

Feature #20852

closed

Anonymous HEREDOC blocks

Added by bradgessler (Brad Gessler) 24 days ago. Updated 15 days ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:119636]

Description

Consider the following code.

# 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.

# 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:

# 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:

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:

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.

Actions

Also available in: Atom PDF

Like1
Like1