-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate_index.html.rb
141 lines (124 loc) · 4.37 KB
/
generate_index.html.rb
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
class GenerateIndex
include RailsCastsCommon
def filelists(dir)
Dir.entries("./railscasts/#{dir}").sort{|x,y| y.split("-")[0] <=> x.split("-")[0] }
end
EpisodeTypes = %w{pro revised free}
MainUrl = SubscriptionCode::TARGET_URL
def stylesheets(style)
case style
when :default
%{
<link href="/stylesheets/bootstrap.css" media="screen" rel="stylesheet" type="text/css" />
}.to_s
when :ascii
%{
<link href="/stylesheets/coderay.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
}.to_s
end
end
def head(style_attr=:default,title="", title_link="")
%{<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Rails Casts Episodes (cached) #{title} - DO NOT DISTRIBUTE</title>
<link rel="alternate" type="application/rss+xml" title="RSS" href="index.xml" />
#{stylesheets(style_attr)}
<style>
body {
margin: 0px;
padding-left: 40px;
}
</style>
</head>
<body>
<img src="/railscasts/railscasts_logo.png" >
<h1>#{title}<a href="index.xml"><img src='/railscasts/feed-icon.png'></a></h1>#{title_link}<br />
}.to_s
end
def footer
%{</body></html>}.to_s
end
def rss_item(title,rel_link)
%{
<item>
<title>#{title}</title>
<description>Video of #{title}</description>
<link>#{MainUrl}#{rel_link}</link>
<pubDate>Tue, 31 Jan 2012 09:00:00 -0400</pubDate>
<enclosure url="#{MainUrl}#{rel_link}" length="1010698" type="video/mpeg"/>
<guid isPermaLink="false">http://tuts.local.crypsis.net/railscasts/#{rel_link}</guid>
</item>
}
end
def make_rss_main(items)
%{<rss version="2.0">
<channel>
<title>Rails Casts (Crypsis)</title>
<description> Cached videos of Rails Casts </description>
<link>#{MainUrl}</link>
<lastBuildDate>Mon, 30 Jan 2012 11:12:55 -0400</lastBuildDate>
<pubDate>Tue, 31 Jan 2012 09:00:00 -0400</pubDate>
#{items}
</channel>
</rss>
}
end
def print_nav(types = EpisodeTypes)
out = ""
out << "<h2>"
types.each do |type|
out << %{<a href="##{type}">#{type.to_s.capitalize}</a> }
out << %{<a href="#{type}/index.xml"><img src='/railscasts/feed-icon-small.png'></a> }
end
out << "</h2>"
out
end
def print_episodes(types = EpisodeTypes,relative_path="")
out = ""
rss = ""
types.each do |type|
filelist = filelists(type)
out << %{<h1><a name="#{type}">#{type.to_s.capitalize}</a> </h1>}
filelist.each do |link|
if link.reverse.split(".")[0] == "4pm"
out << "<div class='row'>"
episode_name = link.to_s.split(".")[0].gsub("-"," ").capitalize
out << %{<a class="btn span4" href="#{relative_path}#{type}/#{link}">#{episode_name}</a>}
htmlfile = link.to_s.split(".")[0]+".html"
ascii = "asciicasts/"+ htmlfile
out << %{<a class="btn offset1 span2" href="#{relative_path}#{type}/#{ascii}">Read Episode</a>} if File.exists?("./railscasts/#{type}/raw/#{htmlfile}")
out << "</div>" + "<br>"*2
rss << rss_item("#{type} - #{episode_name}","#{type}/#{link}")
end
end
out << "<br>"*3
end
[out,rss]
end
def process
eps = print_episodes
open("railscasts/index.html","w+").write(head+print_nav+eps[0]+footer)
open("railscasts/index.xml","w+").write(make_rss_main(eps[1]))
EpisodeTypes.each do |type|
rel_path = "../"
eps = print_episodes([type],rel_path)
open("railscasts/#{type}/index.html","w+").write(head+eps[0]+footer)
open("railscasts/#{type}/index.xml","w+").write(make_rss_main(eps[1]))
filelists(type).each do |ep|
next unless ep.reverse.split(".")[0] == "4pm"
htmlfile = ep.to_s.split(".")[0]+".html"
ascii = "asciicasts/"+ htmlfile
raw = "raw/"+ htmlfile
watch_ep = %{<a class="btn" href="#{rel_path}#{ep}">Watch Episode</a>}
if File.exists?("railscasts/#{type}/#{raw}")
open("railscasts/#{type}/#{ascii}","w+") do |asci|
asci.write( head(:ascii, ep.split(".")[0].split(".")[0].gsub("-"," ").capitalize, watch_ep)+open("railscasts/#{type}/#{raw}").read+footer )
end
end
end
end
end
end