如何在ERB模板中输入回车空格?
通过使用 sinatra,我想生成一个 webVTT,它考虑了空格,以制作一个相同的返回文件,例如:
WEBVTT
1
00:00:22.865 --> 00:00:30.413
Now we are gonna focus on the hihats, and this is where you actually get to hold these sticks. And
2
00:00:30.416 --> 00:00:37.745
I play matched grip which is where your both the sticks are held in the same way, a lot of people called traditional grip,
我编写了以下代码,迭代从 json 转换的哈希对象:
WEBVTT
<% @sub_json['data'].each_with_index do |value, index|%>
<%= index+1 %>
<%= value['start'].to_time %>--><%= value['end'].to_time%>
<%= value['en'] %>
<%= %>
<% end %>
结果不起作用,我粘贴从浏览器向vim发出请求并使用 set list!
显示所有空格,似乎所有返回空格都被删除,我想这就是我的代码不起作用的原因
任何人都知道如何添加空格到使代码工作?
by using sinatra and I want generate a webVTT, which take the whitespaces into account, to make a identical return file like:
WEBVTT
1
00:00:22.865 --> 00:00:30.413
Now we are gonna focus on the hihats, and this is where you actually get to hold these sticks. And
2
00:00:30.416 --> 00:00:37.745
I play matched grip which is where your both the sticks are held in the same way, a lot of people called traditional grip,
I made the following code, with iterate a hash object converted from json:
WEBVTT
<% @sub_json['data'].each_with_index do |value, index|%>
<%= index+1 %>
<%= value['start'].to_time %>--><%= value['end'].to_time%>
<%= value['en'] %>
<%= %>
<% end %>
the result doesn't work, I paste the request from browser to vim and use set list!
to show all the whitespaces, it seems all the return whitespaces are removed, I guess this is the reason that my code doesn't work
anyone know how to add whitespaces to make the code working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是 Sinatra 评估 ERB 的方式存在问题。通常,您的代码中会有空格,并且您必须使用类似
<%= some code -%>
的内容来删除尾随空格(请注意尾随破折号)。 Sinatra 可能会更改默认的 trim_mode< /a> 评估 ERB 时。不过,你必须深入挖掘内部结构才能找到答案。This might be a problem with the way Sinatra is evaluating the ERB. Normally your code would have the whitespaces there, and you would have to use something like
<%= some code -%>
to remove trailing whitespace (notice the trailing dash). Sinatra may change the default trim_mode when evaluating the ERB. You'd have to dig around in the internals to find that out, though.您是否在initializers/mime_types.rb中将vtt注册为mime类型?实际上,这是一个 Rails 文件,但我猜你必须为 Sinatra 做类似的事情。
Did you register vtt as a mime type in initializers/mime_types.rb? Actually, that's a Rails file, but I'd guess you have to do something similar for Sinatra.