don't hardcode "Lobsters" and "lobste.rs" everywhere, use Rails.application.{name,domain}

This commit is contained in:
joshua stein 2013-06-30 01:29:51 -05:00
parent 7e71908f3d
commit a471eb180a
23 changed files with 140 additions and 74 deletions

View file

@ -53,14 +53,31 @@ MariaDB have been tested) database, username, and password and put them in a
lobsters$ rake db:schema:load lobsters$ rake db:schema:load
* Create a `config/initializers/secret_token.rb` file, using a randomly generated key from the output of `rake secret`: * Create a `config/initializers/secret_token.rb` file, using a randomly
generated key from the output of `rake secret`:
Lobsters::Application.config.secret_token = 'your random secret here' Lobsters::Application.config.secret_token = 'your random secret here'
* (Optional, only needed for the search engine) Install Sphinx. Build Sphinx config and start server: * (Optional, only needed for the search engine) Install Sphinx. Build Sphinx
config and start server:
lobsters$ rake thinking_sphinx:rebuild lobsters$ rake thinking_sphinx:rebuild
* Define your site's name and default domain, which are used in various places,
in a `config/initializers/production.rb` or similar file:
class << Rails.application
def domain
"example.com"
end
def name
"Example News"
end
end
Rails.application.routes.default_url_options[:host] = Rails.application.domain
* Create an initial administrator user and at least one tag: * Create an initial administrator user and at least one tag:
lobsters$ rails console lobsters$ rails console
@ -74,11 +91,7 @@ MariaDB have been tested) database, username, and password and put them in a
irb(main):006:0> t.tag = "test" irb(main):006:0> t.tag = "test"
irb(main):007:0> t.save irb(main):007:0> t.save
* The default development hostname is defined as `lobsters.localhost:3000`.
You should define this in `/etc/hosts` (or through DNS) to point to
`127.0.0.1`.
* Run the Rails server in development mode. You should be able to login to * Run the Rails server in development mode. You should be able to login to
`http://lobsters.localhost:3000` with your `test` user: `http://localhost:3000` with your new `test` user:
lobsters$ rails server lobsters$ rails server

View file

@ -43,9 +43,10 @@ class SignupController < ApplicationController
if @new_user.save if @new_user.save
@invitation.destroy @invitation.destroy
session[:u] = @new_user.session_token session[:u] = @new_user.session_token
flash[:success] = "Welcome to Lobsters, #{@new_user.username}!" flash[:success] = "Welcome to #{Rails.application.name}, " <<
"#{@new_user.username}!"
Countinual.count!("lobsters.users.created", "+1") Countinual.count!("#{Rails.application.shortname}.users.created", "+1")
return redirect_to "/signup/invite" return redirect_to "/signup/invite"
else else

View file

@ -20,7 +20,8 @@ class StoriesController < ApplicationController
Vote.vote_thusly_on_story_or_comment_for_user_because(1, @story.id, Vote.vote_thusly_on_story_or_comment_for_user_because(1, @story.id,
nil, @user.id, nil) nil, @user.id, nil)
Countinual.count!("lobsters.stories.submitted", "+1") Countinual.count!("#{Rails.application.shortname}.stories.submitted",
"+1")
return redirect_to @story.comments_url return redirect_to @story.comments_url

View file

@ -1,12 +1,15 @@
class EmailMessage < ActionMailer::Base class EmailMessage < ActionMailer::Base
default :from => "nobody@lobste.rs" default :from => "#{Rails.application.name} " <<
"<nobody@#{Rails.application.domain}>"
def notify(message, user) def notify(message, user)
@message = message @message = message
@user = user @user = user
mail(:to => user.email, :from => "Lobsters <nobody@lobste.rs>", mail(
:subject => "[Lobsters] Private Message from " << :to => user.email,
"#{message.author.username}: #{message.subject}") :subject => "[#{Rails.application.name}] Private Message from " <<
"#{message.author.username}: #{message.subject}"
)
end end
end end

View file

@ -1,21 +1,26 @@
class EmailReply < ActionMailer::Base class EmailReply < ActionMailer::Base
default :from => "nobody@lobste.rs" default :from => "#{Rails.application.name} " <<
"<nobody@#{Rails.application.domain}>"
def reply(comment, user) def reply(comment, user)
@comment = comment @comment = comment
@user = user @user = user
mail(:to => user.email, :from => "Lobsters <nobody@lobste.rs>", mail(
:subject => "[Lobsters] Reply from #{comment.user.username} on " << :to => user.email,
"#{comment.story.title}") :subject => "[#{Rails.application.name}] Reply from " <<
"#{comment.user.username} on #{comment.story.title}"
)
end end
def mention(comment, user) def mention(comment, user)
@comment = comment @comment = comment
@user = user @user = user
mail(:to => user.email, :from => "Lobsters <nobody@lobste.rs>", mail(
:subject => "[Lobsters] Mention from #{comment.user.username} on " << :to => user.email,
"#{comment.story.title}") :subject => "[#{Rails.application.name}] Mention from " <<
"#{comment.user.username} on #{comment.story.title}"
)
end end
end end

View file

@ -1,9 +1,14 @@
class InvitationMailer < ActionMailer::Base class InvitationMailer < ActionMailer::Base
default :from => "#{Rails.application.name} " <<
"<nobody@#{Rails.application.domain}>"
def invitation(invitation) def invitation(invitation)
@invitation = invitation @invitation = invitation
mail(:to => invitation.email, mail(
:from => "Lobsters Invitation <nobody@lobste.rs>", :to => invitation.email,
subject: "[Lobsters] Welcome to Lobsters") subject: "[#{Rails.application.name}] Welcome to " <<
Rails.application.name
)
end end
end end

View file

@ -1,9 +1,14 @@
class PasswordReset < ActionMailer::Base class PasswordReset < ActionMailer::Base
default :from => "#{Rails.application.name} " <<
"<nobody@#{Rails.application.domain}>"
def password_reset_link(user, ip) def password_reset_link(user, ip)
@user = user @user = user
@ip = ip @ip = ip
mail(:to => user.email, :from => "Lobsters <nobody@lobste.rs>", mail(
:subject => "[Lobsters] Reset your password") :to => user.email,
:subject => "[#{Rails.application.name}] Reset your password"
)
end end
end end

View file

@ -139,8 +139,8 @@ class Comment < ActiveRecord::Base
if u.pushover_mentions? && u.pushover_user_key.present? if u.pushover_mentions? && u.pushover_user_key.present?
Pushover.push(u.pushover_user_key, u.pushover_device, { Pushover.push(u.pushover_user_key, u.pushover_device, {
:title => "Lobsters mention by #{self.user.username} on " << :title => "#{Rails.application.name} mention by " <<
self.story.title, "#{self.user.username} on #{self.story.title}",
:message => self.plaintext_comment, :message => self.plaintext_comment,
:url => self.url, :url => self.url,
:url_title => "Reply to #{self.user.username}", :url_title => "Reply to #{self.user.username}",
@ -164,8 +164,8 @@ class Comment < ActiveRecord::Base
if u.pushover_replies? && u.pushover_user_key.present? if u.pushover_replies? && u.pushover_user_key.present?
Pushover.push(u.pushover_user_key, u.pushover_device, { Pushover.push(u.pushover_user_key, u.pushover_device, {
:title => "Lobsters reply from #{self.user.username} on " << :title => "#{Rails.application.name} reply from " <<
"#{self.story.title}", "#{self.user.username} on #{self.story.title}",
:message => self.plaintext_comment, :message => self.plaintext_comment,
:url => self.url, :url => self.url,
:url_title => "Reply to #{self.user.username}", :url_title => "Reply to #{self.user.username}",
@ -179,7 +179,7 @@ class Comment < ActiveRecord::Base
end end
def log_to_countinual def log_to_countinual
Countinual.count!("lobsters.comments.submitted", "+1") Countinual.count!("#{Rails.application.shortname}.comments.submitted", "+1")
end end
def delete_for_user(user) def delete_for_user(user)
@ -289,7 +289,7 @@ class Comment < ActiveRecord::Base
end end
def mailing_list_message_id def mailing_list_message_id
"comment.#{short_id}.#{created_at.to_i}@lobste.rs" "comment.#{short_id}.#{created_at.to_i}@#{Rails.application.domain}"
end end
def plaintext_comment def plaintext_comment

View file

@ -45,8 +45,8 @@ class Message < ActiveRecord::Base
self.recipient.pushover_user_key.present? self.recipient.pushover_user_key.present?
Pushover.push(self.recipient.pushover_user_key, Pushover.push(self.recipient.pushover_user_key,
self.recipient.pushover_device, { self.recipient.pushover_device, {
:title => "Lobsters message from #{self.author.username}: " << :title => "#{Rails.application.name} message from " <<
"#{self.subject}", "#{self.author.username}: #{self.subject}",
:message => self.plaintext_body, :message => self.plaintext_body,
:url => self.url, :url => self.url,
:url_title => "Reply to #{self.author.username}", :url_title => "Reply to #{self.author.username}",

View file

@ -229,7 +229,8 @@ class Story < ActiveRecord::Base
s = Sponge.new s = Sponge.new
s.timeout = 3 s.timeout = 3
@fetched_content = s.fetch(self.url, :get, nil, nil, @fetched_content = s.fetch(self.url, :get, nil, nil,
{ "User-agent" => "lobste.rs! for #{for_remote_ip}" }, 3) { "User-agent" => "#{Rails.application.domain} for #{for_remote_ip}" },
3)
rescue rescue
end end
@ -284,7 +285,7 @@ class Story < ActiveRecord::Base
end end
def mailing_list_message_id def mailing_list_message_id
"story.#{short_id}.#{created_at.to_i}@lobste.rs" "story.#{short_id}.#{created_at.to_i}@#{Rails.application.domain}"
end end
@_tags_a = [] @_tags_a = []

View file

@ -133,7 +133,7 @@ class User < ActiveRecord::Base
def linkified_about def linkified_about
# most users are probably mentioning "@username" to mean a twitter url, not # most users are probably mentioning "@username" to mean a twitter url, not
# a link to a lobste.rs profile # a link to a profile on this site
Markdowner.to_html(self.about, { :disable_profile_links => true }) Markdowner.to_html(self.about, { :disable_profile_links => true })
end end

View file

@ -2,7 +2,8 @@
<% coder = HTMLEntities.new %> <% coder = HTMLEntities.new %>
<rss version="2.0"> <rss version="2.0">
<channel> <channel>
<title>lobste.rs<%= @title.present? ? ": " + h(@title) : "" %></title> <title><%= Rails.application.name %><%= @title.present? ?
": " + h(@title) : "" %></title>
<description><%= @title %></description> <description><%= @title %></description>
<link><%= root_url %>comments</link> <link><%= root_url %>comments</link>

View file

@ -2,7 +2,8 @@
<% coder = HTMLEntities.new %> <% coder = HTMLEntities.new %>
<rss version="2.0"> <rss version="2.0">
<channel> <channel>
<title>lobste.rs<%= @title.present? ? ": " + h(@title) : "" %></title> <title><%= Rails.application.name %><%= @title.present? ?
": " + h(@title) : "" %></title>
<description><%= @title %></description> <description><%= @title %></description>
<link><%= root_url + (@newest ? "newest" : "") %></link> <link><%= root_url + (@newest ? "newest" : "") %></link>

View file

@ -1,6 +1,6 @@
Hello <%= @invitation.email %>, Hello <%= @invitation.email %>,
The user <%= @invitation.user.username %> has invited you to the website Lobsters<%= @invitation.memo.present? ? raw(":\n\n #{@invitation.memo}") : "." %> The user <%= @invitation.user.username %> has invited you to the website <%= Rails.application.name %><%= @invitation.memo.present? ? raw(":\n\n #{@invitation.memo}") : "." %>
To create an account, visit the URL below: To create an account, visit the URL below:

View file

@ -14,7 +14,8 @@
<link rev="canonical" rel="self alternate shorter shorturl shortlink" <link rev="canonical" rel="self alternate shorter shorturl shortlink"
href="<%= @short_url %>" /> href="<%= @short_url %>" />
<% end %> <% end %>
<title><%= @title.present? ? "#{@title} | Lobsters" : "Lobsters" %></title> <title><%= @title.present? ? "#{@title} | " : "" %><%=
Rails.application.name %></title>
<%= stylesheet_link_tag "application", :media => "all" %> <%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %> <%= javascript_include_tag "application" %>
<%= csrf_meta_tags %> <%= csrf_meta_tags %>
@ -33,7 +34,7 @@
<div id="headerleft"> <div id="headerleft">
<a id="l_holder" style="background-color: #<%= sprintf("%02x%02x%02x", <a id="l_holder" style="background-color: #<%= sprintf("%02x%02x%02x",
[ 255, (@traffic * 7).floor + 50.0 ].min, 0, 0) %>;" href="/" [ 255, (@traffic * 7).floor + 50.0 ].min, 0, 0) %>;" href="/"
title="Lobsters (<%= @traffic.to_i %>)"></a> title="<%= Rails.application.name %> (<%= @traffic.to_i %>)"></a>
<% links = { <% links = {
"/" => "Home", "/" => "Home",

View file

@ -1,7 +1,7 @@
Hello <%= @user.email %>, Hello <%= @user.email %>,
Someone at <%= @ip %> requested to reset your account password Someone at <%= @ip %> requested to reset your account password
on lobste.rs. If you submitted this request, visit the link below to on <%= Rails.application.name %>. If you submitted this request, visit the link below to
set a new password. If not, you can disregard this e-mail. set a new password. If not, you can disregard this e-mail.
<%= root_url %>login/set_new_password?token=<%= @user.password_reset_token %> <%= root_url %>login/set_new_password?token=<%= @user.password_reset_token %>

View file

@ -152,7 +152,8 @@
<%= f.label :pushover_messages, "List Address:", <%= f.label :pushover_messages, "List Address:",
:class => "required" %> :class => "required" %>
<span> <span>
<tt>lobsters-<%= @edit_user.mailing_list_token %>@lobste.rs</tt> <tt><%= Rails.application.shortname %>-<%=
@edit_user.mailing_list_token %>@<%= Rails.application.domain %></tt>
</span> </span>
</div> </div>

View file

@ -21,16 +21,16 @@
<a href="javascript:window.location=%22<%= root_url %>stories/new?url=%22+encodeURIComponent(document.location)+%22&title=%22+encodeURIComponent(document.title)" <a href="javascript:window.location=%22<%= root_url %>stories/new?url=%22+encodeURIComponent(document.location)+%22&title=%22+encodeURIComponent(document.title)"
style="border: 1px solid #ddd; padding: 0.5em; background-color: style="border: 1px solid #ddd; padding: 0.5em; background-color:
#f8f8f8; line-height: 1.5em; margin-left: 1em;">Submit to #f8f8f8; line-height: 1.5em; margin-left: 1em;">Submit to
Lobsters</a> <%= Rails.application.name %></a>
</div> </div>
<ul> <ul>
<li> <li>
<p> <p>
To be able to easily submit a page you're viewing in your browser To be able to easily submit a page you're viewing in your browser
to Lobsters, drag the bookmarklet to the right to your bookmark to <%= Rails.application.name %>, drag the bookmarklet to the right
bar. You'll be taken to this page with the viewed page's URL and to your bookmark bar. You'll be taken to this page with the viewed
title. page's URL and title.
</p> </p>
<li><p> <li><p>

View file

@ -55,15 +55,33 @@ module Lobsters
# Version of your assets, change this if you want to expire all your assets # Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0' config.assets.version = '1.0'
config.cache_store = :memory_store config.cache_store = :memory_store
end end
end end
# disable yaml/xml/whatever input parsing
silence_warnings do silence_warnings do
ActionDispatch::ParamsParser::DEFAULT_PARSERS = {} ActionDispatch::ParamsParser::DEFAULT_PARSERS = {}
end end
Rails.application.routes.default_url_options[:host] = "lobste.rs" # define site name and domain to be used globally, can be overridden in
# config/initializers/production.rb
class << Rails.application
def domain
"lobste.rs"
end
def name
"Lobsters"
end
# used as mailing list prefix and countinual prefix, cannot have spaces
def shortname
name.downcase.gsub(/[^a-z]/, "")
end
end
Rails.application.routes.default_url_options[:host] = Rails.application.domain
require "#{Rails.root}/lib/monkey" require "#{Rails.root}/lib/monkey"

View file

@ -35,5 +35,3 @@ Lobsters::Application.configure do
# Expands the lines which load the assets # Expands the lines which load the assets
config.assets.debug = true config.assets.debug = true
end end
Rails.application.routes.default_url_options[:host] = "lobsters.localhost:3000"

View file

@ -1,6 +1,6 @@
ActionMailer::Base.smtp_settings = { ActionMailer::Base.smtp_settings = {
:address => "127.0.0.1", :address => "127.0.0.1",
:port => 25, :port => 25,
:domain => "lobste.rs", :domain => Rails.application.domain,
:enable_starttls_auto => false, :enable_starttls_auto => false,
} }

View file

@ -43,20 +43,26 @@ last_story_id = (Keystore.value_for(LAST_STORY_KEY) || Story.last.id).to_i
Story.where("id > ?", last_story_id).order(:id).each do |s| Story.where("id > ?", last_story_id).order(:id).each do |s|
s.fetch_story_cache! s.fetch_story_cache!
s.save s.save
mailing_list_users.each do |u| mailing_list_users.each do |u|
if (s.tags.map{|t| t.id } & u.tag_filters.map{|t| t.tag_id }).any? if (s.tags.map{|t| t.id } & u.tag_filters.map{|t| t.tag_id }).any?
next next
end end
IO.popen([ {}, "/usr/sbin/sendmail", "-i", "-f", "nobody@lobste.rs", domain = Rails.application.domain
u.email ], "w") do |mail| list = "#{Rails.application.shortname}-#{u.mailing_list_token}@" <<
mail.puts "From: #{s.user.username} <#{s.user.username}@lobste.rs>" Rails.application.domain
mail.puts "Reply-To: lobsters-#{u.mailing_list_token}@lobste.rs"
mail.puts "To: lobsters-#{u.mailing_list_token}@lobste.rs" IO.popen([ {}, "/usr/sbin/sendmail", "-i", "-f",
mail.puts "X-BeenThere: lobsters-#{u.mailing_list_token}.lobste.rs" "nobody@#{Rails.application.domain}", u.email ], "w") do |mail|
mail.puts "List-Id: Lobsters <lobsters-#{u.mailing_list_token}.lobste.rs>" mail.puts "From: #{s.user.username} <#{s.user.username}@" <<
mail.puts "List-Unsubscribe: <https://lobste.rs/settings>" "#{Rails.application.domain}>"
mail.puts "Reply-To: #{list}"
mail.puts "To: #{list}"
mail.puts "X-BeenThere: #{list}"
mail.puts "List-Id: #{Rails.application.name} <#{list}>"
mail.puts "List-Unsubscribe: <" <<
"#{Rails.application.routes.url_helpers.root_url}settings>"
mail.puts "Precedence: list" mail.puts "Precedence: list"
mail.puts "Content-Type: text/plain; charset=\"us-ascii\"" mail.puts "Content-Type: text/plain; charset=\"us-ascii\""
mail.puts "Message-ID: <#{s.mailing_list_message_id}>" mail.puts "Message-ID: <#{s.mailing_list_message_id}>"
@ -105,13 +111,18 @@ Comment.where("id > ?", last_comment_id).order(:id).each do |c|
next next
end end
IO.popen([ {}, "/usr/sbin/sendmail", "-i", "-f", "nobody@lobste.rs", domain = Rails.application.domain
u.email ], "w") do |mail| list = "#{Rails.application.shortname}-#{u.mailing_list_token}@" <<
mail.puts "From: #{c.user.username} <#{c.user.username}@lobste.rs>" Rails.application.domain
mail.puts "Reply-To: lobsters-#{u.mailing_list_token}@lobste.rs"
mail.puts "To: lobsters-#{u.mailing_list_token}@lobste.rs" IO.popen([ {}, "/usr/sbin/sendmail", "-i", "-f",
mail.puts "List-Id: Lobsters <lobsters-#{u.mailing_list_token}.lobste.rs>" "nobody@#{domain}", u.email ], "w") do |mail|
mail.puts "List-Unsubscribe: <https://lobste.rs/settings>" mail.puts "From: #{c.user.username} <#{c.user.username}@#{domain}>"
mail.puts "Reply-To: #{list}"
mail.puts "To: #{list}"
mail.puts "List-Id: #{Rails.application.name} <#{list}>"
mail.puts "List-Unsubscribe: <" <<
"#{Rails.application.routes.url_helpers.root_url}settings>"
mail.puts "Precedence: list" mail.puts "Precedence: list"
mail.puts "Content-Type: text/plain; charset=\"us-ascii\"" mail.puts "Content-Type: text/plain; charset=\"us-ascii\""
mail.puts "Message-ID: <#{c.mailing_list_message_id}>" mail.puts "Message-ID: <#{c.mailing_list_message_id}>"

View file

@ -1,12 +1,12 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
# #
# postfix main.cf: # postfix main.cf:
# relay_domains = lobste.rs # relay_domains = example.com
# transport_maps = hash:/etc/postfix/transport # transport_maps = hash:/etc/postfix/transport
# defer_transports = # defer_transports =
# #
# postfix transports: # postfix transports:
# lobste.rs lobsters: # example.com lobsters:
# #
# postfix master.cf: # postfix master.cf:
# lobsters unix - n n - 2 pipe # lobsters unix - n n - 2 pipe
@ -25,7 +25,8 @@ EX_TEMPFAIL = 75
EX_UNAVAILABLE = 69 EX_UNAVAILABLE = 69
recipient = ARGV[0] recipient = ARGV[0]
user_token = recipient.gsub(/^lobsters-/, "").gsub(/@.*/, "") user_token = recipient.gsub(/^#{Rails.application.shortname}-/, "").
gsub(/@.*/, "")
sender = ARGV[1] sender = ARGV[1]
message = "" message = ""
email = nil email = nil
@ -34,7 +35,7 @@ while !STDIN.eof?
message += STDIN.gets.to_s message += STDIN.gets.to_s
end end
if message.match(/^X-BeenThere: lobsters-/i) if message.match(/^X-BeenThere: #{Rails.application.shortname}-/i)
# avoid looping # avoid looping
exit exit
end end
@ -47,7 +48,7 @@ if !sending_user
# if this looks like a user token but invalid, generate a bounce to be # if this looks like a user token but invalid, generate a bounce to be
# helpful. otherwise supress it to avoid talking back to spammers # helpful. otherwise supress it to avoid talking back to spammers
exit(recipient.match(/^lobsters-/) ? EX_NOUSER : 0) exit(recipient.match(/^#{Rails.application.shortname}-/) ? EX_NOUSER : 0)
end end
# the mail gem stupidly spams STDERR while parsing e-mail, so silence that # the mail gem stupidly spams STDERR while parsing e-mail, so silence that