rails_apps_composer 1.0.0
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/README.textile +313 -0
- data/bin/rails_apps_composer +7 -0
- data/lib/rails_wizard.rb +10 -0
- data/lib/rails_wizard/command.rb +79 -0
- data/lib/rails_wizard/config.rb +86 -0
- data/lib/rails_wizard/recipe.rb +106 -0
- data/lib/rails_wizard/recipes.rb +38 -0
- data/lib/rails_wizard/template.rb +58 -0
- data/recipes/action_mailer.rb +41 -0
- data/recipes/activerecord.rb +37 -0
- data/recipes/add_user.rb +87 -0
- data/recipes/add_user_name.rb +74 -0
- data/recipes/application_layout.rb +45 -0
- data/recipes/ban_spiders.rb +27 -0
- data/recipes/capybara.rb +34 -0
- data/recipes/cleanup.rb +36 -0
- data/recipes/css_setup.rb +42 -0
- data/recipes/cucumber.rb +62 -0
- data/recipes/devise.rb +76 -0
- data/recipes/devise_navigation.rb +93 -0
- data/recipes/env_yaml.rb +54 -0
- data/recipes/git.rb +38 -0
- data/recipes/haml.rb +23 -0
- data/recipes/heroku.rb +58 -0
- data/recipes/home_page.rb +45 -0
- data/recipes/home_page_users.rb +47 -0
- data/recipes/hoptoad.rb +34 -0
- data/recipes/jammit.rb +43 -0
- data/recipes/jquery.rb +70 -0
- data/recipes/less.rb +12 -0
- data/recipes/mongo_mapper.rb +18 -0
- data/recipes/mongohq.rb +59 -0
- data/recipes/mongoid.rb +39 -0
- data/recipes/mootools.rb +23 -0
- data/recipes/navigation.rb +68 -0
- data/recipes/omniauth.rb +152 -0
- data/recipes/omniauth_email.rb +82 -0
- data/recipes/pow.rb +12 -0
- data/recipes/prototype.rb +11 -0
- data/recipes/rails_admin.rb +21 -0
- data/recipes/redis.rb +17 -0
- data/recipes/redistogo.rb +40 -0
- data/recipes/rightjs.rb +17 -0
- data/recipes/rspec.rb +112 -0
- data/recipes/sass.rb +13 -0
- data/recipes/seed_database.rb +42 -0
- data/recipes/sequel.rb +13 -0
- data/recipes/settingslogic.rb +43 -0
- data/recipes/slim.rb +11 -0
- data/recipes/test_unit.rb +11 -0
- data/recipes/users_page.rb +103 -0
- data/spec/rails_wizard/config_spec.rb +99 -0
- data/spec/rails_wizard/recipe_spec.rb +103 -0
- data/spec/rails_wizard/recipes/sanity_spec.rb +30 -0
- data/spec/rails_wizard/recipes_spec.rb +24 -0
- data/spec/rails_wizard/template_spec.rb +48 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/support/rails_directory.rb +17 -0
- data/spec/support/template_runner.rb +28 -0
- data/templates/helpers.erb +45 -0
- data/templates/layout.erb +69 -0
- data/templates/recipe.erb +10 -0
- data/version.rb +3 -0
- metadata +206 -0
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'rails_wizard/config'
|
2
|
+
|
3
|
+
require 'active_support/inflector'
|
4
|
+
require 'yaml'
|
5
|
+
require 'erb'
|
6
|
+
|
7
|
+
module RailsWizard
|
8
|
+
class Recipe
|
9
|
+
extend Comparable
|
10
|
+
|
11
|
+
def self.<=>(another)
|
12
|
+
return -1 if another.run_after.include?(self.key) || self.run_before.include?(another.key)
|
13
|
+
return 1 if another.run_before.include?(self.key) || self.run_after.include?(another.key)
|
14
|
+
self.key <=> another.key
|
15
|
+
end
|
16
|
+
|
17
|
+
ATTRIBUTES = %w(key args category name description template config exclusive tags run_before run_after requires)
|
18
|
+
DEFAULT_ATTRIBUTES = {
|
19
|
+
:category => 'other',
|
20
|
+
:args => [],
|
21
|
+
:tags => [],
|
22
|
+
:run_after => [],
|
23
|
+
:run_before => [],
|
24
|
+
:requires => []
|
25
|
+
}
|
26
|
+
|
27
|
+
def self.generate(key, template_or_file, attributes = {})
|
28
|
+
if template_or_file.respond_to?(:read)
|
29
|
+
file = template_or_file.read
|
30
|
+
parts = file.split(/^__END__$/)
|
31
|
+
raise ArgumentError, "The recipe file must have YAML matter after an __END__" unless parts.size == 2
|
32
|
+
template = parts.first.strip
|
33
|
+
attributes = YAML.load(parts.last).inject({}) do |h,(k,v)|
|
34
|
+
h[k.to_sym] = v
|
35
|
+
h
|
36
|
+
end.merge!(attributes)
|
37
|
+
else
|
38
|
+
template = template_or_file
|
39
|
+
end
|
40
|
+
|
41
|
+
recipe_class = Class.new(RailsWizard::Recipe)
|
42
|
+
recipe_class.attributes = attributes
|
43
|
+
recipe_class.template = template
|
44
|
+
recipe_class.key = key
|
45
|
+
|
46
|
+
recipe_class
|
47
|
+
end
|
48
|
+
|
49
|
+
ATTRIBUTES.each do |setter|
|
50
|
+
class_eval <<-RUBY
|
51
|
+
def self.#{setter}
|
52
|
+
attributes[:#{setter}]
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.#{setter}=(val)
|
56
|
+
attributes[:#{setter}] = val
|
57
|
+
end
|
58
|
+
|
59
|
+
def #{setter}
|
60
|
+
self.class.#{setter}
|
61
|
+
end
|
62
|
+
RUBY
|
63
|
+
end
|
64
|
+
|
65
|
+
# The attributes hash containing any set values for
|
66
|
+
def self.attributes
|
67
|
+
@attributes ||= DEFAULT_ATTRIBUTES.dup
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.attributes=(hash)
|
71
|
+
attributes.merge! hash
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.config
|
75
|
+
return nil unless attributes[:config]
|
76
|
+
RailsWizard::Config.new(attributes[:config])
|
77
|
+
end
|
78
|
+
|
79
|
+
def attributes
|
80
|
+
self.class.attributes
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.compile
|
84
|
+
"# >#{"[ #{name} ]".center(75,'-')}<\n\n# #{description}\nsay_recipe '#{name}'\n\n#{template}\n"
|
85
|
+
end
|
86
|
+
def compile; self.class.compile end
|
87
|
+
|
88
|
+
def self.to_mongo(value)
|
89
|
+
case value
|
90
|
+
when Class
|
91
|
+
value.key
|
92
|
+
when String
|
93
|
+
value
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.from_mongo(key)
|
98
|
+
return key if key.respond_to?(:superclass) && key.superclass == RailsWizard::Recipe
|
99
|
+
RailsWizard::Recipes[key]
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.get_binding
|
103
|
+
binding
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module RailsWizard
|
2
|
+
module Recipes
|
3
|
+
@@categories = {}
|
4
|
+
@@list = {}
|
5
|
+
|
6
|
+
def self.add(recipe)
|
7
|
+
RailsWizard::Recipes.const_set ActiveSupport::Inflector.camelize(recipe.key), recipe
|
8
|
+
@@list[recipe.key] = recipe
|
9
|
+
(@@categories[recipe.category.to_s] ||= []) << recipe.key
|
10
|
+
@@categories[recipe.category.to_s].uniq!
|
11
|
+
recipe
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.[](key)
|
15
|
+
@@list[key.to_s]
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.list
|
19
|
+
@@list.keys.sort
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.list_classes
|
23
|
+
@@list.values.sort_by{|c| c.key}
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.categories
|
27
|
+
@@categories.keys.sort
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.for(category)
|
31
|
+
(@@categories[category.to_s] || []).sort
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.remove_from_category(category, recipe)
|
35
|
+
(@@categories[category.to_s] ||= []).delete(recipe.key)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module RailsWizard
|
2
|
+
class Template
|
3
|
+
attr_reader :recipes
|
4
|
+
|
5
|
+
def initialize(recipes)
|
6
|
+
@recipes = recipes.map{|r| RailsWizard::Recipe.from_mongo(r)}
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.template_root
|
10
|
+
File.dirname(__FILE__) + '/../../templates'
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.render(template_name, binding = nil)
|
14
|
+
erb = ERB.new(File.open(template_root + '/' + template_name + '.erb').read)
|
15
|
+
erb.result(binding)
|
16
|
+
end
|
17
|
+
def render(template_name, binding = nil); self.class.render(template_name, binding) end
|
18
|
+
|
19
|
+
|
20
|
+
def resolve_recipes
|
21
|
+
# @resolve_recipes ||= recipes_with_dependencies.sort
|
22
|
+
@resolve_recipes ||= recipes_with_dependencies
|
23
|
+
end
|
24
|
+
|
25
|
+
def recipe_classes
|
26
|
+
@recipe_classes ||= recipes.map{|r| RailsWizard::Recipe.from_mongo(r)}
|
27
|
+
end
|
28
|
+
|
29
|
+
def recipes_with_dependencies
|
30
|
+
@recipes_with_dependencies ||= recipe_classes
|
31
|
+
|
32
|
+
added_more = false
|
33
|
+
for recipe in recipe_classes
|
34
|
+
recipe.requires.each do |requirement|
|
35
|
+
requirement = RailsWizard::Recipe.from_mongo(requirement)
|
36
|
+
count = @recipes_with_dependencies.size
|
37
|
+
(@recipes_with_dependencies << requirement).uniq!
|
38
|
+
unless @recipes_with_dependencies.size == count
|
39
|
+
added_more = true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
added_more ? recipes_with_dependencies : @recipes_with_dependencies
|
45
|
+
end
|
46
|
+
|
47
|
+
def compile
|
48
|
+
render 'layout', binding
|
49
|
+
end
|
50
|
+
|
51
|
+
def args
|
52
|
+
recipes.map(&:args).uniq
|
53
|
+
end
|
54
|
+
|
55
|
+
def custom_code?; false end
|
56
|
+
def custom_code; nil end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Application template recipe for the rails_apps_composer. Check for a newer version here:
|
2
|
+
# https://github.com/fortuity/rails_apps_composer/blob/master/recipes/action_mailer.rb
|
3
|
+
|
4
|
+
after_bundler do
|
5
|
+
say_wizard "ActionMailer recipe running 'after bundler'"
|
6
|
+
# modifying environment configuration files for ActionMailer
|
7
|
+
gsub_file 'config/environments/development.rb', /# Don't care if the mailer can't send/, '# ActionMailer Config'
|
8
|
+
gsub_file 'config/environments/development.rb', /config.action_mailer.raise_delivery_errors = false/ do
|
9
|
+
<<-RUBY
|
10
|
+
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
11
|
+
# A dummy setup for development - no deliveries, but logged
|
12
|
+
config.action_mailer.delivery_method = :smtp
|
13
|
+
config.action_mailer.perform_deliveries = false
|
14
|
+
config.action_mailer.raise_delivery_errors = true
|
15
|
+
config.action_mailer.default :charset => "utf-8"
|
16
|
+
RUBY
|
17
|
+
end
|
18
|
+
gsub_file 'config/environments/production.rb', /config.active_support.deprecation = :notify/ do
|
19
|
+
<<-RUBY
|
20
|
+
config.active_support.deprecation = :notify
|
21
|
+
|
22
|
+
config.action_mailer.default_url_options = { :host => 'yourhost.com' }
|
23
|
+
# ActionMailer Config
|
24
|
+
# Setup for production - deliveries, no errors raised
|
25
|
+
config.action_mailer.delivery_method = :smtp
|
26
|
+
config.action_mailer.perform_deliveries = true
|
27
|
+
config.action_mailer.raise_delivery_errors = false
|
28
|
+
config.action_mailer.default :charset => "utf-8"
|
29
|
+
RUBY
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
__END__
|
35
|
+
|
36
|
+
name: ActionMailer
|
37
|
+
description: "Configure ActionMailer to show errors during development and suppress failures when the app is deployed to production."
|
38
|
+
author: fortuity
|
39
|
+
|
40
|
+
category: other
|
41
|
+
tags: [utilities, configuration]
|
@@ -0,0 +1,37 @@
|
|
1
|
+
if config['database']
|
2
|
+
say_wizard "Configuring '#{config['database']}' database settings..."
|
3
|
+
old_gem = gem_for_database
|
4
|
+
@options = @options.dup.merge(:database => config['database'])
|
5
|
+
gsub_file 'Gemfile', "gem '#{old_gem}'", "gem '#{gem_for_database}'"
|
6
|
+
template "config/databases/#{@options[:database]}.yml", "config/database.yml.new"
|
7
|
+
run 'mv config/database.yml.new config/database.yml'
|
8
|
+
end
|
9
|
+
|
10
|
+
after_bundler do
|
11
|
+
rake "db:create:all" if config['auto_create']
|
12
|
+
end
|
13
|
+
|
14
|
+
__END__
|
15
|
+
|
16
|
+
name: ActiveRecord
|
17
|
+
description: "Use the default ActiveRecord database store."
|
18
|
+
author: mbleigh
|
19
|
+
|
20
|
+
exclusive: orm
|
21
|
+
category: persistence
|
22
|
+
tags: [sql, defaults, orm]
|
23
|
+
|
24
|
+
config:
|
25
|
+
- database:
|
26
|
+
type: multiple_choice
|
27
|
+
prompt: "Which database are you using?"
|
28
|
+
choices:
|
29
|
+
- ["MySQL", mysql]
|
30
|
+
- ["Oracle", oracle]
|
31
|
+
- ["PostgreSQL", postgresql]
|
32
|
+
- ["SQLite", sqlite3]
|
33
|
+
- ["Frontbase", frontbase]
|
34
|
+
- ["IBM DB", ibm_db]
|
35
|
+
- auto_create:
|
36
|
+
type: boolean
|
37
|
+
prompt: "Automatically create database with default configuration?"
|
data/recipes/add_user.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Application template recipe for the rails_apps_composer. Check for a newer version here:
|
2
|
+
# https://github.com/fortuity/rails_apps_composer/blob/master/recipes/add_user.rb
|
3
|
+
|
4
|
+
after_bundler do
|
5
|
+
|
6
|
+
say_wizard "AddUser recipe running 'after bundler'"
|
7
|
+
|
8
|
+
if recipes.include? 'omniauth'
|
9
|
+
generate(:model, "user provider:string uid:string name:string email:string")
|
10
|
+
gsub_file 'app/models/user.rb', /end/ do
|
11
|
+
<<-RUBY
|
12
|
+
attr_accessible :provider, :uid, :name, :email
|
13
|
+
end
|
14
|
+
RUBY
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
if recipes.include? 'devise'
|
19
|
+
|
20
|
+
# Generate models and routes for a User
|
21
|
+
generate 'devise user'
|
22
|
+
|
23
|
+
# Add a 'name' attribute to the User model
|
24
|
+
if recipes.include? 'mongoid'
|
25
|
+
gsub_file 'app/models/user.rb', /end/ do
|
26
|
+
<<-RUBY
|
27
|
+
field :name
|
28
|
+
validates_presence_of :name
|
29
|
+
validates_uniqueness_of :name, :email, :case_sensitive => false
|
30
|
+
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
|
31
|
+
end
|
32
|
+
RUBY
|
33
|
+
end
|
34
|
+
else
|
35
|
+
# for ActiveRecord
|
36
|
+
# Devise created a Users database, we'll modify it
|
37
|
+
generate 'migration AddNameToUsers name:string'
|
38
|
+
# Devise created a Users model, we'll modify it
|
39
|
+
gsub_file 'app/models/user.rb', /attr_accessible :email/, 'attr_accessible :name, :email'
|
40
|
+
inject_into_file 'app/models/user.rb', :before => 'validates_uniqueness_of' do
|
41
|
+
"validates_presence_of :name\n"
|
42
|
+
end
|
43
|
+
gsub_file 'app/models/user.rb', /validates_uniqueness_of :email/, 'validates_uniqueness_of :name, :email'
|
44
|
+
end
|
45
|
+
|
46
|
+
unless recipes.include? 'haml'
|
47
|
+
|
48
|
+
# Generate Devise views (unless you are using Haml)
|
49
|
+
run 'rails generate devise:views'
|
50
|
+
|
51
|
+
# Modify Devise views to add 'name'
|
52
|
+
inject_into_file "app/views/devise/registrations/edit.html.erb", :after => "<%= devise_error_messages! %>\n" do
|
53
|
+
<<-ERB
|
54
|
+
<p><%= f.label :name %><br />
|
55
|
+
<%= f.text_field :name %></p>
|
56
|
+
ERB
|
57
|
+
end
|
58
|
+
|
59
|
+
inject_into_file "app/views/devise/registrations/new.html.erb", :after => "<%= devise_error_messages! %>\n" do
|
60
|
+
<<-ERB
|
61
|
+
<p><%= f.label :name %><br />
|
62
|
+
<%= f.text_field :name %></p>
|
63
|
+
ERB
|
64
|
+
end
|
65
|
+
|
66
|
+
else
|
67
|
+
|
68
|
+
# copy Haml versions of modified Devise views
|
69
|
+
inside 'app/views/devise/registrations' do
|
70
|
+
get 'https://github.com/fortuity/rails3-application-templates/raw/master/files/rails3-mongoid-devise/app/views/devise/registrations/edit.html.haml', 'edit.html.haml'
|
71
|
+
get 'https://github.com/fortuity/rails3-application-templates/raw/master/files/rails3-mongoid-devise/app/views/devise/registrations/new.html.haml', 'new.html.haml'
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
__END__
|
81
|
+
|
82
|
+
name: AddUser
|
83
|
+
description: "Add a User model including 'name' and 'email' attributes."
|
84
|
+
author: fortuity
|
85
|
+
|
86
|
+
category: other
|
87
|
+
tags: [utilities, configuration]
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Application template recipe for the rails_apps_composer. Check for a newer version here:
|
2
|
+
# https://github.com/fortuity/rails_apps_composer/blob/master/recipes/add_user_name.rb
|
3
|
+
|
4
|
+
after_bundler do
|
5
|
+
|
6
|
+
say_wizard "AddUserName recipe running 'after bundler'"
|
7
|
+
|
8
|
+
# Add a 'name' attribute to the User model
|
9
|
+
if recipes.include? 'mongoid'
|
10
|
+
gsub_file 'app/models/user.rb', /end/ do
|
11
|
+
<<-RUBY
|
12
|
+
field :name
|
13
|
+
validates_presence_of :name
|
14
|
+
validates_uniqueness_of :name, :email, :case_sensitive => false
|
15
|
+
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
|
16
|
+
end
|
17
|
+
RUBY
|
18
|
+
end
|
19
|
+
else
|
20
|
+
# for ActiveRecord
|
21
|
+
# Devise created a Users database, we'll modify it
|
22
|
+
generate 'migration AddNameToUsers name:string'
|
23
|
+
# Devise created a Users model, we'll modify it
|
24
|
+
gsub_file 'app/models/user.rb', /attr_accessible :email/, 'attr_accessible :name, :email'
|
25
|
+
inject_into_file 'app/models/user.rb', :before => 'validates_uniqueness_of' do
|
26
|
+
"validates_presence_of :name\n"
|
27
|
+
end
|
28
|
+
gsub_file 'app/models/user.rb', /validates_uniqueness_of :email/, 'validates_uniqueness_of :name, :email'
|
29
|
+
end
|
30
|
+
|
31
|
+
if recipes.include? 'devise'
|
32
|
+
unless recipes.include? 'haml'
|
33
|
+
|
34
|
+
# Generate Devise views (unless you are using Haml)
|
35
|
+
run 'rails generate devise:views'
|
36
|
+
|
37
|
+
# Modify Devise views to add 'name'
|
38
|
+
inject_into_file "app/views/devise/registrations/edit.html.erb", :after => "<%= devise_error_messages! %>\n" do
|
39
|
+
<<-ERB
|
40
|
+
<p><%= f.label :name %><br />
|
41
|
+
<%= f.text_field :name %></p>
|
42
|
+
ERB
|
43
|
+
end
|
44
|
+
|
45
|
+
inject_into_file "app/views/devise/registrations/new.html.erb", :after => "<%= devise_error_messages! %>\n" do
|
46
|
+
<<-ERB
|
47
|
+
<p><%= f.label :name %><br />
|
48
|
+
<%= f.text_field :name %></p>
|
49
|
+
ERB
|
50
|
+
end
|
51
|
+
|
52
|
+
else
|
53
|
+
|
54
|
+
# copy Haml versions of modified Devise views
|
55
|
+
inside 'app/views/devise/registrations' do
|
56
|
+
get 'https://github.com/fortuity/rails3-application-templates/raw/master/files/rails3-mongoid-devise/app/views/devise/registrations/edit.html.haml', 'edit.html.haml'
|
57
|
+
get 'https://github.com/fortuity/rails3-application-templates/raw/master/files/rails3-mongoid-devise/app/views/devise/registrations/new.html.haml', 'new.html.haml'
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
__END__
|
67
|
+
|
68
|
+
name: AddUserName
|
69
|
+
description: "Modify the default Devise configuration to add a 'name' attribute for all users."
|
70
|
+
author: fortuity
|
71
|
+
|
72
|
+
requires: [devise]
|
73
|
+
category: other
|
74
|
+
tags: [utilities, configuration]
|