xrails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010 Alessio Rocco
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ xRails is a base Rails application that you can upgrade.
2
+
3
+ Installation
4
+ ------------
5
+
6
+ First install the xRails gem:
7
+
8
+ gem install xrails
9
+
10
+ Then run:
11
+
12
+ xrails create projectname
13
+
14
+ This will create a Rails 3 app in `projectname'. This script creates a
15
+ new git repository. It is not meant to be used against an existing repo.
16
+
17
+ Gemfile
18
+ -------
19
+
20
+ To see the latest and greatest gems, look at xRails'
21
+ [template/files/xrails_Gemfile](https://github.com/AlessioRocco/xRails/template/files/xrail_Gemfile),
22
+ which will be copied into your projectname/Gemfile.
23
+
24
+ It includes application gems like:
25
+
26
+ * [jQuery](https://github.com/jquery/jquery) for Javascript pleasantry
27
+ * [Will Paginate](https://github.com/mislav/will_paginate) for pagination
28
+
29
+ And testing gems like:
30
+
31
+ * [Cucumber](https://github.com/aslakhellesoy/cucumber-rails) for integration testing
32
+ * [Webrat](https://github.com/brynary/webrat) for acceptance tests
33
+ * [Database Cleaner](https://github.com/bmabey/database_cleaner) for cleaning your database
34
+ * [RSpec](https://github.com/rspec/rspec) for awesome, readable isolation testing
35
+ * [Shoulda](http://github.com/thoughtbot/shoulda) for frequently needed Rails and RSpec matchers
36
+
37
+ Other goodies
38
+ -------------
39
+
40
+ xRails also comes with:
41
+
42
+ * Rails' flashes set up and in application layout.
43
+ * A few nice time formats.
44
+
45
+ See [template/files](https://github.com/AlessioRocco/xRails/template/files) to
46
+ see what is generated one-time.
47
+
48
+ Issues
49
+ ------
50
+
51
+ If you have problems, please create a [Github issue](https://github.com/AlessioRocco/xRails/issues).
52
+
53
+ Credits
54
+ -------
55
+
56
+ This gem is forked by Suspenders:
57
+
58
+ ![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
59
+
60
+ Suspenders is maintained and funded by [thoughtbot, inc](http://thoughtbot.com/community)
61
+
62
+ The names and logos for thoughtbot are trademarks of thoughtbot, inc.
63
+
64
+ License
65
+ -------
66
+
67
+ xRails is Copyright © 2008-2011 Alessio Rocco. It is free software, and may be redistributed under the terms specified in the LICENSE file.
data/Rakefile ADDED
@@ -0,0 +1,102 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'cucumber/rake/task'
4
+ require 'date'
5
+
6
+ XRAILS_GEM_VERSION = '0.1.0'
7
+
8
+ #############################################################################
9
+ #
10
+ # Testing functions
11
+ #
12
+ #############################################################################
13
+
14
+ Cucumber::Rake::Task.new
15
+
16
+ namespace :test do
17
+ desc "A full xrails app's test suite"
18
+ task :full => ['cucumber']
19
+ end
20
+
21
+ desc 'Run the test suite'
22
+ task :default => ['test:full']
23
+
24
+ #############################################################################
25
+ #
26
+ # Helper functions
27
+ #
28
+ #############################################################################
29
+
30
+ def name
31
+ @name ||= Dir['*.gemspec'].first.split('.').first
32
+ end
33
+
34
+ def version
35
+ XRAILS_GEM_VERSION
36
+ end
37
+
38
+ def date
39
+ Date.today.to_s
40
+ end
41
+
42
+ def gemspec_file
43
+ "#{name}.gemspec"
44
+ end
45
+
46
+ def gem_file
47
+ "#{name}-#{version}.gem"
48
+ end
49
+
50
+ def replace_header(head, header_name)
51
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
52
+ end
53
+
54
+ #############################################################################
55
+ #
56
+ # Packaging tasks
57
+ #
58
+ #############################################################################
59
+
60
+ task :release => :build do
61
+ unless `git branch` =~ /^\* master$/
62
+ puts "You must be on the master branch to release!"
63
+ exit!
64
+ end
65
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
66
+ sh "git tag v#{version}"
67
+ sh "git push origin master"
68
+ sh "git push --tags"
69
+ sh "gem push pkg/#{name}-#{version}.gem"
70
+ end
71
+
72
+ task :build => :gemspec do
73
+ sh "mkdir -p pkg"
74
+ sh "gem build #{gemspec_file}"
75
+ sh "mv #{gem_file} pkg"
76
+ end
77
+
78
+ task :gemspec do
79
+ # read spec file and split out manifest section
80
+ spec = File.read(gemspec_file)
81
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
82
+
83
+ # replace name version and date
84
+ replace_header(head, :name)
85
+ replace_header(head, :version)
86
+ replace_header(head, :date)
87
+
88
+ # determine file list from git ls-files
89
+ files = `git ls-files`.
90
+ split("\n").
91
+ sort.
92
+ reject { |file| file =~ /^\./ }.
93
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
94
+ map { |file| " #{file}" }.
95
+ join("\n")
96
+
97
+ # piece file back together and write
98
+ manifest = " s.files = %w[\n#{files}\n ]\n"
99
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
100
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
101
+ puts "Updated #{gemspec_file}"
102
+ end
data/bin/xrails ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/create")
4
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/errors")
5
+
6
+ include XRails::Errors
7
+
8
+ def usage
9
+ "Usage: #{File.basename(__FILE__)} create new_project_name"
10
+ end
11
+
12
+ case ARGV[0]
13
+ when 'create', '--create'
14
+ begin
15
+ XRails::Create.run!(ARGV[1])
16
+ rescue XRails::InvalidInput => e
17
+ error_with_message(e.message)
18
+ end
19
+ when 'help', '--help'
20
+ puts usage
21
+ else
22
+ error_with_message "Unknown subcommand: #{ARGV[0]}\n#{usage}"
23
+ end
@@ -0,0 +1,15 @@
1
+ Feature: Rake works in the suspended project
2
+
3
+ Scenario: Running rake in the suspended project
4
+ Given a new xrails project named "test_project"
5
+ When I create the required databases
6
+ And I run the rake task "cucumber"
7
+ Then I see a successful response in the shell
8
+
9
+ Scenario: Making a spec then running rake
10
+ Given a new xrails project named "test_project"
11
+ When I create the required databases
12
+ And I generate "model post title:string"
13
+ And I run the rake task "db:migrate"
14
+ And I run the rake task "spec"
15
+ Then I see a successful response in the shell
@@ -0,0 +1,28 @@
1
+ Given 'a new xrails project named "$project_name"' do |project_name|
2
+ `rm -rf ./#{project_name}`
3
+ `./bin/xrails create #{project_name}`
4
+ end
5
+
6
+ When 'I run the rake task "$task_name"' do |task_name|
7
+ Dir.chdir('test_project') do
8
+ system("rake #{task_name}")
9
+ end
10
+ end
11
+
12
+ When 'I generate "$generator_with_args"' do |generator_with_args|
13
+ Dir.chdir('test_project') do
14
+ system("rails generate #{generator_with_args}")
15
+ end
16
+ end
17
+
18
+ Then 'I see a successful response in the shell' do
19
+ $?.to_i.should == 0
20
+ end
21
+
22
+ When 'I create the required databases' do
23
+ Dir.chdir('test_project') do
24
+ system("rake db:create")
25
+ system("rake db:migrate")
26
+ system("rake db:test:prepare")
27
+ end
28
+ end
@@ -0,0 +1 @@
1
+
data/lib/create.rb ADDED
@@ -0,0 +1,54 @@
1
+ # Methods needed to create a project.
2
+
3
+ require 'rubygems'
4
+ require File.expand_path(File.dirname(__FILE__) + "/errors")
5
+
6
+ module XRails
7
+ class Create
8
+ attr_accessor :project_path
9
+
10
+ def self.run!(project_path)
11
+ creator = self.new(project_path)
12
+ creator.create_project!
13
+ end
14
+
15
+ def initialize(project_path)
16
+ self.project_path = project_path
17
+ validate_project_path
18
+ validate_project_name
19
+ end
20
+
21
+ def create_project!
22
+ exec(<<-COMMAND)
23
+ rails new #{project_path} \
24
+ --template=#{template} \
25
+ --skip-test-unit \
26
+ --skip-prototype
27
+ COMMAND
28
+ end
29
+
30
+ private
31
+
32
+ def validate_project_name
33
+ project_name = File.basename(project_path)
34
+ unless project_name =~ /^[a-z0-9_]+$/
35
+ raise InvalidInput.new("Project name must only contain [a-z0-9_]")
36
+ end
37
+ end
38
+
39
+ def validate_project_path
40
+ base_directory = Dir.pwd
41
+ full_path = File.join(base_directory, project_path)
42
+
43
+ # This is for the common case for the user's convenience; the race
44
+ # condition can still occur.
45
+ if File.exists?(full_path)
46
+ raise InvalidInput.new("Project directory (#{project_path}) already exists")
47
+ end
48
+ end
49
+
50
+ def template
51
+ File.expand_path(File.dirname(__FILE__) + "/../template/xrails.rb")
52
+ end
53
+ end
54
+ end
data/lib/errors.rb ADDED
@@ -0,0 +1,12 @@
1
+ # User errors
2
+
3
+ module XRails
4
+ class InvalidInput < Exception; end
5
+
6
+ module Errors
7
+ def error_with_message(msg)
8
+ STDERR.puts msg
9
+ exit 1
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ <div id="flash">
2
+ <% flash.each do |key, value| -%>
3
+ <div id="flash_<%= key %>"><%=h value %></div>
4
+ <% end -%>
5
+ </div>
@@ -0,0 +1,17 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem "rails", ">= 3.0.7"
4
+ gem "sqlite3"
5
+ gem "rack"
6
+ gem "will_paginate"
7
+ gem "jquery-rails"
8
+
9
+ # RSpec needs to be in :development group to expose generators
10
+ # and rake tasks without having to type RAILS_ENV=test.
11
+ group :development, :test do
12
+ gem "rspec-rails", "~> 2.4"
13
+ gem "cucumber-rails"
14
+ gem "webrat"
15
+ gem "database_cleaner"
16
+ gem "shoulda"
17
+ end
@@ -0,0 +1,11 @@
1
+ db/schema.rb
2
+ public/system
3
+ *.DS_Store
4
+ coverage/*
5
+ *.swp
6
+ rerun.txt
7
+ tags
8
+ !.keep
9
+ vendor/bundler_gems
10
+ .rvmrc
11
+ .idea
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+
6
+ <title><%= @title ||= "Title" %></title>
7
+ <meta name="description" content="<%= @description ||= "Description" %>" />
8
+ <meta name="keywords" content="<%= @keywords ||= "Keywords"%>" />
9
+
10
+ <link rel="shortcut icon" href="/favicon.ico" />
11
+
12
+ <%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" %>
13
+ <%= stylesheet_link_tag :all %>
14
+ <%= javascript_include_tag 'jquery', 'jquery-ui', 'rails', 'application', :cache => true %>
15
+
16
+ <%= yield :head %>
17
+
18
+ <%= csrf_meta_tag %>
19
+ </head>
20
+ <body>
21
+ <%= render "shared/flashes" %>
22
+
23
+ <%= yield %>
24
+ </body>
25
+ </html>
@@ -0,0 +1,84 @@
1
+ # xRails
2
+ # =============
3
+ # by Alessio Rocco
4
+
5
+ require 'net/http'
6
+ require 'net/https'
7
+
8
+ template_root = File.expand_path(File.join(File.dirname(__FILE__)))
9
+ source_paths << File.join(template_root, "files")
10
+
11
+ # Helpers
12
+
13
+ def concat_file(source, destination)
14
+ contents = IO.read(find_in_source_paths(source))
15
+ append_file destination, contents
16
+ end
17
+
18
+ def replace_in_file(relative_path, find, replace)
19
+ path = File.join(destination_root, relative_path)
20
+ contents = IO.read(path)
21
+ unless contents.gsub!(find, replace)
22
+ raise "#{find.inspect} not found in #{relative_path}"
23
+ end
24
+ File.open(path, "w") { |file| file.write(contents) }
25
+ end
26
+
27
+ def action_mailer_host(rails_env, host)
28
+ inject_into_file(
29
+ "config/environments/#{rails_env}.rb",
30
+ "\n\n config.action_mailer.default_url_options = { :host => '#{host}' }",
31
+ :before => "\nend"
32
+ )
33
+ end
34
+
35
+ def download_file(uri_string, destination)
36
+ uri = URI.parse(uri_string)
37
+ http = Net::HTTP.new(uri.host, uri.port)
38
+ http.use_ssl = true if uri_string =~ /^https/
39
+ request = Net::HTTP::Get.new(uri.path)
40
+ contents = http.request(request).body
41
+ path = File.join(destination_root, destination)
42
+ File.open(path, "w") { |file| file.write(contents) }
43
+ end
44
+
45
+ say "Getting rid of files we don't use"
46
+
47
+ remove_file "README"
48
+ remove_file "public/index.html"
49
+ remove_file "public/images/rails.png"
50
+
51
+ say "Setting up the staging environment"
52
+
53
+ run "cp config/environments/production.rb config/environments/staging.rb"
54
+
55
+ say "Creating xRails views"
56
+
57
+ empty_directory "app/views/shared"
58
+ copy_file "_flashes.html.erb", "app/views/shared/_flashes.html.erb"
59
+ copy_file "xrails_layout.html.erb.erb",
60
+ "app/views/layouts/application.html.erb",
61
+ :force => true
62
+
63
+ say "Get ready for bundler... (this will take a while)"
64
+
65
+ copy_file 'xrails_Gemfile', 'Gemfile', :force => true
66
+ run "bundle install"
67
+
68
+ say "Setting up plugins"
69
+
70
+ generate "jquery:install", "--ui"
71
+ generate "rspec:install"
72
+ generate "cucumber:install", "--rspec --webrat"
73
+
74
+ say "Ignore the right files"
75
+
76
+ concat_file "xrails_gitignore", ".gitignore"
77
+ empty_directory_with_gitkeep "app/models"
78
+ empty_directory_with_gitkeep "db/migrate"
79
+ empty_directory_with_gitkeep "log"
80
+ empty_directory_with_gitkeep "public/images"
81
+ empty_directory_with_gitkeep "spec/support"
82
+
83
+ say "Congratulations! You just pulled our xRails."
84
+
data/xrails.gemspec ADDED
@@ -0,0 +1,52 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
+ s.rubygems_version = '1.6.2'
5
+
6
+ s.name = 'xrails'
7
+ s.version = '0.1.0'
8
+ s.date = '2011-05-10'
9
+
10
+ s.summary = "Generate a Rails app using Alessio Rocco's best practices."
11
+ s.description = <<-HERE
12
+ xRails is a base Rails project that you can upgrade. It is used by
13
+ Alessio Rocco to get a jump start on a working app. Use xRails if you're in a
14
+ rush to build something amazing; don't use it if you like missing deadlines.
15
+ HERE
16
+
17
+ s.authors = ["thoughtbot", "Alessio Rocco"]
18
+ s.email = 'alessio.rocco.lt@gmail.com'
19
+ s.homepage = 'http://github.com/AlessioRocco/xRails'
20
+
21
+ s.executables = ["xrails"]
22
+ s.default_executable = 'xrails'
23
+
24
+ s.rdoc_options = ["--charset=UTF-8"]
25
+ s.extra_rdoc_files = %w[README.md LICENSE]
26
+
27
+ s.add_dependency('rails', '>= 3.0.3')
28
+ s.add_dependency('bundler', '>= 1.0.7')
29
+ s.add_dependency('trout', '>= 0.3.0')
30
+
31
+ # = MANIFEST =
32
+ s.files = %w[
33
+ LICENSE
34
+ README.md
35
+ Rakefile
36
+ bin/xrails
37
+ features/rake_clean.feature
38
+ features/step_definitions/shell.rb
39
+ features/support/env.rb
40
+ lib/create.rb
41
+ lib/errors.rb
42
+ template/files/_flashes.html.erb
43
+ template/files/xrails_Gemfile
44
+ template/files/xrails_gitignore
45
+ template/files/xrails_layout.html.erb.erb
46
+ template/xrails.rb
47
+ xrails.gemspec
48
+ ]
49
+ # = MANIFEST =
50
+
51
+ s.test_files = s.files.select {|path| path =~ /^features/ }
52
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xrails
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - thoughtbot
14
+ - Alessio Rocco
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-05-10 00:00:00 +02:00
20
+ default_executable: xrails
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: rails
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 1
31
+ segments:
32
+ - 3
33
+ - 0
34
+ - 3
35
+ version: 3.0.3
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 25
47
+ segments:
48
+ - 1
49
+ - 0
50
+ - 7
51
+ version: 1.0.7
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: trout
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 19
63
+ segments:
64
+ - 0
65
+ - 3
66
+ - 0
67
+ version: 0.3.0
68
+ type: :runtime
69
+ version_requirements: *id003
70
+ description: |
71
+ xRails is a base Rails project that you can upgrade. It is used by
72
+ Alessio Rocco to get a jump start on a working app. Use xRails if you're in a
73
+ rush to build something amazing; don't use it if you like missing deadlines.
74
+
75
+ email: alessio.rocco.lt@gmail.com
76
+ executables:
77
+ - xrails
78
+ extensions: []
79
+
80
+ extra_rdoc_files:
81
+ - README.md
82
+ - LICENSE
83
+ files:
84
+ - LICENSE
85
+ - README.md
86
+ - Rakefile
87
+ - bin/xrails
88
+ - features/rake_clean.feature
89
+ - features/step_definitions/shell.rb
90
+ - features/support/env.rb
91
+ - lib/create.rb
92
+ - lib/errors.rb
93
+ - template/files/_flashes.html.erb
94
+ - template/files/xrails_Gemfile
95
+ - template/files/xrails_gitignore
96
+ - template/files/xrails_layout.html.erb.erb
97
+ - template/xrails.rb
98
+ - xrails.gemspec
99
+ has_rdoc: true
100
+ homepage: http://github.com/AlessioRocco/xRails
101
+ licenses: []
102
+
103
+ post_install_message:
104
+ rdoc_options:
105
+ - --charset=UTF-8
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ requirements: []
127
+
128
+ rubyforge_project:
129
+ rubygems_version: 1.6.2
130
+ signing_key:
131
+ specification_version: 2
132
+ summary: Generate a Rails app using Alessio Rocco's best practices.
133
+ test_files:
134
+ - features/rake_clean.feature
135
+ - features/step_definitions/shell.rb
136
+ - features/support/env.rb