Project

General

Profile

Actions

Feature #20525

open

Percent string literal with indentation support or String#dedent

Added by bradgessler (Brad Gessler) 26 days ago. Updated 26 days ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:118180]

Description

I have code that looks like this in an application:

ContentSlide(title: "Why Phlex?"){
  Markdown <<~MARKDOWN

  * Because its fun
  * Because its super-de-dooper
  MARKDOWN
},

The "squiggle" HEREDOCs strips the indentation, but the name of the HEREDOC doesn't look that great since "Markdown" appears twice.

What I'd prefer is a string literal that deals with indentation, maybe it looks something like this:

ContentSlide(title: "Why Phlex?"){
  Markdown %~{
    # Why do you like markdown?

    * Because its fun
    * Because its super-de-dooper
  }
},

If Ruby doesn't want to go down the path of adding another type of literal, I'd propose adding a method to String that does the same thing as the ~ HEREDOC so something like this is possible:

ContentSlide(title: "Why Phlex?"){
  Markdown %{
    # Why do you like markdown?

    * Because its fun
    * Because its super-de-dooper
  }.dedent
},
Actions #1

Updated by bradgessler (Brad Gessler) 26 days ago

  • Tracker changed from Bug to Feature
  • Backport deleted (3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN)
Actions #2

Updated by bradgessler (Brad Gessler) 26 days ago

  • Subject changed from Percent string literal with indentation support to Percent string literal with indentation support or String#dedent
Actions #3

Updated by bradgessler (Brad Gessler) 26 days ago

  • Description updated (diff)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0