diff --git a/Gemfile b/Gemfile deleted file mode 100644 index 86385a6..0000000 --- a/Gemfile +++ /dev/null @@ -1,59 +0,0 @@ -source 'http://rubygems.org' - -gem 'rails', '3.0.3' - -gem 'sqlite3-ruby', :require => 'sqlite3' - -gem "rails_admin", :git => 'git://github.com/sferik/rails_admin.git' -gem "haml-rails", ">= 0.2" -gem "inherited_resources", ">=1.1.2" -gem "will_paginate", ">=3.0.pre2" -gem "devise", ">=1.1.2" -gem "formtastic", ">=1.1.0" -gem "friendly_id", "~>3.0" -gem "compass", ">= 0.10.5" -gem "lemonade", "0.3.4" -gem "barista", ">= 0.5.0" -gem "hoptoad_notifier", ">=2.3.6" -gem "inploy", ">=1.6.8" - -group :development do - gem "autotest" - gem "autotest-notification" - gem "rails3-generators", :git => "git://github.com/indirect/rails3-generators.git" - gem "metric_fu", ">=1.5.1" -end - -group :development, :test do - gem "evergreen" - gem "factory_girl_rails" - gem "rspec-rails", ">=2.0.1" - gem "evergreen", :require => "evergreen/rails" - platforms :mri_18 do - gem "ruby-debug" - end - platforms :mri_19 do - gem "ruby-debug19", :require => 'ruby-debug' - end -end - -group :test do - gem "rspec", ">=2.0.1" - gem "remarkable", ">=4.0.0.alpha4" - gem "remarkable_activemodel", ">=4.0.0.alpha4" - gem "remarkable_activerecord", ">=4.0.0.alpha4" - gem "capybara-envjs" -end - -group :cucumber do - gem "cucumber", ">=0.6.3" - gem "cucumber-rails", ">=0.3.2" - gem "capybara", ">=0.3.6" - gem "database_cleaner", ">=0.5.0" - gem "spork", ">=0.8.4" - gem "pickle", ">=0.4.2" -end - -group :production do - gem "newrelic_rpm", ">=2.12.3" -end diff --git a/README.textile b/README.textile index d75dd5f..0fb654a 100644 --- a/README.textile +++ b/README.textile @@ -1,4 +1,4 @@ -Read the "Gemfile":blob/master/Gemfile to understand everything this template installs and pre-configures for you. +Read the "Gemfile":blob/master/files/Gemfile to understand everything this template installs and pre-configures for you. One of gems, "Johnson":http://rubygems.org/gems/johnson, still has some issues compiling under Ruby 1.9.2 so you will need to use Ruby 1.8.7 instead. @@ -8,10 +8,51 @@ This template is heavily dependent on wget so, if you're using a Mac, you will n Since Github started forcing SSL in all its URLs, we need to download the template file separately: -
wget --no-check-certificate https://github.com/dcrec1/rails3_template/raw/master/main.rb -O /tmp/rails3_template.rb
+
wget --no-check-certificate https://github.com/akitaonrails/rails3_template/raw/master/main.rb -O /tmp/rails3_template.rb
Then whenever you want to create a new project, just do: -
rails new app_name -T -m /tmp/rails3_template.rb
+
rails new app_name -JT -m /tmp/rails3_template.rb
Change app_name for your project name. You can configure what you need and run rake db:migrate to get started. + +h2. CRITERIA + +This is intended to be an opinionated template. The options chosen have these reasons: + +* Standard ERB instead of HAML - even though HAML is great the pros and cons are too balanced to justify replacing ERB. +* Simple Form instead of Formtastic - to me, "feels" simpler +* SASS instead of pure CSS - this undeniably adds value on top of CSS making it easier to organize +* JQuery instead of Prototype - no need to say more +* Kaminari instead of Will Paginate - cleaner solution for pagination +* Pure Javascript instead of CoffeeScript - as HAML, the syntax gets more elegant, but there is no inherent advantages +* RSpec, Factory Girl Cucumber, Spork, Capybara, Celerity, Faker, Metric Fu - this is the universally accepted main test package, so be it +* Evergreen - testing Javascript is great and this seems to be the best so far +* Devise - the best authentication system so far +* Inherited Resources - lighter controllers +* Compass, Asset Packager, Lemonade - easier way to deal with images and other assets +* Cells - this is experimental but does bring advantages in making controller less cluttered and isolating components + +So, opinionated to a point, trying to stick to the basics where advantages are not so obvious. + +h2. TESTING + +Read Peter Cooper's "excellent tutorial":http://www.rubyinside.com/how-to-rails-3-and-rspec-2-4336.html on how to setup a fast testing environment: + +This template tries to do so. Before starting just run: + +
spork
+ +And in another terminal run: + +
rake watchr
+ +Also do not forget to modify config/environments/test.rb to reload classes: + +
config.cache_classes = false
+ +h2. CREDITS + +This Template is based on "Diego Carrion's template":https://github.com/dcrec1/rails3_template. The changes include removing HAML, Hoptoad, Coffeescript (Barista), Remarkable, adding yajl for json, thin, replacing will_paginate for kaminari, replacing autotest for watchr, enabling spork, replacing formtastic for simple_form, bundling gems within the app, + +Author: Fabio Akita (@AkitaOnRails) diff --git a/application.html.haml b/application.html.haml deleted file mode 100644 index 2f558b9..0000000 --- a/application.html.haml +++ /dev/null @@ -1,18 +0,0 @@ -!!! 5 -%html - %head - %title - = raw stylesheet_link_merged('screen', :media => 'screen, projection') - = raw stylesheet_link_merged('print', :media => 'print') - /[if lt IE 8] - = raw stylesheet_link_merged('ie', :media => 'screen, projection') - = csrf_meta_tag - %body - #container - %header HEADER - %sidebar SIDEBAR - %section#content= yield - %footer FOOTER - %script{ :type => "text/javascript", :src => "http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" } - %script{ :type => "text/javascript", :src => "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js" } - = raw javascript_include_merged(:base) diff --git a/build.rake b/build.rake deleted file mode 100644 index ded6a4f..0000000 --- a/build.rake +++ /dev/null @@ -1,5 +0,0 @@ -task :clean do - system "rm rerun.txt" -end - -task :build => [:clean, 'db:migrate', :spec, 'barista:brew', 'spec:javascripts', :cucumber, 'metrics:all'] diff --git a/build.sh b/build.sh deleted file mode 100644 index d5ba5ea..0000000 --- a/build.sh +++ /dev/null @@ -1,2 +0,0 @@ -bundle install ~/.bundle --without=production -rake build diff --git a/files/Gemfile b/files/Gemfile new file mode 100644 index 0000000..afd4134 --- /dev/null +++ b/files/Gemfile @@ -0,0 +1,57 @@ +source 'http://rubygems.org' + +gem 'rails', '3.0.5' + +gem 'sqlite3-ruby', :require => 'sqlite3' + +gem "rails_admin", :git => 'https://github.com/sferik/rails_admin.git' +gem "inherited_resources" +gem "kaminari" +gem "devise" +gem "simple_form" +gem "friendly_id" +gem "compass" +gem "lemonade" +gem "cells" +gem 'yajl-ruby', :require => 'yajl/json_gem' + +group :development do + gem "watchr" + gem "rails3-generators", :git => "https://github.com/indirect/rails3-generators.git" + gem "metric_fu" +end + +group :development, :test do + gem "spork" + gem "thin" + gem "evergreen" + gem "factory_girl_rails" + gem "rspec-rails" + gem "rspec-cells" + gem "faker" + gem "evergreen", :require => "evergreen/rails" + platforms :mri_18 do + gem "ruby-debug" + end + platforms :mri_19 do + gem "ruby-debug19", :require => 'ruby-debug' + end +end + +group :test do + gem "rspec" + gem "capybara-envjs" +end + +group :cucumber do + gem "cucumber" + gem "cucumber-rails" + gem "capybara" + gem "database_cleaner" + gem "spork" + gem "pickle" +end + +group :production do + gem "newrelic_rpm" +end diff --git a/files/application.html b/files/application.html new file mode 100644 index 0000000..4f39484 --- /dev/null +++ b/files/application.html @@ -0,0 +1 @@ + diff --git a/files/application.html.erb b/files/application.html.erb new file mode 100644 index 0000000..e868846 --- /dev/null +++ b/files/application.html.erb @@ -0,0 +1,29 @@ + + + + TITLE + <%= raw stylesheet_link_merged('screen', :media => 'screen, projection') %> + <%= raw stylesheet_link_merged('simple_form', :media => 'screen, projection') %> + <%= raw stylesheet_link_merged('print', :media => 'print') %> + + <%= csrf_meta_tag %> + + +
+
HEADER
+ SIDEBAR +
+ <% content_for :notice do %>

<%= notice %>

<% end %> + <% content_for :alert do %>

<%= alert %>

<% end %> + <%= yield %> +
+ +
+ + + <%= raw javascript_include_merged(:base) %> + + diff --git a/files/application_spec.js b/files/application_spec.js new file mode 100644 index 0000000..38c3dd3 --- /dev/null +++ b/files/application_spec.js @@ -0,0 +1,39 @@ +// Example of how to add javascript specs +// +// require("/jquery.js"); +// require("/jquery-ui.js"); +// require("/application.js"); +// $.ready(); +// +// describe("with main template", function() { +// template('application.html'); +// +// describe("on load", function() { +// beforeEach(function() { +// }); +// +// it("should set select as text inputs", function() { +// expect($("#sign_in")).toBeATextInput(); +// }); +// +// it("should not set all select as text inputs", function() { +// expect($("#select")).not.toBeATextInput(); +// }); +// +// it("should hide the anchor", function() { +// $("#container a.next").show(); +// $("#container a.next").click(); +// expect($("#playboard a.next")).toBeHidden(); +// }); +// +// it("should show .matches nav a.prev", function() { +// $("#container a.prev").hide(); +// $("#container a.next").click(); +// expect($("#playboard a.prev")).toBeVisible(); +// }); +// +// it("should prevent the event default", function() { +// expect(eventForSelectorHandler("#container a.prev", "click")).toBeDefaultPrevented(); +// }); +// }) +// }) diff --git a/asset_packages.yml b/files/asset_packages.yml similarity index 100% rename from asset_packages.yml rename to files/asset_packages.yml diff --git a/bootstrap.rake b/files/bootstrap.rake similarity index 100% rename from bootstrap.rake rename to files/bootstrap.rake diff --git a/files/build.rake b/files/build.rake new file mode 100644 index 0000000..fe5447f --- /dev/null +++ b/files/build.rake @@ -0,0 +1,5 @@ +task :clean do + system "rm rerun.txt" +end + +task :build => [:clean, 'db:migrate', :spec, 'spec:javascripts', :cucumber, 'metrics:all'] diff --git a/files/build.sh b/files/build.sh new file mode 100644 index 0000000..27a8e6e --- /dev/null +++ b/files/build.sh @@ -0,0 +1,2 @@ +bundle install --without=production +rake build diff --git a/devise_steps.rb b/files/devise_steps.rb similarity index 100% rename from devise_steps.rb rename to files/devise_steps.rb diff --git a/evergreen.rb b/files/evergreen.rb similarity index 100% rename from evergreen.rb rename to files/evergreen.rb diff --git a/factory_girl.rb b/files/factory_girl.rb similarity index 100% rename from factory_girl.rb rename to files/factory_girl.rb diff --git a/gitignore b/files/gitignore similarity index 100% rename from gitignore rename to files/gitignore diff --git a/grid.png b/files/grid.png similarity index 100% rename from grid.png rename to files/grid.png diff --git a/htaccess b/files/htaccess similarity index 100% rename from htaccess rename to files/htaccess diff --git a/files/html5.js b/files/html5.js new file mode 100644 index 0000000..3587bf7 --- /dev/null +++ b/files/html5.js @@ -0,0 +1,6 @@ +// html5shiv MIT @rem remysharp.com/html5-enabling-script +// iepp v1.6.2 MIT @jon_neal iecss.com/print-protector +/*@cc_on(function(m,c){var z="abbr|article|aside|audio|canvas|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video";function n(d){for(var a=-1;++ai";if(g.childNodes.length!==1){var i=z.split("|"),o=i.length,s=RegExp("(^|\\s)("+z+")", +"gi"),t=RegExp("<(/*)("+z+")","gi"),u=RegExp("(^|[^\\n]*?\\s)("+z+")([^\\n]*)({[\\n\\w\\W]*?})","gi"),r=c.createDocumentFragment(),k=c.documentElement;g=k.firstChild;var h=c.createElement("body"),l=c.createElement("style"),f;n(c);n(r);g.insertBefore(l, +g.firstChild);l.media="print";m.attachEvent("onbeforeprint",function(){var d=-1,a=p(c.styleSheets,"all"),e=[],b;for(f=f||c.body;(b=u.exec(a))!=null;)e.push((b[1]+b[2]+b[3]).replace(s,"$1.iepp_$2")+b[4]);for(l.styleSheet.cssText=e.join("\n");++d true, :views => false g.integration_tool :rspec, :fixture => true, :views => true g.fixture_replacement :factory_girl, :dir => "spec/support/factories" @@ -19,44 +21,53 @@ generate "cucumber:install --capybara --rspec --spork" generate "pickle --path --email" generate "friendly_id" -generate "formtastic:install" +generate "simple_form:install" generate "devise:install" generate "devise User" generate "devise Admin" generate "rails_admin:install_admin" -generate "barista:install" -run "gem install compass" -run "compass init --using blueprint --app rails --css-dir public/stylesheets" +run "compass init --using blueprint --app rails --css-dir public/stylesheets --sass-dir app/stylesheets" + append_file "config/compass.rb", "require 'lemonade'" +remove_file ".rspec" +create_file ".rspec", "--colour --drb" + run "rm public/stylesheets/*" +run "mkdir -p app/cells spec/javascripts spec/javascripts/templates" run "wget --no-check-certificate 'https://github.com/rails/jquery-ujs/raw/master/src/rails.js' -O public/javascripts/rails.js" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/gitignore' -O .gitignore" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/screen.scss' -O app/stylesheets/screen.scss" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/print.scss' -O app/stylesheets/print.scss" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/application.html.haml' -O app/views/layouts/application.html.haml" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/factory_girl.rb' -O features/support/factory_girl.rb" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/devise_steps.rb' -O features/step_definitions/devise_steps.rb" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/remarkable.rb' -O spec/support/remarkable.rb" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/users.rb' -O spec/support/factories/users.rb" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/build.rake' -O lib/tasks/build.rake" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/bootstrap.rake' -O lib/tasks/bootstrap.rake" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/build.sh' -O build.sh" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/overlay.png' -O public/images/overlay.png" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/newrelic.yml' -O config/newrelic.yml" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/hoptoad.rb' -O config/initializers/hoptoad.rb" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/rails_admin.rb' -O config/initializers/rails_admin.rb" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/htaccess' -O public/.htaccess" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/asset_packages.yml' -O config/asset_packages.yml" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/evergreen.rb' -O config/evergreen.rb" -run "wget --no-check-certificate 'https://github.com/dcrec1/rails3_template/raw/master/grid.png' -O public/images/grid.png" - -create_file 'config/deploy.rb', <<-DEPLOY -application = '#{app_name}' -repository = '' -hosts = %w() -DEPLOY +run "wget --no-check-certificate '#{BASE_URI}/gitignore' -O .gitignore" +run "wget --no-check-certificate '#{BASE_URI}/screen.scss' -O app/stylesheets/screen.scss" +run "wget --no-check-certificate '#{BASE_URI}/print.scss' -O app/stylesheets/print.scss" +run "wget --no-check-certificate '#{BASE_URI}/simple_form.scss' -O app/stylesheets/simple_form.scss" +run "wget --no-check-certificate '#{BASE_URI}/application.html.erb' -O app/views/layouts/application.html.erb" +run "wget --no-check-certificate '#{BASE_URI}/factory_girl.rb' -O features/support/factory_girl.rb" +run "wget --no-check-certificate '#{BASE_URI}/devise_steps.rb' -O features/step_definitions/devise_steps.rb" +run "wget --no-check-certificate '#{BASE_URI}/users.rb' -O spec/support/factories/users.rb" +run "wget --no-check-certificate '#{BASE_URI}/build.rake' -O lib/tasks/build.rake" +run "wget --no-check-certificate '#{BASE_URI}/build.sh' -O build.sh" +run "wget --no-check-certificate '#{BASE_URI}/bootstrap.rake' -O lib/tasks/bootstrap.rake" +run "wget --no-check-certificate '#{BASE_URI}/overlay.png' -O public/images/overlay.png" +run "wget --no-check-certificate '#{BASE_URI}/newrelic.yml' -O config/newrelic.yml" +run "wget --no-check-certificate '#{BASE_URI}/rails_admin.rb' -O config/initializers/rails_admin.rb" +run "wget --no-check-certificate '#{BASE_URI}/htaccess' -O public/.htaccess" +run "wget --no-check-certificate '#{BASE_URI}/asset_packages.yml' -O config/asset_packages.yml" +run "wget --no-check-certificate '#{BASE_URI}/evergreen.rb' -O config/evergreen.rb" +run "wget --no-check-certificate '#{BASE_URI}/grid.png' -O public/images/grid.png" +run "wget --no-check-certificate '#{BASE_URI}/html5.js' -O public/javascripts/html5.js" +run "wget --no-check-certificate '#{BASE_URI}/spec_helper.rb' -O spec/spec_helper.rb" +run "wget --no-check-certificate '#{BASE_URI}/application.html' -O spec/javascripts/templates/application.html" +run "wget --no-check-certificate '#{BASE_URI}/application_spec.js' -O spec/javascripts/application_spec.js" +run "wget --no-check-certificate '#{BASE_URI}/spec_helper.js' -O spec/javascripts/spec_helper.js" +run "wget --no-check-certificate '#{BASE_URI}/watchr.rb' -O .watchr" +run "wget --no-check-certificate '#{BASE_URI}/watchr.rake' -O lib/tasks/watchr.rake" +run "wget --no-check-certificate '#{I18N_BASE_URI}/en-US.yml' -O config/locales/en.yml" +run "wget --no-check-certificate '#{I18N_BASE_URI}/pt-BR.yml' -O config/locales/pt-BR.yml" +run "wget http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js -O public/javascripts/jquery.js" +run "wget http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js -O public/javascripts/jquery-ui.js" + +run "chmod u+x build.sh" append_file 'Rakefile', <<-METRIC_FU @@ -70,12 +81,53 @@ Synthesis::AssetPackage.merge_environments = %w(staging production) ASSET_PACKAGER -run "mkdir -p app/coffeescripts spec/javascripts spec/javascripts/templates" -run "chmod u+x build.sh" +remove_file 'README' +create_file 'README', <<-README +== Rails 3 Application + +Install Ruby 1.8.7 or Ruby Enterprise Edition (http://www.rubyenterpriseedition.com). + +To run tests open a Terminal and run: + + spork + +Now open a new Terminal and run: + + rake watchr + +If you want to run the entire Test Suite run: + + rspec spec + +With Thin, instead of 'rails server', you can start the server like this: + + thin start + +README git :init git :add => '.' git :add => 'public/javascripts/rails.js --force' git :commit => '-am "Initial commit"' -puts "SUCCESS!" +puts <<-MSG + +SUCCESS! + +Read the README file and do not forget to change a few things. + +== Spork: + + Ensure you enable class reload within the test environment by changing the + config/environments/test.rb to have: + + config.cache_classes = false + +== Devise: + + Ensure you have defined root_url to *something* in your config/routes.rb. + For example: + + root :to => "home#index" + +MSG diff --git a/rails_admin.rb b/rails_admin.rb deleted file mode 100644 index 110a62f..0000000 --- a/rails_admin.rb +++ /dev/null @@ -1 +0,0 @@ -RailsAdmin.authenticate_with { authenticate_admin! } diff --git a/remarkable.rb b/remarkable.rb deleted file mode 100644 index 83aae44..0000000 --- a/remarkable.rb +++ /dev/null @@ -1 +0,0 @@ -require 'remarkable/active_record'