rails-maker 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +21 -0
- data/README.md +87 -0
- data/bin/rails-maker +16 -0
- data/lib/rails-maker.rb +8 -0
- data/lib/rails-maker/cli.rb +44 -0
- data/lib/rails-maker/errors.rb +11 -0
- data/lib/rails-maker/template_runner.rb +30 -0
- data/lib/rails-maker/version.rb +3 -0
- data/spec/railsmaker_cli_spec.rb +13 -0
- data/spec/railsmaker_template_runner_spec.rb +27 -0
- data/spec/spec_helper.rb +3 -0
- data/templates/default/bootstrap.rb +76 -0
- data/templates/default/default.rb +57 -0
- data/templates/default/lib/admin.rb +29 -0
- data/templates/default/lib/admin/dashboard_spec.rb +24 -0
- data/templates/default/lib/admin/layout.rb +79 -0
- data/templates/default/lib/admin/sass.rb +43 -0
- data/templates/default/lib/admin/users.rb +134 -0
- data/templates/default/lib/admin/users_spec.rb +31 -0
- data/templates/default/lib/application_layout.rb +118 -0
- data/templates/default/lib/authentication.rb +165 -0
- data/templates/default/lib/authorization.rb +112 -0
- data/templates/default/lib/css.rb +53 -0
- data/templates/default/lib/db.rb +2 -0
- data/templates/default/lib/db_seed.rb +1 -0
- data/templates/default/lib/gemfile.rb +73 -0
- data/templates/default/lib/haml_generator.rb +13 -0
- data/templates/default/lib/home_controller.rb +10 -0
- data/templates/default/lib/initializers.rb +0 -0
- data/templates/default/lib/rails_clean.rb +12 -0
- data/templates/default/lib/test_suite.rb +11 -0
- metadata +205 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010-2011 Quick Left
|
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,87 @@
|
|
1
|
+
The rails-maker
|
2
|
+
===========
|
3
|
+
Generate a Rails 3 app with the application templates Quick Left uses to start their projects off right!
|
4
|
+
|
5
|
+
|
6
|
+
### What you get
|
7
|
+
|
8
|
+
The rails-maker provides a set of templates to generate Rails 3 applications.
|
9
|
+
Everything is configured and ready to rock your next Rails 3 project.
|
10
|
+
We hope it saves you a mess of time!
|
11
|
+
|
12
|
+
* Default: A base Rails 3 application with Devise and Cancan for
|
13
|
+
authentication and authorization. Roles are stored in the database
|
14
|
+
with a HABTM relationship between the role and user models. You also get
|
15
|
+
a basic admin to manage users. The rails-maker also rolls in all of the things
|
16
|
+
we like to have setup in our apps like: haml, sass, jquery, cucumber,
|
17
|
+
capybara, mocha, factory_girl, rspec, timecop, autotest, evergreen,
|
18
|
+
jasmine, will_paginate, friendly_id and hoptoad_notifier.
|
19
|
+
|
20
|
+
rails-maker new my_app
|
21
|
+
rails-maker new my_app default
|
22
|
+
|
23
|
+
* Async: A Rails 3 application with the basic setup complete for running
|
24
|
+
fully async on the Thin web server. Included gems are thin,
|
25
|
+
rack-fiber_pool, mysql2, and rspec.
|
26
|
+
|
27
|
+
rails-maker new my_app async
|
28
|
+
|
29
|
+
|
30
|
+
### Quick Start
|
31
|
+
|
32
|
+
gem install rails-maker
|
33
|
+
|
34
|
+
rails-maker new my_app
|
35
|
+
|
36
|
+
|
37
|
+
### Options ( in default template )
|
38
|
+
|
39
|
+
rails-maker new my_app --no-auth
|
40
|
+
|
41
|
+
rails-maker new my_app --no-roles
|
42
|
+
|
43
|
+
rails-maker new my_app --no-admin
|
44
|
+
|
45
|
+
|
46
|
+
### Testing generated default app
|
47
|
+
|
48
|
+
rake spec
|
49
|
+
rake cucumber
|
50
|
+
rake spec:javascripts
|
51
|
+
bundle exec autotest
|
52
|
+
|
53
|
+
|
54
|
+
### Issues
|
55
|
+
|
56
|
+
Please report issues to the [the rails-maker issue tracker](http://github.com/koteus/rails-maker/issues/).
|
57
|
+
|
58
|
+
|
59
|
+
### Development
|
60
|
+
|
61
|
+
bundle install
|
62
|
+
bundle exec cucumber
|
63
|
+
|
64
|
+
Running `bundle exec cucumber` will take some time. It runs the CLI tool with different option combinations and tests
|
65
|
+
those outputs with aruba.
|
66
|
+
|
67
|
+
|
68
|
+
### Patches/Pull Requests
|
69
|
+
|
70
|
+
* Fork it.
|
71
|
+
* Add tests for it.
|
72
|
+
* Make your changes.
|
73
|
+
* Commit.
|
74
|
+
* Send a pull request.
|
75
|
+
|
76
|
+
|
77
|
+
### Thanks
|
78
|
+
|
79
|
+
All of the contributors to the many awesome open source projects that make up rails-maker and allow us to do our job everyday.
|
80
|
+
Also, thanks go out to the crew at thoughtbot for writing suspenders. It's what gave us the idea to package up our
|
81
|
+
templates into a gem in the first place.
|
82
|
+
|
83
|
+
|
84
|
+
### Copyright
|
85
|
+
|
86
|
+
Copyright (c) 2010-2011 Collin Schaafsma & Quick Left. See LICENSE for details.
|
87
|
+
|
data/bin/rails-maker
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Requires
|
4
|
+
begin
|
5
|
+
require 'rails-maker'
|
6
|
+
rescue LoadError
|
7
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
|
8
|
+
require 'rubygems'
|
9
|
+
require 'rails-maker'
|
10
|
+
end
|
11
|
+
|
12
|
+
# Setup Constants
|
13
|
+
RailsMaker::GEM_ROOT = File.expand_path( File.dirname( __FILE__ ) + '/../' )
|
14
|
+
|
15
|
+
# Run
|
16
|
+
RailsMaker::CLI.start(ARGV)
|
data/lib/rails-maker.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'thor/actions'
|
3
|
+
|
4
|
+
module RailsMaker
|
5
|
+
|
6
|
+
class CLI < Thor
|
7
|
+
|
8
|
+
include Thor::Actions
|
9
|
+
|
10
|
+
desc 'new [app]', 'Create a new Rails application'
|
11
|
+
long_desc <<-D
|
12
|
+
The rails-maker will ask you a few questions to determine what features you
|
13
|
+
would like to generate. Based on your answers it will setup a new Rails application.
|
14
|
+
D
|
15
|
+
|
16
|
+
def new(project, template_name = 'default')
|
17
|
+
|
18
|
+
# Require the template runner
|
19
|
+
require "#{RailsMaker::GEM_ROOT}/templates/#{template_name}/#{template_name}.rb"
|
20
|
+
|
21
|
+
# Invoke the template runner
|
22
|
+
# invoke "RailsMaker:Templates:#{template_name}:on_invocation"
|
23
|
+
# invoke RailsMaker::Templates::Default.on_invocation
|
24
|
+
|
25
|
+
# Execute the template
|
26
|
+
exec(<<-COMMAND)
|
27
|
+
rails new #{project} \
|
28
|
+
--template=#{RailsMaker::GEM_ROOT}/templates/#{template_name}/bootstrap.rb \
|
29
|
+
--skip-test-unit \
|
30
|
+
--skip-prototype
|
31
|
+
COMMAND
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'version', "Prints the rails-maker's version information"
|
36
|
+
def version
|
37
|
+
say "The rails-maker version #{RailsMaker::VERSION}"
|
38
|
+
end
|
39
|
+
map %w(-v --version) => :version
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'thor/actions'
|
3
|
+
require 'thor/group'
|
4
|
+
|
5
|
+
module RailsMaker
|
6
|
+
|
7
|
+
class TemplateRunner < Thor::Group
|
8
|
+
|
9
|
+
# Define the Standard Arguments in any base template class
|
10
|
+
def self.extended(base)
|
11
|
+
base.class_eval do
|
12
|
+
argument :project, :type => :string
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Includes
|
17
|
+
include Thor::Actions
|
18
|
+
|
19
|
+
# The method to run when the template is invoked. This is used to
|
20
|
+
# parse custom options from the command line or complete any other
|
21
|
+
# setup prior to invoking the system command that will construct
|
22
|
+
# the project.
|
23
|
+
def on_invocation
|
24
|
+
raise RailsMaker::Errors::TemplateRunnerInvocationNotImplementedError.new("Template did not define an on_invocation method!")
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TestTemplate1 < ::RailsMaker::TemplateRunner
|
4
|
+
def on_invocation
|
5
|
+
return "hi"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class TestTemplate2 < ::RailsMaker::TemplateRunner
|
10
|
+
end
|
11
|
+
|
12
|
+
describe RailsMaker::TemplateRunner do
|
13
|
+
|
14
|
+
it "should not raise an error if the on_invocation method is implemented" do
|
15
|
+
lambda {
|
16
|
+
TestTemplate1.new.on_invocation
|
17
|
+
}.should_not raise_error
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise an error if the on_invocation method isn't implemented" do
|
21
|
+
lambda {
|
22
|
+
TestTemplate2.new.on_invocation
|
23
|
+
}.should raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "net/https"
|
3
|
+
require "uri"
|
4
|
+
require 'rbconfig'
|
5
|
+
|
6
|
+
say "Building Application with the rails-maker..."
|
7
|
+
|
8
|
+
def get_remote_https_file(source, destination)
|
9
|
+
uri = URI.parse(source)
|
10
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
11
|
+
http.use_ssl = true
|
12
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
13
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
14
|
+
response = http.request(request)
|
15
|
+
path = File.join(destination_root, destination)
|
16
|
+
File.open(path, "w") { |file| file.write(response.body) }
|
17
|
+
end
|
18
|
+
|
19
|
+
git :init
|
20
|
+
|
21
|
+
run 'rm .gitignore'
|
22
|
+
create_file '.gitignore' do
|
23
|
+
<<-FILE
|
24
|
+
.bundle
|
25
|
+
.DS_Store
|
26
|
+
log/*.log
|
27
|
+
tmp/**/*
|
28
|
+
config/database.yml
|
29
|
+
db/*.sqlite3
|
30
|
+
public/system/**/**/**/*
|
31
|
+
.idea/*
|
32
|
+
.sass-cache/**/*
|
33
|
+
*.swp
|
34
|
+
public/uploads
|
35
|
+
FILE
|
36
|
+
end
|
37
|
+
|
38
|
+
files = %w{
|
39
|
+
gemfile
|
40
|
+
haml_generator
|
41
|
+
rails_clean
|
42
|
+
application_layout
|
43
|
+
home_controller
|
44
|
+
css
|
45
|
+
test_suite
|
46
|
+
authentication
|
47
|
+
authorization
|
48
|
+
admin
|
49
|
+
db
|
50
|
+
db_seed
|
51
|
+
}
|
52
|
+
|
53
|
+
files.each do |file|
|
54
|
+
apply File.expand_path("../lib/#{file}.rb", __FILE__)
|
55
|
+
end
|
56
|
+
|
57
|
+
login_msg = (ENV['RAILSMAKER_ADMIN']) ? "Login to admin with email #{ENV['RAILSMAKER_USER_EMAIL']} and password #{ENV['RAILSMAKER_USER_PASSWORD']}" : ""
|
58
|
+
|
59
|
+
say <<-D
|
60
|
+
|
61
|
+
|
62
|
+
########################################################################
|
63
|
+
|
64
|
+
The rails-maker just added like 6 hours to your life.
|
65
|
+
|
66
|
+
Template Installed :: Default
|
67
|
+
|
68
|
+
Next run...
|
69
|
+
|
70
|
+
rake spec
|
71
|
+
rails s
|
72
|
+
|
73
|
+
#{login_msg}
|
74
|
+
|
75
|
+
########################################################################
|
76
|
+
D
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module RailsMaker
|
2
|
+
|
3
|
+
module Templates
|
4
|
+
|
5
|
+
class Default < RailsMaker::TemplateRunner
|
6
|
+
|
7
|
+
# Class Options
|
8
|
+
# @see https://github.com/wycats/thor/wiki/Groups
|
9
|
+
class_option :auth , :type => :boolean , :default => true , :banner => "Sets up devise for authentication."
|
10
|
+
class_option :roles , :type => :boolean , :default => true , :banner => "Sets up cancan for authorization with rolify."
|
11
|
+
class_option :admin , :type => :boolean , :default => true , :banner => "Sets up very basic admin"
|
12
|
+
|
13
|
+
# Descriptions
|
14
|
+
desc "Runs the default rails-maker Rails stack task"
|
15
|
+
|
16
|
+
# The method to run when the template is invoked
|
17
|
+
def on_invocation
|
18
|
+
|
19
|
+
# Dup our options so we can modify them
|
20
|
+
opts = options.dup
|
21
|
+
|
22
|
+
# Can't build an admin or roles without devise
|
23
|
+
unless opts[:auth]
|
24
|
+
opts[:admin] = false
|
25
|
+
opts[:roles] = false
|
26
|
+
end
|
27
|
+
|
28
|
+
# Env vars used in our template
|
29
|
+
ENV['RAILSMAKER_AUTH'] = "true" if opts[:auth]
|
30
|
+
ENV['RAILSMAKER_ADMIN'] = "true" if opts[:admin]
|
31
|
+
ENV['RAILSMAKER_ROLES'] = "true" if opts[:roles]
|
32
|
+
ENV['RAILSMAKER_USER_NAME'] = git_user_name if opts[:admin]
|
33
|
+
ENV['RAILSMAKER_USER_EMAIL'] = git_user_email if opts[:admin]
|
34
|
+
ENV['RAILSMAKER_USER_PASSWORD'] = user_password if opts[:admin]
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def git_user_name
|
41
|
+
`git config --global user.name`.chomp.gsub('"', '\"') || 'admin'
|
42
|
+
end
|
43
|
+
|
44
|
+
def git_user_email
|
45
|
+
`git config --global user.email`.chomp || 'admin@ikitlab.com'
|
46
|
+
end
|
47
|
+
|
48
|
+
def user_password
|
49
|
+
'admin123'
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
say "Building admin"
|
2
|
+
generate(:controller, "admin/dashboard index")
|
3
|
+
route("match 'admin' => 'admin/dashboard#index'")
|
4
|
+
|
5
|
+
# Do layout and SASS stuff
|
6
|
+
apply File.expand_path("../admin/sass.rb", __FILE__)
|
7
|
+
apply File.expand_path("../admin/layout.rb", __FILE__)
|
8
|
+
|
9
|
+
create_file 'app/controllers/admin/base_controller.rb' do
|
10
|
+
<<-RUBY
|
11
|
+
class Admin::BaseController < ApplicationController
|
12
|
+
layout 'admin'
|
13
|
+
before_filter :authenticate_user!
|
14
|
+
before_filter :verify_admin
|
15
|
+
|
16
|
+
private
|
17
|
+
def verify_admin
|
18
|
+
redirect_to root_url unless current_user.role? :admin
|
19
|
+
end
|
20
|
+
end
|
21
|
+
RUBY
|
22
|
+
end
|
23
|
+
|
24
|
+
gsub_file 'app/controllers/admin/dashboard_controller.rb', /ApplicationController/, 'Admin::BaseController'
|
25
|
+
|
26
|
+
# make a user admin
|
27
|
+
apply File.expand_path("../admin/users.rb", __FILE__)
|
28
|
+
apply File.expand_path("../admin/dashboard_spec.rb", __FILE__)
|
29
|
+
apply File.expand_path("../admin/users_spec.rb", __FILE__)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
run 'rm spec/controllers/admin/dashboard_controller_spec.rb'
|
2
|
+
|
3
|
+
create_file 'spec/controllers/admin/dashboard_controller_spec.rb' do
|
4
|
+
<<-'FILE'
|
5
|
+
require 'spec_helper'
|
6
|
+
include Devise::TestHelpers
|
7
|
+
|
8
|
+
describe Admin::DashboardController do
|
9
|
+
before(:each) do
|
10
|
+
@user = @user ||=Factory.create(:admin)
|
11
|
+
sign_in @user
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "GET 'index'" do
|
15
|
+
it "should be successful" do
|
16
|
+
get 'index'
|
17
|
+
response.should be_success
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
FILE
|
24
|
+
end
|