Skip to content

Commit

Permalink
Merge remote-tracking branch 'melancholyfleur/master' into rss
Browse files Browse the repository at this point in the history
Conflicts:
	config/routes.rb
  • Loading branch information
steveklabnik committed Mar 6, 2012
2 parents 87bebf7 + ac121f7 commit d4b6ac3
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/controllers/questions_controller.rb
Expand Up @@ -10,6 +10,7 @@ def create
end

def show
@title = "Questions"
@answer = Answer.new
show!
end
Expand Down Expand Up @@ -65,4 +66,18 @@ def set_presenter
end
end

def feed
@title = "Questions Feed"

@questions = Question.all(:select => "title, description, solution_id, created_at", :order => "created_at DESC", :limit => 20) unless @support

@updated = @questions.first.updated_at unless @questions.empty?

respond_to do |format|
format.html
format.atom
format.xml { render :xml => @questions }
end
end

end
3 changes: 3 additions & 0 deletions app/views/layouts/application.html.haml
Expand Up @@ -2,6 +2,9 @@
!!!
%html
%head
= auto_discovery_link_tag :atom, feed_path
= auto_discovery_link_tag :rss, feed_path

- title = yield :title
%title #{title.blank? ? "" : "#{title} | "}Hackety Hack!

Expand Down
17 changes: 17 additions & 0 deletions app/views/questions/feed.atom.builder
@@ -0,0 +1,17 @@
atom_feed :language => 'en-US' do |feed|
feed.title @title
feed.updated @updated

@questions.each do |item|
next if item.created_at.blank?

feed.entry item do |entry|
entry.url questions_url(item)
entry.title item.title
entry.content item.description, :type => 'html'
entry.updated(item.created_at.strftime("%Y-%m-%dT%H:%M:%SZ"))
entry.author item.user
end
end
end

1 change: 1 addition & 0 deletions app/views/questions/index.html.haml
Expand Up @@ -10,6 +10,7 @@
= render :partial => "shared/questions_blurb"
- else
= render :partial => "shared/support_blurb"
= render :partial => "shared/atom_blurb"

%ul.questions
= render :partial => "list", :collection => collection
Expand Down
4 changes: 4 additions & 0 deletions app/views/shared/_atom_blurb.html.haml
@@ -0,0 +1,4 @@
%section.support
%p Subscribe to the #{link_to "Questions Atom Feed", feed_path}.


1 change: 1 addition & 0 deletions app/views/shared/_support_blurb.html.haml
@@ -1,3 +1,4 @@
%section.support
%h2 Support
%p Having a problem running Hackety Hack? Found a bug? Check out the #{link_to "support section", support_questions_path}

6 changes: 6 additions & 0 deletions config/routes.rb
Expand Up @@ -2,6 +2,12 @@

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

resources :questions do
match '/feed' => 'questions#feed',
:as => :feed,
:defaults => { :format => 'atom' }
end

resources :questions do
resources :answers
end
Expand Down
17 changes: 17 additions & 0 deletions controllers/admin.rb
@@ -0,0 +1,17 @@
#This is the 'admins' controller

# Show how many users there are
get '/admin' do
admin_only!
#get usercount
@usercount = Hacker.all.length
today = Date.today
@newusers = Hacker.all(:created_at => {'$gt' => today.to_time, '$lt' => (today + 1.day).to_time}).length
@newusernames = Hacker.all(:created_at => {'$gt' => today.to_time, '$lt' => (today + 1.day).to_time})
@forumposts = Discussion.all(:created_at => {'$gt' => today.to_time, '$lt' => (today + 1.day).to_time}).length
@postlinks = Discussion.all(:created_at => {'$gt' => today.to_time, '$lt' => (today + 1.day).to_time})
@forumreplies = Discussion.all(:updated_at => {'$gt' => today.to_time, '$lt' => (today + 1.day).to_time}).length

haml :"admin/index"
end

2 changes: 2 additions & 0 deletions features/admin.feature
@@ -0,0 +1,2 @@
Feature: Admin functionality
Scenario: Admin page
24 changes: 24 additions & 0 deletions views/admin/index.haml
@@ -0,0 +1,24 @@
%h1= current_user.username + "'s admin page"
%img{:src => current_user.gravatar_url}

%p Total Hacker Count: #{@usercount}

%p New Users Today: #{@newusers}
%ul
- @newusernames.each do |name|
%li
%a{:href => "/hackers/#{name.username}"}= name.username

%p New Forum Discussions: #{@forumposts}
%ul
- @postlinks.each do |postlink|
%li
%a{:href => "/forums/#{postlink.forum}/#{postlink.slug}"}= postlink.title

%p New Forum Replies: #{@forumreplies}
%ul
- @postlinks.each do |replylink|
%li
%a{:href => "/forums/#{replylink.forum}/#{replylink.slug}"}= replylink.slug


0 comments on commit d4b6ac3

Please sign in to comment.