Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 371 lines (327 sloc) 8.373 kb
3c8edb4 Zachary Scott integrate feed
authored
1 require "builder"
2 require "data_mapper"
3 require "glorify"
edcd894 Zachary Scott haml layout
authored
4 require "haml"
f94b96a Zachary Scott initial commit
authored
5 require "httparty"
3c8edb4 Zachary Scott integrate feed
authored
6 require "json"
7 require "sass"
e64103f Zachary Scott reboot
authored
8 require "sinatra"
f94b96a Zachary Scott initial commit
authored
9
e64103f Zachary Scott reboot
authored
10 set :base_uri, 'http://github.com/api/v2/json'
ab5e7b0 Zachary Scott remove defaults, readme needs a rewrite
authored
11 set :ga_id, ENV['GA_ID']
12 set :ga_domain, ENV['GA_DOMAIN']
13 set :userid, ENV['GITHUB_USER']
14 set :repoid, ENV['GITHUB_REPO']
28bc967 Zachary Scott :public is no longer used to avoid overloading Module#public, use :publi...
authored
15 set :public_folder, File.dirname(__FILE__) + '/public'
e64103f Zachary Scott reboot
authored
16 set :views, File.dirname(__FILE__)
01cb60a Zachary Scott branching support closes #5
authored
17
3c8edb4 Zachary Scott integrate feed
authored
18 DataMapper.setup(:default, ENV['DATABASE_URL'])
19 class Post
20 include DataMapper::Resource
21 property :id, Serial
22 property :title, String
23 property :file, String
24 property :created_at, DateTime
25 validates_uniqueness_of :file, :title
26 end
27 DataMapper.finalize
28 Post.auto_upgrade!
29
8a75dce Zachary Scott replace dalli response cache with rack-cache cache_control
authored
30 configure :production do
31 sha1, date = `git log HEAD~1..HEAD --pretty=format:%h^%ci`.strip.split('^')
32
33 require 'rack/cache'
34 use Rack::Cache
35
36 before do
37 cache_control :public, :must_revalidate, :max_age=>300
38 etag sha1
39 last_modified date
bfc6d19 Zachary Scott switching rack dependency source from git to rubygems and modularizing t...
authored
40 end
8a75dce Zachary Scott replace dalli response cache with rack-cache cache_control
authored
41 end
42
0590c96 Zachary Scott switch markdown parser to redcarpet and add support for syntax highlight...
authored
43 helpers do
58e9e1f Zachary Scott map blobs to an index array and sort alphabetically
authored
44 def escape_uri text
45 return text.gsub('_',' ').gsub('.md', '')
46 end
3c8edb4 Zachary Scott integrate feed
authored
47
48 def request_file file
49 glorify(HTTParty.get("https://raw.github.com/#{settings.userid}/#{settings.repoid}/master/#{file}").to_s)
50 end
0590c96 Zachary Scott switch markdown parser to redcarpet and add support for syntax highlight...
authored
51 end
52
088d322 Zachary Scott move info and user requests to before block
authored
53 before do
8a75dce Zachary Scott replace dalli response cache with rack-cache cache_control
authored
54 @info = HTTParty.get("#{settings.base_uri}/repos/show/#{settings.userid}/#{settings.repoid}")
33f9f34 Zachary Scott fix homepage links, for rss too
authored
55 @info["repository"]["homepage"].chomp!('/') if @info["repository"]["homepage"][-1,1] == '/'
8a75dce Zachary Scott replace dalli response cache with rack-cache cache_control
authored
56 @user = HTTParty.get("#{settings.base_uri}/user/show/#{settings.userid}")
088d322 Zachary Scott move info and user requests to before block
authored
57 end
58
59 get '/' do
58e9e1f Zachary Scott map blobs to an index array and sort alphabetically
authored
60 @blobs = HTTParty.get("#{settings.base_uri}/blob/all/#{settings.userid}/#{settings.repoid}/master")["blobs"].map{|b|b[0]}.sort
e64103f Zachary Scott reboot
authored
61 haml :index
62 end
f94b96a Zachary Scott initial commit
authored
63
8ca2c91 Zachary Scott use raw api from master branch
authored
64 get '/show/:post' do
9394a14 Zachary Scott integrate glorify for syntax highlighting
authored
65 @post = glorify(HTTParty.get("https://raw.github.com/#{settings.userid}/#{settings.repoid}/master/#{params[:post]}").to_s)
8a75dce Zachary Scott replace dalli response cache with rack-cache cache_control
authored
66 @history = HTTParty.get("#{settings.base_uri}/commits/list/#{settings.userid}/#{settings.repoid}/master/#{params[:post]}").to_hash
e64103f Zachary Scott reboot
authored
67 haml :show
bfc6d19 Zachary Scott switching rack dependency source from git to rubygems and modularizing t...
authored
68 end
e64103f Zachary Scott reboot
authored
69
3c8edb4 Zachary Scott integrate feed
authored
70 get '/feed' do
71 @posts = Post.all(:order => [:id.desc], :limit => 20)
72 builder :feed, :layout => false
73 end
74
75 post '/feed/:token' do
76 push = JSON.parse(params[:payload])
77 push['commits'].each do |commit|
552375a Zachary Scott only create post if commit['added'] is not empty
authored
78 if commit['added'] && !commit['added'].empty?
3c8edb4 Zachary Scott integrate feed
authored
79 @post = Post.create(
80 :title => escape_uri(commit['added'].first),
81 :file => commit['added'].first,
82 :created_at => commit['timestamp']
83 ) if params[:token] == ENV['TOKEN']
84 end
85 end
86 end
87
91348e1 Zachary Scott add ga support and env's with default opts for myself
authored
88 get '/ga.js' do
89 haml :ga, :layout => false
90 end
91
e64103f Zachary Scott reboot
authored
92 get '/stylesheet.css' do
93 content_type 'text/css', :charset => 'utf-8'
94 sass :stylesheet
95 end
96
97 __END__
98
99 @@layout
100 !!!html
101 %html{:lang=>"en"}
102 %head
103 %meta{:charset=>"utf-8"}
104 %title
105 = "#{@info["repository"]["name"]} | #{@info["repository"]["description"]}"
106 %link{:rel=>"stylesheet", :href=>"/stylesheet.css", :type=>"text/css"}
0590c96 Zachary Scott switch markdown parser to redcarpet and add support for syntax highlight...
authored
107 %link{:rel=>"stylesheet", :href=>"/css/pygments.css", :type=>"text/css"}
3c8edb4 Zachary Scott integrate feed
authored
108 <link rel="alternate" type="application/rss+xml" title="RSS" href="/feed">
1d679b6 Zachary Scott add ga
authored
109 %script{:type=>"text/javascript", :src=>"/ga.js"}
e64103f Zachary Scott reboot
authored
110 %body
111 #header
112 = haml(:header, :layout=>false)
113 #content
114 #main
115 = yield
116 #sidebar
117 = haml(:sidebar, :layout=>false)
118 = haml(:footer, :layout=>false)
119
3c8edb4 Zachary Scott integrate feed
authored
120 @@feed
121 xml.instruct! :xml, :version => '1.0'
122 xml.rss :version => "2.0" do
123 xml.channel do
124 xml.title @info["repository"]["name"]
125 xml.description @info["repository"]["description"]
126 xml.link @info["repository"]["url"]
127
128 @posts.each do |post|
129 xml.item do
130 xml.title post.title
33f9f34 Zachary Scott fix homepage links, for rss too
authored
131 xml.link "#{@info["repository"]["homepage"]}/show/#{post.file}"
3c8edb4 Zachary Scott integrate feed
authored
132 xml.description request_file(post.file)
133 xml.pubDate Time.parse(post.created_at.to_s).rfc822()
33f9f34 Zachary Scott fix homepage links, for rss too
authored
134 xml.guid "#{@info["repository"]["homepage"]}/show/#{post.file}"
3c8edb4 Zachary Scott integrate feed
authored
135 end
136 end
137 end
138 end
e64103f Zachary Scott reboot
authored
139
140 @@index
4a2b8c2 Zachary Scott index page post list
authored
141 %ul.posts
142 - @blobs.each do |b|
143 %li
144 %h1
145 %a{:href=>"/show/#{b}"}= escape_uri b
e64103f Zachary Scott reboot
authored
146
147 @@header
148 %ul#blog_stats
149 %li
3c8edb4 Zachary Scott integrate feed
authored
150 %a{:href=>"/feed"}
7fdbdbb Zachary Scott use new icons
authored
151 %img{:src=>"/images/rss2.png"}
e64103f Zachary Scott reboot
authored
152 %li
153 %a{:href=>"https://github.com/#{settings.userid}/#{settings.repoid}/watchers"}
154 = @info["repository"]["watchers"]
155 %img{:src=>"/images/watchers.png"}
156 %li
157 %a{:href=>"https://github.com/#{settings.userid}/#{settings.repoid}/network"}
158 = @info["repository"]["forks"]
159 %img{:src=>"/images/forks.png"}
160
161 %h1
162 %a{:href=>"#{@info["repository"]["homepage"]}"}
163 = @info["repository"]["name"]
164 %p= @info["repository"]["description"]
165
166 @@footer
167 #footer
168 Official blog repo at
169 %a{:href=>"#{@info["repository"]["url"]}"}
170 github
171 Powered by
172 %a{:href=>"http://github.com/zzak/blarghhhh"}
173 blarghhhh
174
175 @@sidebar
176 %h1#username
177 = @user["user"]["name"]
178 %a{:href=>"http://github.com/#{settings.userid}/followers"}
7fdbdbb Zachary Scott use new icons
authored
179 %sup
180 = @user["user"]["followers_count"]
181 %img{:src=>"/images/watchers.png"}
e64103f Zachary Scott reboot
authored
182 %ul#user_stats
183 %li
294287d Zachary Scott darken font colors, link shadows, sidebar design
authored
184 %a{:href=>"mailto:#{@user["user"]["email"]}"}
185 mail
186 %br
187 %img{:src=>"/images/mail.png"}
e64103f Zachary Scott reboot
authored
188 %li
7fdbdbb Zachary Scott use new icons
authored
189 %a{:href=>"http://github.com/#{@user["user"]["login"]}"}
294287d Zachary Scott darken font colors, link shadows, sidebar design
authored
190 code
191 %br
7fdbdbb Zachary Scott use new icons
authored
192 %img{:src=>"/images/code.png"}
e64103f Zachary Scott reboot
authored
193 %li
294287d Zachary Scott darken font colors, link shadows, sidebar design
authored
194 %a{:href=>@user["user"]["blog"]}
195 home
196 %br
197 %img{:src=>"/images/home.png"}
198 %img#avatar{:src=>"http://www.gravatar.com/avatar/#{@user["user"]["gravatar_id"]}"}
e64103f Zachary Scott reboot
authored
199
200 @@show
201 #post_info
202 %h2 Author
203 %p#author_name
204 By
205 %a{:href=>"http://github.com/#{@history["commits"][0]["author"]["login"]}"}
206 = @history["commits"][0]["author"]["name"]
207 %h2 Last Update
208 %p#authored_date
c4e4ff7 Zachary Scott parse date first
authored
209 = Date.parse(@history["commits"][0]["authored_date"]).strftime("%A %B %d %Y at %I:%M%p")
e64103f Zachary Scott reboot
authored
210 %h2#history_button History
211 #history
212 - @history["commits"].each do |commit|
213 .commit
214 %p.commit_message= commit["message"]
c4e4ff7 Zachary Scott parse date first
authored
215 %p.commit_date= Date.parse(commit["authored_date"]).strftime("%A %B %d %Y at %I:%M%p")
e64103f Zachary Scott reboot
authored
216 #post
d419199 Zachary Scott HAML ~ to preserve whitespace
authored
217 ~ @post
e64103f Zachary Scott reboot
authored
218
91348e1 Zachary Scott add ga support and env's with default opts for myself
authored
219 @@ga
220 var _gaq = _gaq || [];
221 _gaq.push(['_setAccount', '#{settings.ga_id}']);
222 _gaq.push(['_setDomainName', '#{settings.ga_domain}']);
223 _gaq.push(['_trackPageview']);
224
225 (function() {
226 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
227 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
228 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
229 })();
230
e64103f Zachary Scott reboot
authored
231 @@stylesheet
232 *
233 margin: 0
234 padding: 0
235 border: 0
236 outline: 0
237
238 body
294287d Zachary Scott darken font colors, link shadows, sidebar design
authored
239 color: #000
d0f9299 Zachary Scott light
authored
240 background-color: #FFFFFF
e64103f Zachary Scott reboot
authored
241 font-family: "Lucida Grande", "Lucida Sans Unicode", "Garuda"
242
243 a:link, a:visited
d206c0f Zachary Scott post info and link styling
authored
244 color: #000000
e64103f Zachary Scott reboot
authored
245
246 a:hover, a:active
247 color: #8F8F8F
248
249 h1 a, h2 a
250 text-decoration: none
251
252 #header
253 clear: both
254 padding: 20px
255 min-height: 40px
256 h1
257 text-align: right
258 p
259 float: right
260 ul
261 list-style-type: none
262 #blog_stats
263 float: right
264 font-size: .8em
265 text-align: right
266 margin: 10px 0 0 15px
267 a
268 text-decoration: none
269
270 #content
271 clear: both
272 width: 98%
273 margin: 10px auto
274
275 #main
276 width: 80%
277 float: left
278 h1
279 line-height: 1.3em
280
281 #sidebar
282 margin-top: 100px
283 width: 19%
284 float: right
285 h1
286 font-size: 1.1em
287 text-align: right
288 sup
289 font-size: .8em
290 h2
291 font-size: 1em
292 text-align: right
293 ul
294 list-style-type: none
295 margin-left: 20px
296 #user_stats
294287d Zachary Scott darken font colors, link shadows, sidebar design
authored
297 text-align: center
298 line-height: 1em
299 clear: both
300 a
301 text-decoration: none
e64103f Zachary Scott reboot
authored
302 li
7fdbdbb Zachary Scott use new icons
authored
303 float: right
304 margin-right: 10px
e64103f Zachary Scott reboot
authored
305 #avatar
294287d Zachary Scott darken font colors, link shadows, sidebar design
authored
306 clear: both
307 text-align: right
7fdbdbb Zachary Scott use new icons
authored
308 #location
309 clear: both
e64103f Zachary Scott reboot
authored
310
311 .page_header
312 margin: 20px
313
4a2b8c2 Zachary Scott index page post list
authored
314 .posts
907ca8b Zachary Scott posts list width and centering
authored
315 width: 700px
316 margin: 0 auto
a3f2be6 Zachary Scott posts list style, link styles
authored
317 li
318 width: 210px
319 float: left
320 margin: 10px
321 list-style-type: none
322 h1
323 font-size: 1em
e64103f Zachary Scott reboot
authored
324
325 #post_info
326 float: right
327 width: 25%
d206c0f Zachary Scott post info and link styling
authored
328 background: #000000
e64103f Zachary Scott reboot
authored
329 padding: 20px
d206c0f Zachary Scott post info and link styling
authored
330 color: #FFFFFF
e64103f Zachary Scott reboot
authored
331 a:link, a:visited
d206c0f Zachary Scott post info and link styling
authored
332 color: #FFFFFF
e64103f Zachary Scott reboot
authored
333 a:hover, a:active
d206c0f Zachary Scott post info and link styling
authored
334 color: #8F8F8F
e64103f Zachary Scott reboot
authored
335 h2
336 text-align: right
d206c0f Zachary Scott post info and link styling
authored
337 color: #8F8F8F
e64103f Zachary Scott reboot
authored
338 #authored_date
339 font-size: 14px
340
341 #post
342 float: left
343 width: 68%
344 ul
345 list-style-position: inside
346 margin-left: 20px
347 p
348 line-height: 1.3em
349 margin: 10px 0px
350 pre
351 overflow: auto
352 overflow-Y: hidden
0590c96 Zachary Scott switch markdown parser to redcarpet and add support for syntax highlight...
authored
353 font-size: 1.1em
e64103f Zachary Scott reboot
authored
354
355 #history_button
356 cursor: pointer
357
358 #history
359 line-height: 17px
360 .commit
361 margin-bottom: 10px
362 .commit_date
363 font-size: 12px
d206c0f Zachary Scott post info and link styling
authored
364 color: #9F9F9F
e64103f Zachary Scott reboot
authored
365
366 #footer
367 clear: both
368 text-align: center
369 font-size: .8em
370
Something went wrong with that request. Please try again.