bnr_generator 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +58 -0
- data/Rakefile +2 -0
- data/bin/bnr +4 -0
- data/bin/highgroove +4 -0
- data/bnr-generator.gemspec +21 -0
- data/lib/bnr-generator/version.rb +5 -0
- data/lib/bnr_command.rb +133 -0
- data/lib/templates/README.md +63 -0
- data/lib/templates/application.css.scss +6 -0
- data/lib/templates/application.js.coffee +4 -0
- data/lib/templates/home_controller.rb +4 -0
- data/lib/templates/index.slim +1 -0
- data/lib/templates/layout.html.slim +44 -0
- data/lib/templates/routes.rb.erb +3 -0
- metadata +103 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Aubrey Rhodes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# BNR-Generator
|
2
|
+
|
3
|
+
Generate Rails projects the way we like them.
|
4
|
+
|
5
|
+
## Dependencies
|
6
|
+
|
7
|
+
The capybara-webkit gem which the generator installs dependes on QT
|
8
|
+
being installed. On OSX with Hombrew run ```brew install qt``` to make
|
9
|
+
sure QT is installed.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
```bash
|
14
|
+
gem install bnr_generator
|
15
|
+
|
16
|
+
# if you are using rbenv
|
17
|
+
rbenv rehash
|
18
|
+
```
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```bash
|
23
|
+
# create a new project
|
24
|
+
bnr new NAME
|
25
|
+
|
26
|
+
# specify the database type
|
27
|
+
bnr new NAME --database=DATABASE
|
28
|
+
|
29
|
+
# Don't create a heroku app
|
30
|
+
bnr new NAME --host=none
|
31
|
+
|
32
|
+
# Don't use rvm
|
33
|
+
bnr new NAME --ruby=none
|
34
|
+
|
35
|
+
# get help, see all options
|
36
|
+
bnr help
|
37
|
+
```
|
38
|
+
|
39
|
+
## What's included?
|
40
|
+
- [Rails](http://rubyonrails.org/) of course, currently the 3.2 branch
|
41
|
+
- [Postgres](http://www.postgresql.org/) all your database needs
|
42
|
+
- [Heroku](http://www.heroku.com/) for deployment ease, a Heroku app will automatically be created for you.
|
43
|
+
- [Slim](http://slim-lang.com/) for templating goodness
|
44
|
+
|
45
|
+
### The testing stack includes :
|
46
|
+
- [RSpec](https://github.com/rspec/rspec-rails/) for Behaviour-Driven Development
|
47
|
+
- [Factory Girl](https://github.com/thoughtbot/factory_girl), a fixtures replacement for generating test data
|
48
|
+
- [Forgery](https://github.com/sevenwire/forgery) for creating fake test data
|
49
|
+
- [Capybara-Webkit](https://github.com/thoughtbot/capybara-webkit) for integration testing with javascript
|
50
|
+
- [SimpleCov](https://github.com/colszowka/simplecov) for test coverage reporting
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/bnr
ADDED
data/bin/highgroove
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/bnr-generator/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Aubrey Rhodes"]
|
6
|
+
gem.email = ["aubrey@bignerdranch.com"]
|
7
|
+
gem.description = %q{Tool to generate a rails project ready for development}
|
8
|
+
gem.summary = %q{Big Nerd Ranch rails project generator}
|
9
|
+
gem.homepage = "http://github.com/bignerdranch/bnr-generator"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "bnr_generator"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Bnr::Generator::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "rails", '>= 3.2.0'
|
19
|
+
gem.add_dependency "thor"
|
20
|
+
gem.add_dependency "heroku"
|
21
|
+
end
|
data/lib/bnr_command.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "active_support/inflector"
|
3
|
+
|
4
|
+
class BnrCommand < Thor
|
5
|
+
include Thor::Actions
|
6
|
+
|
7
|
+
desc "new NAME", "Generates a new project with the given name"
|
8
|
+
method_option :database, type: :string, default: 'postgresql', aliases: '-d'
|
9
|
+
method_option :host, type: :string, default: 'heroku', aliases: '-h',
|
10
|
+
desc: 'Hosting to set up for this app. Values can be: heroku, none.'
|
11
|
+
method_option :ruby, type: :string, default: 'rvm', aliases: '-r',
|
12
|
+
desc: 'Ruby version manager to use. Values can be: rvm, none.'
|
13
|
+
def new(name)
|
14
|
+
@name = name
|
15
|
+
run "rails new #{name} --skip-bundle -T -q -d #{options[:database]}"
|
16
|
+
inside name do
|
17
|
+
run "git init -q"
|
18
|
+
gsub_file "Gemfile", /^ *#.*$/, ''
|
19
|
+
gsub_file "Gemfile", /^ *$\n/, ''
|
20
|
+
append_to_file "Gemfile" do
|
21
|
+
<<-EOF
|
22
|
+
gem 'slim'
|
23
|
+
gem 'slim-rails'
|
24
|
+
gem 'bootstrap-sass', '~> 2.0.4.0'
|
25
|
+
group :test, :development do
|
26
|
+
gem 'rspec-rails'
|
27
|
+
gem 'factory_girl_rails'
|
28
|
+
gem 'forgery'
|
29
|
+
gem 'heroku'
|
30
|
+
end
|
31
|
+
group :test do
|
32
|
+
gem 'capybara'
|
33
|
+
gem 'launchy'
|
34
|
+
gem 'database_cleaner'
|
35
|
+
gem 'capybara-webkit'
|
36
|
+
gem 'simplecov'
|
37
|
+
end
|
38
|
+
EOF
|
39
|
+
end
|
40
|
+
if options[:ruby] == 'rvm'
|
41
|
+
run "rvm 1.9.3-p125 do rvm --rvmrc --create 1.9.3-p125@#{name}"
|
42
|
+
end
|
43
|
+
rvm_run "gem install bundler"
|
44
|
+
rvm_run "bundle install --quiet"
|
45
|
+
rvm_run "rails g rspec:install"
|
46
|
+
rvm_run "rails g forgery"
|
47
|
+
insert_into_file 'spec/spec_helper.rb', "\nrequire 'capybara/rspec'", after: "require 'rspec/autorun'"
|
48
|
+
gsub_file 'spec/spec_helper.rb', / *# Remove this[^\n]*\n *config\.fixture_path[^\n]*\n\n/m, ''
|
49
|
+
gsub_file 'spec/spec_helper.rb', /config.use_transactional_fixtures = true/, 'config.use_transactional_fixtures = false'
|
50
|
+
insert_into_file 'spec/spec_helper.rb', after: "config.infer_base_class_for_anonymous_controllers = false\n" do
|
51
|
+
<<-EOF
|
52
|
+
|
53
|
+
config.before(:suite) do
|
54
|
+
DatabaseCleaner.strategy = :truncation
|
55
|
+
end
|
56
|
+
|
57
|
+
config.before(:each) do
|
58
|
+
DatabaseCleaner.start
|
59
|
+
end
|
60
|
+
|
61
|
+
config.after(:each) do
|
62
|
+
DatabaseCleaner.clean
|
63
|
+
end
|
64
|
+
EOF
|
65
|
+
end
|
66
|
+
append_to_file 'spec/spec_helper.rb', "\nCapybara.javascript_driver = :webkit\n"
|
67
|
+
prepend_to_file 'spec/spec_helper.rb' do
|
68
|
+
<<-EOF
|
69
|
+
require 'simplecov'
|
70
|
+
SimpleCov.start
|
71
|
+
|
72
|
+
EOF
|
73
|
+
end
|
74
|
+
append_to_file '.gitignore', "\ncoverage\n.rvmrc"
|
75
|
+
remove_file 'public/index.html'
|
76
|
+
remove_file 'README.rdoc'
|
77
|
+
remove_file 'doc/README_FOR_APP'
|
78
|
+
gsub_file 'config/database.yml', /username: .*$/, 'username:'
|
79
|
+
rvm_run 'rake db:create'
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
# Layout file
|
84
|
+
remove_file "#{name}/app/views/layouts/application.html.erb"
|
85
|
+
copy_file "templates/layout.html.slim", "#{name}/app/views/layouts/application.html.slim"
|
86
|
+
|
87
|
+
# Remove css and js application files
|
88
|
+
remove_file "#{name}/app/assets/javascripts/application.js"
|
89
|
+
remove_file "#{name}/app/assets/stylesheets/application.css"
|
90
|
+
copy_file "templates/application.js.coffee", "#{name}/app/assets/javascripts/application.js.coffee"
|
91
|
+
copy_file "templates/application.css.scss", "#{name}/app/assets/stylesheets/application.css.scss"
|
92
|
+
|
93
|
+
copy_file "templates/README.md", "#{name}/README.md"
|
94
|
+
copy_file "templates/home_controller.rb", "#{name}/app/controllers/home_controller.rb"
|
95
|
+
copy_file "templates/index.slim", "#{name}/app/views/home/index.slim"
|
96
|
+
remove_file "#{name}/config/routes.rb"
|
97
|
+
template "templates/routes.rb.erb", "#{name}/config/routes.rb"
|
98
|
+
|
99
|
+
inside name do
|
100
|
+
rvm_run 'rake db:migrate'
|
101
|
+
rvm_run 'git add .'
|
102
|
+
rvm_run 'git commit -m "Initial Commit"'
|
103
|
+
if options[:host] == 'heroku'
|
104
|
+
rvm_run "heroku apps:create #{heroku_name(name)} -s cedar"
|
105
|
+
rvm_run 'git push heroku master'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
desc "destroy NAME", "Destroys an app that was generated by the new action"
|
112
|
+
def destroy(name)
|
113
|
+
rvm_run "heroku apps:destroy #{heroku_name(name)} --confirm #{heroku_name(name)}"
|
114
|
+
remove_dir name
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.source_root
|
118
|
+
File.dirname(__FILE__)
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
def rvm_run(command, config = {})
|
124
|
+
if options[:ruby] == 'rvm'
|
125
|
+
command = "rvm 1.9.3-p125@#{@name} do " + command
|
126
|
+
end
|
127
|
+
run command, config
|
128
|
+
end
|
129
|
+
|
130
|
+
def heroku_name(name)
|
131
|
+
name.gsub(/[^a-z0-9\-]/, '')
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# <Project Name>
|
2
|
+
|
3
|
+
## Getting Setup
|
4
|
+
|
5
|
+
```bash
|
6
|
+
# Checkout the repo
|
7
|
+
git clone git@github.com:highgroove/<project>.git
|
8
|
+
|
9
|
+
# Install rvm and create a gemset
|
10
|
+
rvm install 1.9.2 && rvm gemset create <project>
|
11
|
+
|
12
|
+
# Install gem dependencies
|
13
|
+
gem install bundler
|
14
|
+
bundle install
|
15
|
+
|
16
|
+
# Install other dependencies
|
17
|
+
# ex: brew install <list dependencies here. e.g. postgres, redis, etc.>
|
18
|
+
|
19
|
+
# Get the database ready
|
20
|
+
# ex: bundle exec rake db:create:all db:schema:load db:test:prepare
|
21
|
+
|
22
|
+
# Start the app and other processes some how e.g. `bundle exec foreman start`
|
23
|
+
|
24
|
+
# setup other services like Solr, Redis, etc...
|
25
|
+
```
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
When making changes to files, make sure that your changes are consistent with
|
30
|
+
the existing style of the file. For Ruby files, these will typically follow the
|
31
|
+
Github Ruby Styleguide:
|
32
|
+
|
33
|
+
* https://github.com/styleguide/ruby
|
34
|
+
|
35
|
+
### Database setup
|
36
|
+
|
37
|
+
For example:
|
38
|
+
|
39
|
+
Grab the production database
|
40
|
+
|
41
|
+
```bash
|
42
|
+
heroku pgbackups:capture --expire
|
43
|
+
curl -o latest.dump `heroku pgbackups:url`
|
44
|
+
pg_restore -h localhost --verbose --clean --no-acl --no-owner -d
|
45
|
+
<project>_development latest.dump
|
46
|
+
rm latest.dump
|
47
|
+
```
|
48
|
+
|
49
|
+
|
50
|
+
### Testing
|
51
|
+
|
52
|
+
Explain how to run the test-suite here
|
53
|
+
|
54
|
+
## Production
|
55
|
+
|
56
|
+
* Explain how to deploy here
|
57
|
+
* Explain any addons required (for example Heroku addons)
|
58
|
+
* Explain external services being used e.g. Mailchimp, Mandrill, NewRelic, etc.
|
59
|
+
|
60
|
+
## Architecture
|
61
|
+
|
62
|
+
* List any salient architecture notes. This should be super high-level but
|
63
|
+
explain to future devs how things fit together
|
@@ -0,0 +1 @@
|
|
1
|
+
h1 Hello World!
|
@@ -0,0 +1,44 @@
|
|
1
|
+
doctype html
|
2
|
+
html lang="en"
|
3
|
+
head
|
4
|
+
meta charset="utf-8"
|
5
|
+
meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"
|
6
|
+
meta name="viewport" content="width=device-width, initial-scale=1.0"
|
7
|
+
title Highgroove generator generated site
|
8
|
+
= csrf_meta_tags
|
9
|
+
|
10
|
+
= stylesheet_link_tag "application", :media => "all"
|
11
|
+
= javascript_include_tag "application"
|
12
|
+
|
13
|
+
body
|
14
|
+
.navbar.navbar-fixed-top
|
15
|
+
.navbar-inner
|
16
|
+
.container
|
17
|
+
a.btn.btn-navbar data-target=".nav-collapse" data-toggle="collapse"
|
18
|
+
span.icon-bar
|
19
|
+
span.icon-bar
|
20
|
+
span.icon-bar
|
21
|
+
a.brand href="#" Home
|
22
|
+
.container.nav-collapse
|
23
|
+
ul.nav
|
24
|
+
li= link_to "Link 1", "/path1"
|
25
|
+
li= link_to "Link 2", "/path2"
|
26
|
+
li= link_to "Link 3", "/path3"
|
27
|
+
|
28
|
+
.container
|
29
|
+
|
30
|
+
.content
|
31
|
+
.row
|
32
|
+
.span9
|
33
|
+
= yield
|
34
|
+
.span3
|
35
|
+
.well.sidebar-nav
|
36
|
+
h3 Sidebar
|
37
|
+
ul.nav.nav-list
|
38
|
+
li.nav-header Sidebar
|
39
|
+
li= link_to "Link 1", "/path1"
|
40
|
+
li= link_to "Link 2", "/path2"
|
41
|
+
li= link_to "Link 3", "/path3"
|
42
|
+
|
43
|
+
footer
|
44
|
+
p © 2012
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bnr_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Aubrey Rhodes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &70323252778340 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70323252778340
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: thor
|
27
|
+
requirement: &70323252777060 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70323252777060
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: heroku
|
38
|
+
requirement: &70323252774800 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70323252774800
|
47
|
+
description: Tool to generate a rails project ready for development
|
48
|
+
email:
|
49
|
+
- aubrey@bignerdranch.com
|
50
|
+
executables:
|
51
|
+
- bnr
|
52
|
+
- highgroove
|
53
|
+
extensions: []
|
54
|
+
extra_rdoc_files: []
|
55
|
+
files:
|
56
|
+
- .gitignore
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- bin/bnr
|
62
|
+
- bin/highgroove
|
63
|
+
- bnr-generator.gemspec
|
64
|
+
- lib/bnr-generator/version.rb
|
65
|
+
- lib/bnr_command.rb
|
66
|
+
- lib/templates/README.md
|
67
|
+
- lib/templates/application.css.scss
|
68
|
+
- lib/templates/application.js.coffee
|
69
|
+
- lib/templates/home_controller.rb
|
70
|
+
- lib/templates/index.slim
|
71
|
+
- lib/templates/layout.html.slim
|
72
|
+
- lib/templates/routes.rb.erb
|
73
|
+
homepage: http://github.com/bignerdranch/bnr-generator
|
74
|
+
licenses: []
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
hash: 3966409057458233289
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
hash: 3966409057458233289
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.8.15
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Big Nerd Ranch rails project generator
|
103
|
+
test_files: []
|