嵌入在Haml布局中的ERB视图:现在如何处理空白? [英] ERB view embedded in a Haml layout: what to do about whitespace now?

查看:49
本文介绍了嵌入在Haml布局中的ERB视图:现在如何处理空白?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Rails 3应用程序,所有视图均在Haml中完成。但是,有些视图来自ERB中必需的gem,而Haml正在添加空白,并且搞乱了textareas等。 (如果您不熟悉haml的这方面,请在此处查看。)

I have a Rails 3 app where the views are all done in Haml. However, there are some views coming from a required gems that are in ERB, and Haml is adding whitespace, and it's messing up textareas and such. (If you're not familiar with this aspect of haml, look here.)

我宁愿不必将布局转换为ERB,而且因为宝石位于ERB中,所以所有传统的Haml空白解决方案都不会

I'd rather not have to convert my layout to ERB, and because the gem is in ERB, all of the traditional Haml whitespace solutions don't help.

那么我如何使我的文本区域(和< pre> s等)不被包装?我可以在自己的应用中执行的任何智能操作都很好,否则我很乐意为原始gem应用补丁。

So how do I get my textareas (and <pre>s etc) not to wrap? Anything smart I can do in my app is good, otherwise I'd be happy to apply a patch to the original gem.

编辑,我想我可能已经找到了一些不错的答案。

Edit I think I might have figured out a few decent answers.

在haml端起作用的一件事是 Haml :: Template.options [:ugly] = true ,可消除所有空格。嗯,这可能是最好的解决方案,但是我的空白在哪里:(我喜欢它,当它不会弄乱我的应用程序时。

One thing that works on the haml end is Haml::Template.options[:ugly] = true, which eliminates all whitespace. Meh, this might be the best solution, but where's my whitespace :( I liked it, when it wasn't messing up my app.

另一个想法是修补gem可以在before_save中自动将\n个字符转换为&#x000A;,它模仿了Haml在我原始问题中链接的链接中所做的事情……但这可能有点麻烦。

Another idea was to patch the gem to automatically convert \n characters to &#x000A; in a before_save, which mimics what Haml does in the link i linked to in my original question... but that might be a bit of a pain.

我想出的最终解决方案(似乎也可行)是创建一个_form.html.haml文档,该文档位于插件中_form.html.erb文档的旁边,并且是相同的。显然,该插件不需要依赖Haml,但是如果父应用正在渲染Haml,则在寻找ERB视图之前,它将先寻找haml视图。那就是Haml实际上需要在应用程序的开头加载。因此,我现在在application.rb的底部一行仅显示了 Haml。

The final solution I came up with, which also seems to work, is to create a _form.html.haml document that sits right next to the _form.html.erb document in the plugin, and is identical. Apparently, the plugin doesn't need to depend on Haml, but if the parent app is rendering Haml, it'll look for a haml view before it looks for an ERB view. There's one caveat, though, and that's that Haml actually needs to be loaded at the beginning of the app. So I have a line at the bottom of application.rb now that just says 'Haml' all by itself.

所以对于其他有此问题的人,现在您有3种解决方案ck,如果您有更好的产品,请发布!

So for anybody else having this problem, now you've got 3 solutions to pick from, and if you've got a better one, please post it!

推荐答案

您是否看过:preserve过滤器?

Have you looked at the :preserve filter?

请参见 http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#preserve-filter

这篇关于嵌入在Haml布局中的ERB视图:现在如何处理空白?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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