rails3-generators 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/LICENSE +20 -0
- data/README.rdoc +11 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/features/support/env.rb +4 -0
- data/lib/generators/authlogic.rb +11 -0
- data/lib/generators/authlogic/session/session_generator.rb +18 -0
- data/lib/generators/authlogic/session/templates/session.rb +2 -0
- data/lib/generators/datamapper.rb +80 -0
- data/lib/generators/datamapper/migration/migration_generator.rb +26 -0
- data/lib/generators/datamapper/migration/templates/migration.rb +21 -0
- data/lib/generators/datamapper/model/model_generator.rb +29 -0
- data/lib/generators/datamapper/model/templates/migration.rb +17 -0
- data/lib/generators/datamapper/model/templates/model.rb +10 -0
- data/lib/generators/datamapper/observer/observer_generator.rb +15 -0
- data/lib/generators/datamapper/observer/templates/observer.rb +5 -0
- data/lib/generators/factory_girl.rb +11 -0
- data/lib/generators/factory_girl/model/model_generator.rb +14 -0
- data/lib/generators/factory_girl/model/templates/fixtures.rb +7 -0
- data/lib/generators/haml.rb +9 -0
- data/lib/generators/haml/controller/controller_generator.rb +24 -0
- data/lib/generators/haml/controller/templates/view.html.haml +0 -0
- data/lib/generators/haml/scaffold/scaffold_generator.rb +23 -0
- data/lib/generators/haml/scaffold/templates/_form.haml.erb +10 -0
- data/lib/generators/haml/scaffold/templates/edit.haml.erb +7 -0
- data/lib/generators/haml/scaffold/templates/index.haml.erb +23 -0
- data/lib/generators/haml/scaffold/templates/layout.haml.erb +8 -0
- data/lib/generators/haml/scaffold/templates/new.haml.erb +5 -0
- data/lib/generators/haml/scaffold/templates/show.haml.erb +9 -0
- data/lib/generators/rspec.rb +25 -0
- data/lib/generators/rspec/controller/controller_generator.rb +26 -0
- data/lib/generators/rspec/controller/templates/controller_spec.rb +23 -0
- data/lib/generators/rspec/controller/templates/view_spec.rb +12 -0
- data/lib/generators/rspec/helper/helper_generator.rb +11 -0
- data/lib/generators/rspec/helper/templates/helper_spec.rb +11 -0
- data/lib/generators/rspec/install/install_generator.rb +28 -0
- data/lib/generators/rspec/install/templates/lib/tasks/rspec.rake +182 -0
- data/lib/generators/rspec/install/templates/script/autospec.tt +6 -0
- data/lib/generators/rspec/install/templates/script/spec.tt +10 -0
- data/lib/generators/rspec/install/templates/script/spec_server.tt +9 -0
- data/lib/generators/rspec/install/templates/spec/rcov.opts +2 -0
- data/lib/generators/rspec/install/templates/spec/spec.opts +4 -0
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb +51 -0
- data/lib/generators/rspec/integration/integration_generator.rb +12 -0
- data/lib/generators/rspec/integration/templates/integration_spec.rb +4 -0
- data/lib/generators/rspec/mailer/mailer_generator.rb +21 -0
- data/lib/generators/rspec/mailer/templates/fixture +3 -0
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +14 -0
- data/lib/generators/rspec/model/model_generator.rb +22 -0
- data/lib/generators/rspec/model/templates/fixtures.yml +19 -0
- data/lib/generators/rspec/model/templates/model_spec.rb +13 -0
- data/lib/generators/rspec/observer/observer_generator.rb +12 -0
- data/lib/generators/rspec/observer/templates/observer_spec.rb +5 -0
- data/lib/generators/rspec/plugin/plugin_generator.rb +11 -0
- data/lib/generators/rspec/plugin/templates/%file_name%_spec.rb.tt +5 -0
- data/lib/generators/rspec/plugin/templates/test_helper.rb +5 -0
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +112 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +127 -0
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +25 -0
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +27 -0
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +25 -0
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +67 -0
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +22 -0
- data/lib/rails3-generators.rb +2 -0
- data/rails3-generators.gemspec +116 -0
- data/spec/rails3-generators_spec.rb +4 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +8 -0
- metadata +144 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Louis T.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rails3-generators"
|
8
|
+
gem.summary = %Q{Rails 3 compatible generators}
|
9
|
+
gem.description = %Q{Rails 3 compatible generators for RSpec, DataMapper, Haml, Factory-girl and Authlogic}
|
10
|
+
gem.email = "negonicrac@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/negonicrac/rails3-generators"
|
12
|
+
gem.authors = ["Louis T."]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_development_dependency "cucumber", ">= 0"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
begin
|
37
|
+
require 'cucumber/rake/task'
|
38
|
+
Cucumber::Rake::Task.new(:features)
|
39
|
+
|
40
|
+
task :features => :check_dependencies
|
41
|
+
rescue LoadError
|
42
|
+
task :features do
|
43
|
+
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
task :default => :spec
|
48
|
+
|
49
|
+
require 'rake/rdoctask'
|
50
|
+
Rake::RDocTask.new do |rdoc|
|
51
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "rails3-generators #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
|
3
|
+
module Authlogic
|
4
|
+
module Generators
|
5
|
+
class Base < Rails::Generators::NamedBase
|
6
|
+
def self.source_root
|
7
|
+
@_authlogic_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'authlogic', generator_name, 'templates'))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'generators/authlogic'
|
2
|
+
|
3
|
+
module Authlogic
|
4
|
+
module Generators
|
5
|
+
class SessionGenerator < Base
|
6
|
+
desc "Builds an Authlogic session model"
|
7
|
+
|
8
|
+
check_class_collision
|
9
|
+
|
10
|
+
def create_session_file
|
11
|
+
template 'session.rb', File.join('app', 'models', class_path, "#{file_name}.rb")
|
12
|
+
end
|
13
|
+
|
14
|
+
hook_for :test_framework
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
require 'rails/generators/active_model'
|
4
|
+
|
5
|
+
module Datamapper
|
6
|
+
module Generators
|
7
|
+
class Base < Rails::Generators::NamedBase #:nodoc:
|
8
|
+
include Rails::Generators::Migration
|
9
|
+
|
10
|
+
def self.source_root
|
11
|
+
@_datamapper_source_root ||= File.expand_path(File.join(File.dirname(__FILE__),
|
12
|
+
'datamapper', generator_name, 'templates'))
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
# Datamapper does not care if migrations have the same name as long as
|
18
|
+
# they have different ids.
|
19
|
+
#
|
20
|
+
def migration_exists?(dirname, file_name) #:nodoc:
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
24
|
+
# Implement the required interface for Rails::Generators::Migration.
|
25
|
+
#
|
26
|
+
def next_migration_number(dirname) #:nodoc:
|
27
|
+
if options[:id]
|
28
|
+
"%.3d" % options[:id]
|
29
|
+
else
|
30
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class ActiveModel < Rails::Generators::ActiveModel #:nodoc:
|
36
|
+
def self.all(klass)
|
37
|
+
"#{klass}.all"
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.find(klass, params=nil)
|
41
|
+
"#{klass}.get(#{params})"
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.build(klass, params=nil)
|
45
|
+
if params
|
46
|
+
"#{klass}.new(#{params})"
|
47
|
+
else
|
48
|
+
"#{klass}.new"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def save
|
53
|
+
"#{name}.save"
|
54
|
+
end
|
55
|
+
|
56
|
+
def update_attributes(params=nil)
|
57
|
+
"#{name}.update(#{params})"
|
58
|
+
end
|
59
|
+
|
60
|
+
def errors
|
61
|
+
"#{name}.errors"
|
62
|
+
end
|
63
|
+
|
64
|
+
def destroy
|
65
|
+
"#{name}.destroy"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
module Rails
|
72
|
+
module Generators
|
73
|
+
class GeneratedAttribute #:nodoc:
|
74
|
+
def type_class
|
75
|
+
return 'DateTime' if type.to_s == 'datetime'
|
76
|
+
return type.to_s.camelcase
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'generators/datamapper'
|
2
|
+
|
3
|
+
module Datamapper
|
4
|
+
module Generators
|
5
|
+
class MigrationGenerator < Base
|
6
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
7
|
+
class_option :id, :type => :numeric, :desc => "The id to be used in this migration"
|
8
|
+
|
9
|
+
def create_migration_file
|
10
|
+
set_local_assigns!
|
11
|
+
migration_template "migration.rb", "db/migrate/#{file_name}.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
attr_reader :migration_action
|
16
|
+
|
17
|
+
def set_local_assigns!
|
18
|
+
if file_name =~ /^(add|remove|drop)_.*_(?:to|from)_(.*)/
|
19
|
+
@migration_action = $1 == 'add' ? 'add' : 'drop'
|
20
|
+
@table_name = $2.pluralize
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
migration <%= migration_number.to_i %>, :<%= migration_file_name %> do
|
2
|
+
up do
|
3
|
+
<% unless attributes.empty? -%>
|
4
|
+
modify_table :<%= table_name %> do
|
5
|
+
<% attributes.each do |attribute| -%>
|
6
|
+
<%= migration_action %>_column :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type_class %><% end -%>
|
7
|
+
<% end -%>
|
8
|
+
end
|
9
|
+
<% end -%>
|
10
|
+
end
|
11
|
+
|
12
|
+
down do
|
13
|
+
<% unless attributes.empty? -%>
|
14
|
+
modify_table :<%= table_name %> do
|
15
|
+
<% attributes.reverse.each do |attribute| -%>
|
16
|
+
<%= migration_action == 'add' ? 'drop' : 'add' %>_column :<%= attribute.name %><% if migration_action == 'drop' %>, :<%= attribute.type_class %><% end -%>
|
17
|
+
<% end -%>
|
18
|
+
end
|
19
|
+
<% end -%>
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'generators/datamapper'
|
2
|
+
|
3
|
+
module Datamapper
|
4
|
+
module Generators
|
5
|
+
class ModelGenerator < Base
|
6
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
7
|
+
class_option :id, :type => :numeric, :desc => "The id to be used in the migration"
|
8
|
+
|
9
|
+
check_class_collision
|
10
|
+
|
11
|
+
class_option :migration, :type => :boolean
|
12
|
+
class_option :timestamps, :type => :boolean
|
13
|
+
class_option :parent, :type => :string, :desc => "The parent class for the generated model"
|
14
|
+
|
15
|
+
def create_migration_file
|
16
|
+
if options[:migration] && options[:parent].nil?
|
17
|
+
file_name = "create_#{file_path.gsub(/\//, '_').pluralize}"
|
18
|
+
migration_template "migration.rb", "db/migrate/#{file_name}.rb"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_model_file
|
23
|
+
template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
24
|
+
end
|
25
|
+
|
26
|
+
hook_for :test_framework
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
migration <%= migration_number.to_i %>, :<%= migration_file_name %> do
|
2
|
+
up do
|
3
|
+
create_table :<%= table_name %> do
|
4
|
+
<% attributes.each do |attribute| -%>
|
5
|
+
column :<%= attribute.name -%>, <%= attribute.type_class %>
|
6
|
+
<% end -%>
|
7
|
+
<% if options[:timestamps] %>
|
8
|
+
column :created_at, DateTime
|
9
|
+
column :updated_at, DateTime
|
10
|
+
<% end -%>
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
down do
|
15
|
+
drop_table :<%= table_name %>
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class <%= class_name %><%= "< #{options[:parent].classify}" if options[:parent] %>
|
2
|
+
<% unless options[:parent] -%>
|
3
|
+
include DataMapper::Resource
|
4
|
+
|
5
|
+
property :id, Serial
|
6
|
+
<% end -%>
|
7
|
+
<% attributes.each do |attribute| -%>
|
8
|
+
property :<%= attribute.name %>, <%= attribute.type_class %>
|
9
|
+
<% end -%>
|
10
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'generators/datamapper'
|
2
|
+
|
3
|
+
module Datamapper
|
4
|
+
module Generators
|
5
|
+
class ObserverGenerator < Base
|
6
|
+
check_class_collision :suffix => "Observer"
|
7
|
+
|
8
|
+
def create_observer_file
|
9
|
+
template 'observer.rb', File.join('app/models', class_path, "#{file_name}_observer.rb")
|
10
|
+
end
|
11
|
+
|
12
|
+
hook_for :test_framework
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rails/generators/named_base'
|
2
|
+
|
3
|
+
module FactoryGirl
|
4
|
+
module Generators
|
5
|
+
class Base < Rails::Generators::NamedBase #:nodoc:
|
6
|
+
def self.source_root
|
7
|
+
@_factory_girl_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'factory_girl', generator_name, 'templates'))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'generators/factory_girl'
|
2
|
+
|
3
|
+
module FactoryGirl
|
4
|
+
module Generators
|
5
|
+
class ModelGenerator < Base
|
6
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
7
|
+
class_option :dir, :type => :string, :default => "test/factories", :desc => "The directory where the factories should go"
|
8
|
+
|
9
|
+
def create_fixture_file
|
10
|
+
template 'fixtures.rb', File.join(options[:dir], "#{table_name}.rb")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'generators/haml'
|
2
|
+
require 'rails/generators/named_base'
|
3
|
+
|
4
|
+
module Haml
|
5
|
+
module Generators
|
6
|
+
class ControllerGenerator < Rails::Generators::NamedBase
|
7
|
+
extend TemplatePath
|
8
|
+
|
9
|
+
argument :actions, :type => :array, :default => [], :banner => "action action"
|
10
|
+
|
11
|
+
def create_view_files
|
12
|
+
base_path = File.join("app/views", class_path, file_name)
|
13
|
+
empty_directory base_path
|
14
|
+
|
15
|
+
actions.each do |action|
|
16
|
+
@action = action
|
17
|
+
@path = File.join(base_path, "#{action}.html.haml")
|
18
|
+
|
19
|
+
template 'view.html.haml', @path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'generators/haml'
|
2
|
+
require 'generators/erb/scaffold/scaffold_generator'
|
3
|
+
|
4
|
+
module Haml
|
5
|
+
module Generators
|
6
|
+
class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
|
7
|
+
extend TemplatePath
|
8
|
+
|
9
|
+
def copy_layout_file
|
10
|
+
return unless options[:layout]
|
11
|
+
template "layout.haml.erb",
|
12
|
+
File.join("app/views/layouts", controller_class_path, "#{controller_file_name}.html.haml")
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def copy_view(view)
|
18
|
+
template "#{view}.haml.erb", File.join("app/views", controller_file_path, "#{view}.html.haml")
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|