[ruby-core:118180] [Ruby master Bug#20525] Percent string literal with indentation support

Issue #20525 has been reported by bradgessler (Brad Gessler). ---------------------------------------- Bug #20525: Percent string literal with indentation support https://bugs.ruby-lang.org/issues/20525 * Author: bradgessler (Brad Gessler) * Status: Open * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- I have code that looks like this in an application: ```ruby 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: ```ruby ContentSlide(title: "Why Phlex?"){ Markdown %{ # Why do you like markdown? * Because its fun * Because its super-de-dooper }.deindent }, ``` -- https://bugs.ruby-lang.org/

Issue #20525 has been updated by nobu (Nobuyoshi Nakada). It conflicts with the existing syntax. `%` plus a punctuation starts a string literal that ends with the punctuation. ---------------------------------------- Feature #20525: Percent string literal with indentation support or String#dedent https://bugs.ruby-lang.org/issues/20525#change-109273 * Author: bradgessler (Brad Gessler) * Status: Open ---------------------------------------- I have code that looks like this in an application: ```ruby 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: ```ruby ContentSlide(title: "Why Phlex?"){ Markdown %{ # Why do you like markdown? * Because its fun * Because its super-de-dooper }.dedent }, ``` -- https://bugs.ruby-lang.org/

Issue #20525 has been updated by shyouhei (Shyouhei Urabe). Why not `<<~"}"` ? ---------------------------------------- Feature #20525: Percent string literal with indentation support or String#dedent https://bugs.ruby-lang.org/issues/20525#change-109299 * Author: bradgessler (Brad Gessler) * Status: Open ---------------------------------------- I have code that looks like this in an application: ```ruby 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: ```ruby ContentSlide(title: "Why Phlex?"){ Markdown %{ # Why do you like markdown? * Because its fun * Because its super-de-dooper }.dedent }, ``` -- https://bugs.ruby-lang.org/

Issue #20525 has been updated by bradgessler (Brad Gessler). Actually this looks decent: ```rb Markdown ~{ # Hi! This is markdown } ``` ---------------------------------------- Feature #20525: Percent string literal with indentation support or String#dedent https://bugs.ruby-lang.org/issues/20525#change-109303 * Author: bradgessler (Brad Gessler) * Status: Open ---------------------------------------- I have code that looks like this in an application: ```ruby 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: ```ruby ContentSlide(title: "Why Phlex?"){ Markdown %{ # Why do you like markdown? * Because its fun * Because its super-de-dooper }.dedent }, ``` -- https://bugs.ruby-lang.org/

Issue #20525 has been updated by mame (Yusuke Endoh). Status changed from Open to Rejected This was briefly discussed at the dev meeting, but ended with "why not use a shorter delimiter like `<<~END` or `<<~MD`?" ---------------------------------------- Feature #20525: Percent string literal with indentation support or String#dedent https://bugs.ruby-lang.org/issues/20525#change-109324 * Author: bradgessler (Brad Gessler) * Status: Rejected ---------------------------------------- I have code that looks like this in an application: ```ruby 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: ```ruby ContentSlide(title: "Why Phlex?"){ Markdown %{ # Why do you like markdown? * Because its fun * Because its super-de-dooper }.dedent }, ``` -- https://bugs.ruby-lang.org/

Issue #20525 has been updated by bradgessler (Brad Gessler). Same reason you can conjure up a Proc via `-> {}` — the syntax looks cleaner and you don't have to stop and try to name it. Not having to name a string is a pretty big boost in terms staying in the flow. The second thing: it looks ugly having two of the same names by each other, which the original example shows: ``` markdown <<~MD # Hello How are you doing? MD ``` still looks kind of weird. This looks better: ``` markdown <<~ # Hello How are you doing?
----------------------------------------
Feature #20525: Percent string literal with indentation support or String#dedent
https://bugs.ruby-lang.org/issues/20525#change-109599
* Author: bradgessler (Brad Gessler)
* Status: Rejected
----------------------------------------
I have code that looks like this in an application:
```ruby
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: ```ruby ContentSlide(title: "Why Phlex?"){ Markdown %{ # Why do you like markdown? * Because its fun * Because its super-de-dooper }.dedent }, ``` -- https://bugs.ruby-lang.org/

Issue #20525 has been updated by ufuk (Ufuk Kayserilioglu). @bradgessler I am not sure if you've missed the suggestion by @shyouhei in https://bugs.ruby-lang.org/issues/20525#note-5: ```ruby markdown <<~"}" # Hello How are you doing? } ``` This doesn't need naming anything and has no repetition either. ---------------------------------------- Feature #20525: Percent string literal with indentation support or String#dedent https://bugs.ruby-lang.org/issues/20525#change-109603 * Author: bradgessler (Brad Gessler) * Status: Rejected ---------------------------------------- I have code that looks like this in an application: ```ruby 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: ```ruby ContentSlide(title: "Why Phlex?"){ Markdown %{ # Why do you like markdown? * Because its fun * Because its super-de-dooper }.dedent }, ``` -- https://bugs.ruby-lang.org/

Issue #20525 has been updated by bradgessler (Brad Gessler). Oh interesting, I thought that was a typo 😂. I was playing around with characters after I wrote this and found something that I think looks a little better than the "}" thing: ```ruby markdown <<~___ # Hello How are you doing? ___ ``` I now understand that both of those work, but it's still not as beautiful syntactically speaking as a HEREDOCS that doesn't require a name or work-around. ---------------------------------------- Feature #20525: Percent string literal with indentation support or String#dedent https://bugs.ruby-lang.org/issues/20525#change-109606 * Author: bradgessler (Brad Gessler) * Status: Rejected ---------------------------------------- I have code that looks like this in an application: ```ruby 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: ```ruby ContentSlide(title: "Why Phlex?"){ Markdown %{ # Why do you like markdown? * Because its fun * Because its super-de-dooper }.dedent }, ``` -- https://bugs.ruby-lang.org/
participants (5)
-
bradgessler (Brad Gessler)
-
mame (Yusuke Endoh)
-
nobu (Nobuyoshi Nakada)
-
shyouhei (Shyouhei Urabe)
-
ufuk (Ufuk Kayserilioglu)