Skip to content

Commit

Permalink
don't hardcode "Lobsters" and "lobste.rs" everywhere, use Rails.appli…
Browse files Browse the repository at this point in the history
…cation.{name,domain}
  • Loading branch information
jcs committed Jun 30, 2013
1 parent 7e71908 commit a471eb1
Show file tree
Hide file tree
Showing 23 changed files with 140 additions and 74 deletions.
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,31 @@ MariaDB have been tested) database, username, and password and put them in a

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'

* (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

* 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:

lobsters$ rails console
Expand All @@ -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):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
`http://lobsters.localhost:3000` with your `test` user:
`http://localhost:3000` with your new `test` user:

lobsters$ rails server
5 changes: 3 additions & 2 deletions app/controllers/signup_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ def signup
if @new_user.save
@invitation.destroy
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"
else
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def create
Vote.vote_thusly_on_story_or_comment_for_user_because(1, @story.id,
nil, @user.id, nil)

Countinual.count!("lobsters.stories.submitted", "+1")
Countinual.count!("#{Rails.application.shortname}.stories.submitted",
"+1")

return redirect_to @story.comments_url

Expand Down
11 changes: 7 additions & 4 deletions app/mailers/email_message.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
class EmailMessage < ActionMailer::Base
default :from => "nobody@lobste.rs"
default :from => "#{Rails.application.name} " <<
"<nobody@#{Rails.application.domain}>"

def notify(message, user)
@message = message
@user = user

mail(:to => user.email, :from => "Lobsters <nobody@lobste.rs>",
:subject => "[Lobsters] Private Message from " <<
"#{message.author.username}: #{message.subject}")
mail(
:to => user.email,
:subject => "[#{Rails.application.name}] Private Message from " <<
"#{message.author.username}: #{message.subject}"
)
end
end
19 changes: 12 additions & 7 deletions app/mailers/email_reply.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
class EmailReply < ActionMailer::Base
default :from => "nobody@lobste.rs"
default :from => "#{Rails.application.name} " <<
"<nobody@#{Rails.application.domain}>"

def reply(comment, user)
@comment = comment
@user = user

mail(:to => user.email, :from => "Lobsters <nobody@lobste.rs>",
:subject => "[Lobsters] Reply from #{comment.user.username} on " <<
"#{comment.story.title}")
mail(
:to => user.email,
:subject => "[#{Rails.application.name}] Reply from " <<
"#{comment.user.username} on #{comment.story.title}"
)
end

def mention(comment, user)
@comment = comment
@user = user

mail(:to => user.email, :from => "Lobsters <nobody@lobste.rs>",
:subject => "[Lobsters] Mention from #{comment.user.username} on " <<
"#{comment.story.title}")
mail(
:to => user.email,
:subject => "[#{Rails.application.name}] Mention from " <<
"#{comment.user.username} on #{comment.story.title}"
)
end
end
11 changes: 8 additions & 3 deletions app/mailers/invitation_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
class InvitationMailer < ActionMailer::Base
default :from => "#{Rails.application.name} " <<
"<nobody@#{Rails.application.domain}>"

def invitation(invitation)
@invitation = invitation

mail(:to => invitation.email,
:from => "Lobsters Invitation <nobody@lobste.rs>",
subject: "[Lobsters] Welcome to Lobsters")
mail(
:to => invitation.email,
subject: "[#{Rails.application.name}] Welcome to " <<
Rails.application.name
)
end
end
9 changes: 7 additions & 2 deletions app/mailers/password_reset.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
class PasswordReset < ActionMailer::Base
default :from => "#{Rails.application.name} " <<
"<nobody@#{Rails.application.domain}>"

def password_reset_link(user, ip)
@user = user
@ip = ip

mail(:to => user.email, :from => "Lobsters <nobody@lobste.rs>",
:subject => "[Lobsters] Reset your password")
mail(
:to => user.email,
:subject => "[#{Rails.application.name}] Reset your password"
)
end
end
12 changes: 6 additions & 6 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def deliver_mention_notifications

if u.pushover_mentions? && u.pushover_user_key.present?
Pushover.push(u.pushover_user_key, u.pushover_device, {
:title => "Lobsters mention by #{self.user.username} on " <<
self.story.title,
:title => "#{Rails.application.name} mention by " <<
"#{self.user.username} on #{self.story.title}",
:message => self.plaintext_comment,
:url => self.url,
:url_title => "Reply to #{self.user.username}",
Expand All @@ -164,8 +164,8 @@ def deliver_reply_notifications

if u.pushover_replies? && u.pushover_user_key.present?
Pushover.push(u.pushover_user_key, u.pushover_device, {
:title => "Lobsters reply from #{self.user.username} on " <<
"#{self.story.title}",
:title => "#{Rails.application.name} reply from " <<
"#{self.user.username} on #{self.story.title}",
:message => self.plaintext_comment,
:url => self.url,
:url_title => "Reply to #{self.user.username}",
Expand All @@ -179,7 +179,7 @@ def deliver_reply_notifications
end

def log_to_countinual
Countinual.count!("lobsters.comments.submitted", "+1")
Countinual.count!("#{Rails.application.shortname}.comments.submitted", "+1")
end

def delete_for_user(user)
Expand Down Expand Up @@ -289,7 +289,7 @@ def has_been_edited?
end

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

def plaintext_comment
Expand Down
4 changes: 2 additions & 2 deletions app/models/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def deliver_reply_notifications
self.recipient.pushover_user_key.present?
Pushover.push(self.recipient.pushover_user_key,
self.recipient.pushover_device, {
:title => "Lobsters message from #{self.author.username}: " <<
"#{self.subject}",
:title => "#{Rails.application.name} message from " <<
"#{self.author.username}: #{self.subject}",
:message => self.plaintext_body,
:url => self.url,
:url_title => "Reply to #{self.author.username}",
Expand Down
5 changes: 3 additions & 2 deletions app/models/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ def fetched_content(for_remote_ip = nil)
s = Sponge.new
s.timeout = 3
@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
end

Expand Down Expand Up @@ -284,7 +285,7 @@ def description=(desc)
end

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

@_tags_a = []
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def initiate_password_reset_for_ip(ip)

def linkified_about
# 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 })
end

Expand Down
3 changes: 2 additions & 1 deletion app/views/comments/index.rss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<% coder = HTMLEntities.new %>
<rss version="2.0">
<channel>
<title>lobste.rs<%= @title.present? ? ": " + h(@title) : "" %></title>
<title><%= Rails.application.name %><%= @title.present? ?
": " + h(@title) : "" %></title>
<description><%= @title %></description>
<link><%= root_url %>comments</link>

Expand Down
3 changes: 2 additions & 1 deletion app/views/home/rss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<% coder = HTMLEntities.new %>
<rss version="2.0">
<channel>
<title>lobste.rs<%= @title.present? ? ": " + h(@title) : "" %></title>
<title><%= Rails.application.name %><%= @title.present? ?
": " + h(@title) : "" %></title>
<description><%= @title %></description>
<link><%= root_url + (@newest ? "newest" : "") %></link>

Expand Down
2 changes: 1 addition & 1 deletion app/views/invitation_mailer/invitation.text.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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:

Expand Down
5 changes: 3 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
<link rev="canonical" rel="self alternate shorter shorturl shortlink"
href="<%= @short_url %>" />
<% end %>
<title><%= @title.present? ? "#{@title} | Lobsters" : "Lobsters" %></title>
<title><%= @title.present? ? "#{@title} | " : "" %><%=
Rails.application.name %></title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
Expand All @@ -33,7 +34,7 @@
<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="Lobsters (<%= @traffic.to_i %>)"></a>
title="<%= Rails.application.name %> (<%= @traffic.to_i %>)"></a>

<% links = {
"/" => "Home",
Expand Down
2 changes: 1 addition & 1 deletion app/views/password_reset/password_reset_link.text.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Hello <%= @user.email %>,

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.

<%= root_url %>login/set_new_password?token=<%= @user.password_reset_token %>
3 changes: 2 additions & 1 deletion app/views/settings/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@
<%= f.label :pushover_messages, "List Address:",
:class => "required" %>
<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>
</div>

Expand Down
8 changes: 4 additions & 4 deletions app/views/stories/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
style="border: 1px solid #ddd; padding: 0.5em; background-color:
#f8f8f8; line-height: 1.5em; margin-left: 1em;">Submit to
Lobsters</a>
<%= Rails.application.name %></a>
</div>
<ul>

<li>
<p>
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
bar. You'll be taken to this page with the viewed page's URL and
title.
to <%= Rails.application.name %>, drag the bookmarklet to the right
to your bookmark bar. You'll be taken to this page with the viewed
page's URL and title.
</p>

<li><p>
Expand Down
22 changes: 20 additions & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,33 @@ class Application < Rails::Application

# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'

config.cache_store = :memory_store
end
end

# disable yaml/xml/whatever input parsing
silence_warnings do
ActionDispatch::ParamsParser::DEFAULT_PARSERS = {}
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"
2 changes: 0 additions & 2 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,3 @@
# Expands the lines which load the assets
config.assets.debug = true
end

Rails.application.routes.default_url_options[:host] = "lobsters.localhost:3000"
2 changes: 1 addition & 1 deletion config/initializers/email.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ActionMailer::Base.smtp_settings = {
:address => "127.0.0.1",
:port => 25,
:domain => "lobste.rs",
:domain => Rails.application.domain,
:enable_starttls_auto => false,
}
Loading

0 comments on commit a471eb1

Please sign in to comment.