From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.0 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id D87211F453 for ; Thu, 14 Feb 2019 08:34:52 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 531AF1219E3; Thu, 14 Feb 2019 17:34:48 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 8839A1219E3 for ; Thu, 14 Feb 2019 17:34:46 +0900 (JST) Received: by filter0046p3las1.sendgrid.net with SMTP id filter0046p3las1-32385-5C652824-12 2019-02-14 08:34:44.69772786 +0000 UTC m=+20390.357207879 Received: from herokuapp.com (ec2-54-224-197-248.compute-1.amazonaws.com [54.224.197.248]) by ismtpd0032p1iad2.sendgrid.net (SG) with ESMTP id dMZU4TliQa2vi2p24dzRYA for ; Thu, 14 Feb 2019 08:34:44.430 +0000 (UTC) Date: Thu, 14 Feb 2019 08:34:45 +0000 (UTC) From: kimmo.lehto@gmail.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 66997 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15538 X-Redmine-Issue-Author: kke X-Redmine-Sender: kke X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS7G5P7S/cwvVpUrhLyM1EoFJHUHP8/aULduKG hoMpaIb6zYaqT4wadaZNdeSDSx2MPppIerFJpdZUzTYFmSWUDOqOzpOiloCWhZcIRpJ9AO/Z30GPJm +Y40S4LiQfpcgy3H2PTo/7BNw2hDMmFSgixGLh7UhQOdke+sY8oRCMt0OA== X-ML-Name: ruby-core X-Mail-Count: 91545 Subject: [ruby-core:91545] [Ruby trunk Feature#15538] Erb indenting / unindenting X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #15538 has been updated by kke (Kimmo Lehto). Description updated Subject changed from Erb indenting / unindenting trim mode to Erb indenting / unindenting Perhaps `<%~` would be good as it resembles the squiggly heredoc `<<~EOB` I'll try to improve on your PoC. It seems to only work when the `<%|` is in the beginning of the line, for anything else it fails. I have yet to find a way to find the index of `stag`, but I have a hunch it has to be done in the line scanner and yielded there. Also, something like this should work: ``` <%= "abcd" %> <%~ [1.2.3].each do |num| -%> <%= num %> <%~ end -%> ``` which would produce: ``` abcd 1 2 3 ``` ---------------------------------------- Feature #15538: Erb indenting / unindenting https://bugs.ruby-lang.org/issues/15538#change-76808 * Author: kke (Kimmo Lehto) * Status: Third Party's Issue * Priority: Normal * Assignee: * Target version: ---------------------------------------- In `Erb`, would it be possible to add a new tag that would indent the following content to match the depth of the tag? The tag could be `<%~` (to resemble the `<<~EOS` squiggy heredoc). ## Reason Something like this would be easy to follow: ``` ruby 1 <%- [2, 3, 4].each do |num| -%> <%- unless num == 3 -%> <%= num %> <%- end -%> <%- end -%> 5 ``` But unfortunately it will render with "extra" indentation: ``` 1 2 4 5 ``` Currently, to avoid this, you have to write your template using either no indentation: ``` 1 <%- [2, 3, 4].each do |num| -%> <%- unless num == 3 -%> <%= num %> <%- end -%> <%- end -%> 5 ``` Or a weird jumpy indentation: ``` 1 <%- [2, 3, 4].each do |num| -%> <%- unless num == 3 -%> <%= num %> <%- end -%> <%- end -%> 5 ``` With the `<%~` it could be written as: ```ruby 1 <%~ [2, 3, 4].each do |num| -%> <%- unless num == 3 -%> <%= num %> <%- end -%> <%~ end -%> 5 ``` And it would output as desired without the "extra" indentation: ``` 1 2 4 5 ``` Another example: ``` <%= "abcd" %> <%~ [1.2.3].each do |num| -%> <%= num %> <%~ end -%> ``` would produce: ``` abcd 1 2 3 ``` ## Using with `=` It would also be handy if the `~` could be used in `<%=` statements, perhaps as `<%~=`. This would be excellent for example when templating YAML's: ```yaml <%- bars = %w(abc def)" -%> foo: bar: <%~= bars.map { |bar| "- #{bar}\n" } %> ``` Which would reindent the statement outcome to produce something like: ```yaml foo: bar: - abc - def ``` This would require these new tags: 1. `<%~` begin a code block and begin or end reindentation mode. content produced inside the block will be reindented to the depth of the `<` character in `<%~`. If the indentation mode was already active due to a previous `<%~`, it ends the indentation mode. 2. `<%~=` like regular `<%=` but multiline strings will be reindented to the column of the `<` character -- https://bugs.ruby-lang.org/