Skip to content

Commit

Permalink
first stab at planet rss aggregation
Browse files Browse the repository at this point in the history
could probably use a prettier layout and auto-posting a weblog url
to the main site (carrying tags)
  • Loading branch information
jcs committed Aug 4, 2014
1 parent 8d17638 commit 85cb7c2
Show file tree
Hide file tree
Showing 17 changed files with 407 additions and 101 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ gem "oauth"
# for parsing incoming mail
gem "mail"

# for planet rss aggregation
gem "feed-normalizer"
gem "loofah"

group :test, :development do
gem "rspec-rails", "~> 2.6"
gem "machinist"
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ GEM
execjs (2.2.1)
faker (1.4.2)
i18n (~> 0.5)
feed-normalizer (1.5.2)
hpricot (>= 0.6)
simple-rss (>= 1.1)
hike (1.2.3)
hpricot (0.8.6)
htmlentities (4.3.2)
i18n (0.6.11)
innertube (1.1.0)
Expand All @@ -48,6 +52,8 @@ GEM
thor (>= 0.14, < 2.0)
json (1.8.1)
kgio (2.9.2)
loofah (2.0.0)
nokogiri (>= 1.5.9)
machinist (2.0)
mail (2.5.4)
mime-types (~> 1.16)
Expand Down Expand Up @@ -97,6 +103,7 @@ GEM
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
simple-rss (1.3.1)
sprockets (2.12.1)
hike (~> 1.2)
multi_json (~> 1.0)
Expand Down Expand Up @@ -136,8 +143,10 @@ DEPENDENCIES
dynamic_form
exception_notification
faker
feed-normalizer
htmlentities
jquery-rails
loofah
machinist
mail
mysql2 (>= 0.3.14)
Expand Down
11 changes: 11 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ li .domain {
font-size: 8.5pt;
vertical-align: middle;
}
li .domain a {
color: #888;
text-decoration: none;
}

.merge {
background: url(data:image/png;base64,iVBORw0KGg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10 @@ div.fieldWithErrors {
font-style: italic;
padding-left: 0.5em;
}



div.weblog_content {
padding: 0 2em;
overflow-x: auto;
}
2 changes: 1 addition & 1 deletion app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def user_params
:email_replies, :email_messages, :email_mentions,
:pushover_replies, :pushover_messages, :pushover_mentions,
:pushover_user_key, :pushover_device, :pushover_sound,
:mailing_list_mode,
:mailing_list_mode, :weblog_feed_url
)
end
end
24 changes: 24 additions & 0 deletions app/controllers/weblogs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class WeblogsController < ApplicationController
before_filter { @page = page }

WEBLOGS_PER_PAGE = 10

def index
@pages = (Weblog.count / WEBLOGS_PER_PAGE.to_f).ceil
if @page > @pages
@page = @pages
end
@show_more = @page < @pages

@weblogs = Weblog.order("created_at DESC").
offset((@page - 1) * WEBLOGS_PER_PAGE).
limit(WEBLOGS_PER_PAGE)

render :action => "index"
end

private
def page
params[:page].to_i > 0 ? params[:page].to_i : 1
end
end
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ def time_ago_in_words_label(*args)
label_tag(nil, time_ago_in_words(*args),
:title => args.first.strftime("%F %T %z"))
end

def main_root_url
Rails.application.routes.url_helpers.root_url
end
end
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class User < ActiveRecord::Base
belongs_to :banned_by_user,
:class_name => "User"
has_many :invitations
has_many :weblogs

has_secure_password

Expand All @@ -31,6 +32,10 @@ class User < ActiveRecord::Base
:format => { :with => /\A[A-Za-z0-9][A-Za-z0-9_-]{0,24}\Z/ },
:uniqueness => { :case_sensitive => false }

validates :weblog_feed_url,
:format => { :with => /\Ahttps?:\/\/([^\.]+\.)+[a-z]+(\/|\z)/ },
:allow_blank => true

validates_each :username do |record,attr,value|
if BANNED_USERNAMES.include?(value.to_s.downcase)
record.errors.add(attr, "is not permitted")
Expand Down
9 changes: 9 additions & 0 deletions app/models/weblog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Weblog < ActiveRecord::Base
belongs_to :user

serialize :tags, Array

def sanitized_content
Loofah.fragment(self.content).scrub!(:strip).scrub!(:nofollow).to_s.html_safe
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
</span>
</div>

<div id="headerright" class="<%= @user ? "loggedin" : "" %>">
<div id="headerright">
<span class="headerlinks">
<a href="/filters" <%= @cur_url == "/filters" ?
raw("class=\"cur_url\"") : "" %>>Filters</a>
Expand Down
63 changes: 63 additions & 0 deletions app/views/layouts/weblogs.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon.png" />
<link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon.png" />
<link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-144.png" />
<link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="robots" content="noarchive,noodp,noydir" />
<meta name="referrer" content="always" />
<% if @short_url %>
<link rev="canonical" rel="self alternate shorter shorturl shortlink"
href="<%= @short_url %>" />
<% end %>
<title><%= @title.present? ? "#{@title} | " : "" %>Planet <%=
Rails.application.name %></title>
<%= stylesheet_link_tag "application", :media => "all" %>
<% if @user %>
<%= javascript_include_tag "application" %>
<script>
Lobsters.curUser = '<%= @user.id %>';
</script>
<% end %>
<%= csrf_meta_tags %>
</head>
<body>
<div id="wrapper">
<div id="header">
<div id="headerleft">
<a id="l_holder" style="background-color: #<%= sprintf("%02x%02x%02x",
[ 255, (@traffic * 7).floor + 50.0 ].min, 0, 0) %>;" href="/"
title="<%= Rails.application.name %> (<%= @traffic.to_i %>)"></a>
<span id="headertitle">
<a href="/">Planet <%= Rails.application.name %></a>
</span>
</div>

<div id="headerright">
<span class="headerlinks">
<a href="<%= main_root_url %>"><%= Rails.application.name %></a>
</span>
</div>

<div class="clear"></div>
</div>

<div id="inside">
<% if flash[:error] %>
<div class="flash-error"><%= flash[:error] %></div>
<% elsif flash[:success] %>
<div class="flash-success"><%= flash[:success] %></div>
<% end %>

<%= yield %>

<div class="clear"></div>
</div>
</div>
</body>
</html>

19 changes: 19 additions & 0 deletions app/views/settings/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@
</span>
</div>

<br>

<div class="boxline">
<%= f.label :pushover_user_key,
raw("<a href=\"https://pushover.net/\">Pushover</a> User Key:"),
:class => "required" %>
<%= f.text_field :pushover_user_key, :size => 40 %>
<span class="hint">
For optional comment and message notifications below
</span>
</div>

<div class="boxline">
Expand All @@ -58,6 +63,20 @@
<%= f.select :pushover_sound, Pushover.sounds.map{|k,v| [ v, k ] } %>
</div>

<br>

<div class="boxline">
<%= f.label :weblog_feed_url, "Weblog Feed URL:",
:class => "required" %>
<%= f.text_field :weblog_feed_url, :placeholder => "optional",
:size => 40 %>
<span class="hint">
For RSS/Atom feed aggregation; restrict to a technical feed if possible
</span>
</div>

<br>

<div class="boxline">
<%= f.label :about, "About:", :class => "required" %>
<%= f.text_area :about, :size => "100x5", :style => "width: 600px;" %>
Expand Down
44 changes: 44 additions & 0 deletions app/views/weblogs/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<ol class="stories list">
<% @weblogs.each do |weblog| %>
<li class="story">
<div class="story_liner">
<div class="details">
<span class="link">
<a href="<%= weblog.url %>"><%= weblog.title %></a>
</span>
<span class="tags">
<% weblog.tags.map{|t| t.downcase }.sort.each do |tag| %>
<a href="<%= main_root_url %>t/<%= tag %>" class="tag"><%= tag %></a>
<% end %>
</span>
<span class="domain">
<a href="<%= weblog.site_url %>"><%= weblog.site_title %></a>
</span>
<div class="byline">
by <a href="<%= main_root_url %>u/<%= weblog.user.username %>"><%=
weblog.user.username %></a>
<%= raw(time_ago_in_words_label(weblog.created_at).
gsub(/^about /, "")) %> ago
</div>
</div>
</div>
<div class="story_content weblog_content shorten_first_p">
<%= weblog.sanitized_content %>
</div>
</li>
<% end %>
</ol>

<div class="morelink">
<% if @page && @page > 1 %>
<a href="/<%= @page == 2 ? "" : "page/#{@page - 1}" %>">&lt;&lt; Page
<%= @page - 1 %></a>
<% end %>

<% if @show_more %>
<% if @page && @page > 1 %>
|
<% end %>
<a href="/page/<%= @page + 1 %>">Page <%= @page + 1 %> &gt;&gt;</a>
<% end %>
</div>
Loading

0 comments on commit 85cb7c2

Please sign in to comment.