渲染时可以使ERB适当缩进吗? [英] Can you get ERB to properly indent when rendered?

查看:70
本文介绍了渲染时可以使ERB适当缩进吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Rails application.html.erb file中包含了多个部分,但是生成的HTML并没有保留我的缩进(格式).有人告诉我,第一行的缩进级别与调用_partial.html.erb时相同,但部分中的所有后续行都将左对齐.

I have several partials that I'm including in my Rails application.html.erb file, but the resulting HTML doesn't preserve my indenting (formatting). I've been told that the first line gets rendered with the same indentation-level as the call to _partial.html.erb, but all subsequent lines in the partial just get left-aligned.

这会产生类似以下的代码(请参阅我的评论以了解定位信息):

This results in code like (see my comments for positioning):

<body>
    <div id="outer">

        <div class="contentwidth main">
            <div class="logo"> <<<<< Shouldn't be this far to the right
    <h1><a href="index.html">minimal.</a></h1>
</div><!-- end logo -->     <<<<<<< Shouldn't be way over to the left

是否有任何方法可以使用ERB更好地解决此问题/格式化我包含的部分内容?还是我需要使用HAML?

Is there any way to fix this/format my included partials better using ERB? Or do I need to use HAML?

推荐答案

doc在过滤器上包含一个示例,该示例使用after过滤器在将html发送到浏览器之前先对其进行压缩.

The doc on filters contains an example of using an after filter to compress the html before sending it to the browser.

做类似的事情,但是使用类似 Tidy 的格式来重新格式化并替换此示例所用的html压缩可以解决问题.

Doing something similar, but using something like Tidy to reformat and replace the html where this example does a compress might do the trick.

这篇关于渲染时可以使ERB适当缩进吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆