通过使用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!
显示所有空格,似乎所有返回的空格都被删除了,我想这就是我的代码没有的原因工作
任何人都知道如何添加空格以使代码正常工作?
答案 0 :(得分:0)
这可能是Sinatra评估ERB的方式的问题。通常你的代码会有空格,你必须使用类似<%= some code -%>
的东西来删除尾随空格(注意尾随的破折号)。在评估ERB时,Sinatra可能会更改默认trim_mode。不过,你必须在内部挖掘才能找到它。
答案 1 :(得分:0)
您是否在initializers / mime_types.rb中将vtt注册为mime类型?实际上,这是一个Rails文件,但我猜你必须为Sinatra做类似的事情。