forked from lobsters/lobsters
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
114 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,50 @@ | ||
class HomeController < ApplicationController | ||
def index | ||
conds = [ "is_expired = 0 " ] | ||
@stories = find_stories_for_user_and_tag_and_newest(@user, nil, false) | ||
|
||
if @user && !@newest | ||
# exclude downvoted items | ||
conds[0] << "AND stories.id NOT IN (SELECT story_id FROM votes " << | ||
"WHERE user_id = ? AND vote < 0) " | ||
conds.push @user.id | ||
end | ||
@rss_link ||= "<link rel=\"alternate\" type=\"application/rss+xml\" " << | ||
"title=\"RSS 2.0\" href=\"/rss\" />" | ||
|
||
if @tag | ||
conds[0] << "AND taggings.tag_id = ?" | ||
conds.push @tag.id | ||
@stories = Story.find(:all, :conditions => conds, | ||
:include => [ :user, :taggings ], :joins => [ :user, :taggings ], | ||
:limit => 30) | ||
|
||
@title = @tag.description.blank?? @tag.tag : @tag.description | ||
@title_url = tag_url(@tag.tag) | ||
else | ||
@stories = Story.find(:all, :conditions => conds, | ||
:include => [ :user, :taggings ], :joins => [ :user ], | ||
:limit => 30) | ||
respond_to do |format| | ||
format.html { render :action => "index" } | ||
format.rss { render :action => "rss", :layout => false } | ||
end | ||
end | ||
|
||
if @user | ||
votes = Vote.votes_by_user_for_stories_hash(@user.id, | ||
@stories.map{|s| s.id }) | ||
def newest | ||
@stories = find_stories_for_user_and_tag_and_newest(@user, nil, true) | ||
|
||
@stories.each do |s| | ||
if votes[s.id] | ||
s.vote = votes[s.id] | ||
end | ||
end | ||
end | ||
@page_title = "Newest Stories" | ||
|
||
if @newest | ||
# TODO: better algorithm here | ||
@stories.sort_by!{|s| s.created_at }.reverse! | ||
else | ||
@stories.sort_by!{|s| s.hotness } | ||
end | ||
@rss_link = "<link rel=\"alternate\" type=\"application/rss+xml\" " << | ||
"title=\"RSS 2.0 - Newest Items\" href=\"/newest.rss\" />" | ||
|
||
render :action => "index" | ||
end | ||
@title = "Newest Stories" | ||
@title_url = "/newest" | ||
|
||
def newest | ||
@newest = true | ||
index | ||
respond_to do |format| | ||
format.html { render :action => "index" } | ||
format.rss { render :action => "rss", :layout => false } | ||
end | ||
end | ||
|
||
def tagged | ||
if !(@tag = Tag.find_by_tag(params[:tag])) | ||
raise ActionController::RoutingError.new("tag not found") | ||
end | ||
@tag = Tag.find_by_tag!(params[:tag]) | ||
@stories = find_stories_for_user_and_tag_and_newest(@user, @tag, false) | ||
|
||
@page_title = @tag.description | ||
|
||
index | ||
@rss_link = "<link rel=\"alternate\" type=\"application/rss+xml\" " << | ||
"title=\"RSS 2.0 - Tagged #{CGI.escape(@tag.tag)} " << | ||
"(#{CGI.escape(@tag.description)})\" href=\"/t/" + | ||
"#{CGI.escape(@tag.tag)}.rss\" />" | ||
|
||
@title = @tag.description.blank?? @tag.tag : @tag.description | ||
@title_url = tag_url(@tag.tag) | ||
|
||
respond_to do |format| | ||
format.html { render :action => "index" } | ||
format.rss { render :action => "rss", :layout => false } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<% coder = HTMLEntities.new %> | ||
<rss version="2.0"> | ||
<channel> | ||
<title>lobste.rs<%= @page_title ? ": " + h(@page_title) : "" %></title> | ||
<description><%= @page_title %></description> | ||
<link>http://lobste.rs/<%= @newest ? "newest" : "" %></link> | ||
|
||
<% @stories.each do |story| %> | ||
<item> | ||
<title><%= raw coder.encode(story.title, :decimal) %></title> | ||
<link><%= story.url_or_comments_url %></link> | ||
<author><%= story.user.username %></author> | ||
<pubDate><%= story.created_at.rfc2822 %></pubDate> | ||
<comments><%= story.comments_url %></comments> | ||
<description><%= raw coder.encode(story.linkified_text, :decimal) | ||
%></description> | ||
<% story.tags.each do |tag| %> | ||
<category><%= tag.tag %></category> | ||
<% end %> | ||
</item> | ||
<% end %> | ||
</channel> | ||
</rss> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters