-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_webpage_audio_with_root.erb
115 lines (105 loc) · 2.34 KB
/
generate_webpage_audio_with_root.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
require 'erb'
if ARGV.empty?
puts "You must add a filename"
exit
end
$filename = ARGV[0]
filename_word = $filename
filename_prs = "prs_#$filename"
filename_audio = "audio_#$filename"
filename_root = "root_#$filename"
title = File.basename($filename, ".txt")
template = %{
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title><%= title %></title>
</head>
<body>
<%
# read word from file
i = 0
$word = Array.new
File.open(filename_word, "r") do |file|
file.each_line{|line|
if line[0] == "#"
next
end
$word[i] = line.chomp
i = i+1
}
end
i = 0
$prs = Array.new
File.open(filename_prs, "r") do |file|
file.each_line{|line| $prs[i] = line.chomp
i = i+1
}
end
i = 0
root_index = 0;
$root = Array.new
File.open(filename_root, "r") do |file|
file.each_line{|line| $root[i] = line.chomp
i = i+1
}
end
i = 0
$audio = Array.new
File.open(filename_audio, "r") do |file|
file.each_line{|line| $audio[i] = line.chomp
i = i+1
}
end
%>
<% for ii in 0..i-1 %>
<% if ii % 4 == 0 and ii/4 < $root.length() and $root[root_index] != "Number Words" and $root[root_index] != "Medical Words" %>
<hr id='<%= $root[root_index] %>'>
<p><strong><%= $root[root_index] %></strong>
<hr>
<table>
<col width="250" />
<col width="250" />
<% end %>
<% if ii % 4 == 0 and ii/4 < $root.length() and ($root[root_index] == "Number Words" or $root[root_index] == "Medical Words") %>
<h2><%= $root[root_index] %></h2>
<% root_index += 1 %>
<hr id='<%= $root[root_index] %>'>
<p><strong><%= $root[root_index] %></strong>
<hr>
<table>
<col width="250" />
<col width="250" />
<% end %>
<% if $prs[ii] == "null" %>
<tr>
<td style="font-family:arial;color:black;font-size:30px;"><%= $word[ii] %></td>
</tr>
<% else %>
<tr>
<td style="font-family:arial;color:black;font-size:30px;"><%= $word[ii] %></td>
<td>[<%= $prs[ii] %>]</td>
<td>
<audio controls="controls">
<source src="audio/<%= $audio[ii] %>.mp3" type="audio/mpeg">Browser not support audio
</audio>
</td>
</tr>
<% end %>
<% if ii % 4 == 3 and ii/4 != ($root.length()-1) %>
<% root_index += 1 %>
</table>
<% end %>
<% end %>
</body>
</html>
}.gsub(/^ /, '')
rhtml = ERB.new(template)
aFile = File.new("#$filename.html", "w+")
if aFile
aFile.syswrite(rhtml.result(binding))
else
puts "Unable to open file!"
end
aFile.close