Skip to content

Commit d4b6ac3

Browse files
committed
Merge remote-tracking branch 'melancholyfleur/master' into rss
Conflicts: config/routes.rb
2 parents 87bebf7 + ac121f7 commit d4b6ac3

10 files changed

Lines changed: 90 additions & 0 deletions

File tree

app/controllers/questions_controller.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def create
1010
end
1111

1212
def show
13+
@title = "Questions"
1314
@answer = Answer.new
1415
show!
1516
end
@@ -65,4 +66,18 @@ def set_presenter
6566
end
6667
end
6768

69+
def feed
70+
@title = "Questions Feed"
71+
72+
@questions = Question.all(:select => "title, description, solution_id, created_at", :order => "created_at DESC", :limit => 20) unless @support
73+
74+
@updated = @questions.first.updated_at unless @questions.empty?
75+
76+
respond_to do |format|
77+
format.html
78+
format.atom
79+
format.xml { render :xml => @questions }
80+
end
81+
end
82+
6883
end

app/views/layouts/application.html.haml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
!!!
33
%html
44
%head
5+
= auto_discovery_link_tag :atom, feed_path
6+
= auto_discovery_link_tag :rss, feed_path
7+
58
- title = yield :title
69
%title #{title.blank? ? "" : "#{title} | "}Hackety Hack!
710

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
atom_feed :language => 'en-US' do |feed|
2+
feed.title @title
3+
feed.updated @updated
4+
5+
@questions.each do |item|
6+
next if item.created_at.blank?
7+
8+
feed.entry item do |entry|
9+
entry.url questions_url(item)
10+
entry.title item.title
11+
entry.content item.description, :type => 'html'
12+
entry.updated(item.created_at.strftime("%Y-%m-%dT%H:%M:%SZ"))
13+
entry.author item.user
14+
end
15+
end
16+
end
17+

app/views/questions/index.html.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
= render :partial => "shared/questions_blurb"
1111
- else
1212
= render :partial => "shared/support_blurb"
13+
= render :partial => "shared/atom_blurb"
1314

1415
%ul.questions
1516
= render :partial => "list", :collection => collection
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
%section.support
2+
%p Subscribe to the #{link_to "Questions Atom Feed", feed_path}.
3+
4+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
%section.support
22
%h2 Support
33
%p Having a problem running Hackety Hack? Found a bug? Check out the #{link_to "support section", support_questions_path}
4+

config/routes.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
resources :lessons, :only => [:index, :show]
44

5+
resources :questions do
6+
match '/feed' => 'questions#feed',
7+
:as => :feed,
8+
:defaults => { :format => 'atom' }
9+
end
10+
511
resources :questions do
612
resources :answers
713
end

controllers/admin.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#This is the 'admins' controller
2+
3+
# Show how many users there are
4+
get '/admin' do
5+
admin_only!
6+
#get usercount
7+
@usercount = Hacker.all.length
8+
today = Date.today
9+
@newusers = Hacker.all(:created_at => {'$gt' => today.to_time, '$lt' => (today + 1.day).to_time}).length
10+
@newusernames = Hacker.all(:created_at => {'$gt' => today.to_time, '$lt' => (today + 1.day).to_time})
11+
@forumposts = Discussion.all(:created_at => {'$gt' => today.to_time, '$lt' => (today + 1.day).to_time}).length
12+
@postlinks = Discussion.all(:created_at => {'$gt' => today.to_time, '$lt' => (today + 1.day).to_time})
13+
@forumreplies = Discussion.all(:updated_at => {'$gt' => today.to_time, '$lt' => (today + 1.day).to_time}).length
14+
15+
haml :"admin/index"
16+
end
17+

features/admin.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Feature: Admin functionality
2+
Scenario: Admin page

views/admin/index.haml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
%h1= current_user.username + "'s admin page"
2+
%img{:src => current_user.gravatar_url}
3+
4+
%p Total Hacker Count: #{@usercount}
5+
6+
%p New Users Today: #{@newusers}
7+
%ul
8+
- @newusernames.each do |name|
9+
%li
10+
%a{:href => "/hackers/#{name.username}"}= name.username
11+
12+
%p New Forum Discussions: #{@forumposts}
13+
%ul
14+
- @postlinks.each do |postlink|
15+
%li
16+
%a{:href => "/forums/#{postlink.forum}/#{postlink.slug}"}= postlink.title
17+
18+
%p New Forum Replies: #{@forumreplies}
19+
%ul
20+
- @postlinks.each do |replylink|
21+
%li
22+
%a{:href => "/forums/#{replylink.forum}/#{replylink.slug}"}= replylink.slug
23+
24+

0 commit comments

Comments
 (0)