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.1 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 ECAAD1F62E for ; Tue, 15 Jan 2019 13:35:20 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id CB1EB12158F; Tue, 15 Jan 2019 22:35:16 +0900 (JST) Received: from o1678916x28.outbound-mail.sendgrid.net (o1678916x28.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 005CC121565 for ; Tue, 15 Jan 2019 22:35:13 +0900 (JST) Received: by filter0114p3las1.sendgrid.net with SMTP id filter0114p3las1-23378-5C3DE18E-3D 2019-01-15 13:35:10.801966641 +0000 UTC m=+57454.850450027 Received: from herokuapp.com (ec2-54-92-132-214.compute-1.amazonaws.com [54.92.132.214]) by ismtpd0033p1iad2.sendgrid.net (SG) with ESMTP id SxQ5Pf1QRyOKVIeIFE1Y_Q for ; Tue, 15 Jan 2019 13:35:10.749 +0000 (UTC) Date: Tue, 15 Jan 2019 13:35:12 +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: 66554 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS7nRD+4sKoILYVY9hNXldxN2C1NMK6MuIgn3R 09E4YH1QYCr1TmjH2I9YawPlZK5BT4pKYrUpP+Dq0JHwiSA53n2C8XqFTcl+wgUsTTnZcHtzEkmeBv 9CurntNFNFUzv9knc0gaJopCa/SVqT7j5tXrAM89cGzm0vzhCMGEr0MEvQ== X-ML-Name: ruby-core X-Mail-Count: 91103 Subject: [ruby-core:91103] [Ruby trunk Feature#15538] Erb indenting / unindenting trim mode 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 reported by kke (Kimmo Lehto). ---------------------------------------- Feature #15538: Erb indenting / unindenting trim mode https://bugs.ruby-lang.org/issues/15538 * Author: kke (Kimmo Lehto) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- In `Erb`, would it be possible to add a new trim mode that would indent the following content to match the depth of the tag? The tag could for example be `<%|` and it would be enabled using `Erb.new(template, trim_mode: '|')` ## Reason Something like this looks nice: ``` ruby - horse <% ['cat', 'dog', 'goldfish'].each do |pet| %> <% unless pet == 'goldfish' %> - <%= pet %> <% end %> <% end %> ``` But unfortunately it will render with "extra" indentation: ``` - horse - cat - dog ``` With the `|` trim mode it could be written as: ```ruby - horse <%| ['cat', 'dog', 'goldfish'].each do |pet| %> .... <% end %> ``` And it would output as desired without the "extra" indentation. Currently, to produce such output, you have write your erb template without indentation or using a jumpy mixed indentation (code and content have different indentation levels but are interleaved) and it's not a very user/editor friendly way to work. ## Using with `=` It would also be handy if the `|` could be used with `<%=`, perhaps `<%|=`, this would be excellent for example when templating YAML's: ```yaml <% bar_content = "- something\n- something else" %> foo: bar: <%|= bar_content %> ``` Which would produce something like: ```yaml foo: bar: - something - something else ``` Instead of the invalid: ```yaml foo: bar: - something - something else ``` Currently there's no way to accomplish this without manually counting the leading spaces, as it's not possible to detect the column where `<%=` appeared. -- https://bugs.ruby-lang.org/