修身模板 - 删除块标记周围的空格 [英] Slim templates - removing whitespaces around the block tag

查看:135
本文介绍了修身模板 - 删除块标记周围的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试一个新项目中的Slim模板(在使用Haml很长一段时间之后)。尽管整体体验非常好,但我遇到了一个问题,空间总是插在通常使用 display:block



说,

  ul.ampm 
li.am am
li.pm pm

生成

 < ul class =ampm> 
< li class =am>
am
< / li>
< li class =pm>
pm
< / li>
< / ul>

同时

  .ampm 
span.am am
span.pm pm

产生

 < div class =ampm> 
< span class =am> am< / span>< / span class =pm> pm< / span>
< / div>

通常情况下这不是一个大问题,但我们使用响应式布局,其中应用显示:inline-block li 标签;显然,在它们之间留有空白会破坏布局。



我知道

  Slim :: Engine.options [:pretty] = true 

on会删除有问题的空白),但它会使所有生成的源代码难以阅读,而不仅仅是我想要修复的部分。



Slim中的< > 似乎与我需要的相反 - 它们旨在用于在内联标签周围添加空白。

因此...


  • 是否可以删除围绕Slim中的单块标签类似于HAML空白食用者? (如果没有关闭漂亮选项的影响,那就是)如果不是,那么它是一个基本的Slim限制(按设计),或者是在路线图上的并且是未来有可能实施?



非常感谢。

解决方案

我通过在关键位置恢复为内联HTML 来解决此问题。对我来说,它是为 select 添加选项的集合:

  select 
- my_collection.each do | item |
< option value =#{item.id}>#{item.name}< / option>

在少数情况下,我可以忍受这一点(它对我来说很重要) 选项元素)。但是如果你需要在整个代码中使用更好的空格,我认为你运气不好。


是一个基本的Slim限制(by设计)或路线图上的内容,并将在未来实施?

我将与没有这两者。看起来Slim团队只是实现了一种天真的算法,并没有回头。例如,来自GitHub问题跟踪器的这段引语:


漂亮的渲染器在某些情况下效果不佳,因为Slim的重点在于性能。如果您有时间,请为神庙项目的漂亮渲染器提供补丁 https://github.com/judofyr/temple 并提供测试用例。


I'm trying Slim templates in a new project (after using Haml for quite a while). While overall experience is great, I've run into a problem with spaces being always inserted around tags which normally use display: block

Say,

ul.ampm
  li.am am
  li.pm pm

generates

<ul class="ampm">
  <li class="am">
    am
  </li>
  <li class="pm">
    pm
  </li>
</ul>

while

.ampm
  span.am am
  span.pm pm

generates

<div class="ampm">
  <span class="am">am</span></span class="pm">pm</span>
</div>

Normally it's not a big issue, but we use responsive layouts which applies display: inline-block to li tags; obviously, having whitespace between them breaks the layout.

I'm aware of

Slim::Engine.options[:pretty] = true

option (and turning it on does remove the offending whitespace), but it makes all generated source hard to read, not just the part I'd like to fix.

< and > in Slim seem to do the opposite to what I need - they're intended to be used for adding whitespace around inline tags.

So...

  • is it possible to remove whitespace around a single block tag in Slim similar to HAML whitespace eaters? (Without the impact of turning off the pretty option, that is)
  • if not, is it a fundamental Slim restriction ("by design") or something which is on the roadmap and would be potentially implemented in the future?

Much appreciated.

解决方案

I worked around this by reverting back to inline HTML in the critical places. For me, it was adding a collection of options to a select:

select
  - my_collection.each do |item|
  <option value="#{item.id}">#{item.name}</option>

I can put up with this in the few cases where it really matters (as it did for me in the option elements). But if you need better whitespacing throughout your code, I think you're out of luck.

is it a fundamental Slim restriction ("by design") or something which is on the roadmap and would be potentially implemented in the future?

I'm going to go with "no" for both of those. It looks like the Slim team just implemented a naive algorithm and didn't look back. Case in point, this quote from the GitHub issue tracker:

The pretty renderer is not working well under some circumstances since Slim's focus lies on performance. If you have time please provide patches for the pretty renderer of the temple project https://github.com/judofyr/temple and also provide test cases.

这篇关于修身模板 - 删除块标记周围的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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