#encoding:utf-8
#! /usr/local/bin/ruby
require "sinatra"
require "haml"
Encoding.default_internal = Encoding.default_external = "UTF-8"
get "/*" do
haml :index
end
post '/' do
@track_in = params[:track_in]
@track_out = out(@track_in)
haml :index
end
def out(trackin)
if trackin != nil
track = trackin.lines.to_a
for i in 0 .. track.size
if track[i] != nil
tr = track[i].chomp.split(/\s\t/)
n,r,k = tr[0],tr[1],tr[2]
t = "#{n}.#{k}(#{r})" if k != nil
t = "#{n}.#{r}" if k == nil or track[i] == /([0-9]{2})\s\t(.+)\r/
puts "#{t}\n"
end
end
end
end
__END__
@@ index
!!!
%html
%head
%meta#_moz_html_fragment/
%title
%body
#main_wrapper
#page
#editing_header
.clear
#preview{style: "border: 5px solid rgb(204, 204, 204); margin: 1em 0pt; padding: 5px; background: rgb(255, 255, 255) none repeat scroll 0% 50%; display: none; width: 75%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"}
%form#form{action: "", method: "post"}
%table{border: "0", cellpadding: "0", cellspacing: "0", style: "width: 0:px;"}
%thead
%tbody
%input{name: "Submit", type: "submit"}/
%textarea#track_in{cols: "100", rows: "15", name: "track_in"}= @track_in
%textarea#track_out{cols: "100", rows: "15", name: "track_out"}= @track_out
输出 http://i.stack.imgur.com/nhplC.jpg 想要的结果 http://i.stack.imgur.com/T0xtJ.jpg
转换曲目列表。将点放在正确的位置,括号内的文本并按特定顺序
请帮帮我