Skip to content

Commit

Permalink
Changed to use a Rails application template instead of cloning a git …
Browse files Browse the repository at this point in the history
…repository
  • Loading branch information
jferris committed Sep 22, 2010
1 parent 1f37a03 commit 36ec034
Show file tree
Hide file tree
Showing 12 changed files with 1,592 additions and 52 deletions.
56 changes: 4 additions & 52 deletions lib/create.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Methods needed to create a project.

require 'rubygems'
require 'digest/md5'
require File.expand_path(File.dirname(__FILE__) + "/errors")
require File.expand_path(File.dirname(__FILE__) + "/command")

Expand All @@ -21,48 +20,12 @@ def initialize(input_project_name, input_template_url)
end

def create_project!
run("mkdir #{project_directory}")
Dir.chdir(project_directory) or fail("Couldn't change to #{project_directory}")
run("git init")
run("git remote add suspenders #{template_url}")
run("git pull suspenders master")

Dir.glob("#{project_directory}/**/*.*").each do |file|
search_and_replace(file, changeme, project_name)
end

Dir.glob("#{project_directory}/**/session_store.rb").each do |file|
datestring = Time.now.strftime("%j %U %w %A %B %d %Y %I %M %S %p %Z")
search_and_replace(file, changesession, Digest::MD5.hexdigest("#{project_name} #{datestring}"))
end

run("git commit -a -m 'Initial commit'")

run("rake gems:refresh_specs")
run("rake db:create RAILS_ENV=development")
run("rake db:create RAILS_ENV=test")

run("script/generate clearance")
run("script/generate clearance_features -f")
run("script/generate clearance_views -f")

run("git add .")
run("git commit -m 'installed clearance'")

puts
puts "Now login to github and add a new project named '#{project_name}'"
Dir.chdir(File.dirname(project_directory))
run("rails new #{project_name} --template=#{template}")

This comment has been minimized.

Copy link
@hgmnz

hgmnz Sep 24, 2010

We can add a couple of options to the rails command:
--skip-prototype --skip-test-unit

Files related to both of these are removed in the template.

Another idea is to be able to pass in a value for -d that either the generator or our template uses to create a database.yml

This comment has been minimized.

Copy link
@jferris

jferris Sep 27, 2010

Author Contributor

Thanks - I'm using the skip options instead of deleting. I decided not to use -d for now, since the mysql option uses a different database driver than what we've been using (or what was used in the rails3 branch of suspenders, which I'm basing this off of).

end

private

def changeme
"CHANGEME"
end

def changesession
"CHANGESESSION"
end

def valid_project_name!(project_name)
unless project_name =~ /^[a-z0-9_]+$/
raise InvalidInput.new("Project name must only contain [a-z0-9_]")
Expand All @@ -88,19 +51,8 @@ def valid_template_url!(template_url, project_name)
end
end

def search_and_replace(file, search, replace)
begin
contents = File.read(file)
if contents[search]
puts "Replacing #{search} with #{replace} in #{file}"
contents.gsub!(search, replace)
File.open(file, "w") { |f| f << contents }
end
rescue Errno::EISDIR => e
# This is fine, because Dir.glob can't select only files.
rescue Errno::ENOENT => e
fail "Attempted to perform a find-and-replace on a missing file: #{file}"
end
def template
File.expand_path(File.dirname(__FILE__) + "/../template/suspenders.rb")
end
end
end
166 changes: 166 additions & 0 deletions template/files/README_FOR_TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
This is Suspenders, the thoughtbot rails template.

To create a new project, first install the suspenders gem:

gem install suspenders

Then run:

suspenders create projectname

This will create a project in ../projectname. You should then follow the
instructions on Github to upload that project there. This creates an
entirely new git repository, and is not meant to be used against an existing
repo.

When making a change to a project that was created via this template, consider
whether it's a change that should be made across all projects. If so, then
make the change in suspenders instead of your project. Note: If you don't
have commit access to suspenders, create a github ticket and we'll review your
suggestion.

Once that's committed, you can pull into your project to get all the changes
that have been made in suspenders since your last pull:

rake git:pull:suspenders

About Suspenders
----------------

Suspenders was created for use at thoughtbot, inc. (http://thoughtbot.com) as a
baseline application setup, with reasonable default plugins that the majority
(if not all) of our applications used, as well as best-practice configuration
options.

Suspenders currently includes a version of Rails from the 2.3 stable branch.
You can determine the changeset with the vendor/rails/REVISION_xxxxx file.

Gems (unpacked in vendor/gems, unless they are compiled gems):
--------------------------------------------------------------

For record pagination:

will_paginate

For text formatting:

RedCloth (4.2.2, not unpacked, this is a compiled gem)

Form builder:

Formtastic

File attachments:

Paperclip

Basic user auth:

Clearance

For testing:

jferris-mocha (standard mocha plus test spies)
factory_girl (fixture replacement for test data)
shoulda (rails test helpers and context framework)
timecop (for time sensitive tests)
fakeweb (for blocking HTTP calls to third-party services)

Error notification:

hoptoad_notifier

Plugins (in vendor/plugins):
----------------------------

limerick_rake (useful rake tasks)
validation_reflection (used by formtastic to find required fields)
high_voltage (Rails engine for static pages)

Initializers (in config/initializers)
-------------------------------------

action_mailer_configs.rb
We use SMTP by default in all applications.

hoptoad.rb
Get your API key at http://hoptoadapp.com

requires.rb
Automatically requires everything in
lib/
lib/extensions
test/mocks/RAILS_ENV (Removed in Rails 2, we decided to keep it)
Add other things you need to require in here.

time_formats.rb
Two time formats are available by default, :short_date and :long_date.
Add other time formats here.

Rake Tasks
----------

Rake tasks are contained in the limerick_rake gem.

bootstrap
Provides rake tasks for loading data into the database. These are used for
an initial application dataset needed for production.

capistrano
Standard capistrano deployment tasks

Testing
-------

Testing is done utilizing Test::Unit, Shoulda, factory_girl, and mocha.

factory_girl is a fixture replacement library, following the factory pattern.
Place your factories in test/factories.rb. The fixture directory has been
removed, as fixtures are not used.

Shoulda is a pragmatic testing framework for TDD and BDD built on top of
Test::Unit. A number of additional testing macros are provided in
test/shoulda_macros:

shoulda_have_form
shoulda_paginate_collection

Timecop is used to freeze the time for the entire test suite. It is frozen to
the value of Time.now; that is, the time that the tests suite starts running.

Deployment
----------

Deployment is done using capistrano, and deploys to a mongrel cluster, running
under Apache.

Rake tasks are provided for managing git branches which the different
environments pull from for deploy.

To push the git master to git staging branch run:

rake git:push:staging

To push the git staging branch to production branch run:

rake git:push:production

Setup your deployment environment by running:

cap ENVIRONMENT deploy:setup
(You'll be prompted for the environment's database password)

Deploy to the desired environment by running:

cap ENVIRONMENT deploy

The default environment for deploy is staging, to deploy to staging, just run:

cap deploy

Mascot
------

The official Suspenders mascot is Suspenders Boy:

http://media.tumblr.com/1TEAMALpseh5xzf0Jt6bcwSMo1_400.png
5 changes: 5 additions & 0 deletions template/files/_flashes.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div id="flash">
<% flash.each do |key, value| -%>
<div id="flash_<%= key %>"><%=h value %></div>
<% end -%>
</div>
2 changes: 2 additions & 0 deletions template/files/_javascript.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%= javascript_include_tag 'jquery', 'jquery-ui', 'prefilled_input', :cache => true %>
<%= yield :javascript %>
Loading

0 comments on commit 36ec034

Please sign in to comment.