rails3-generators 0.10.3 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.bundle/config +2 -0
- data/CHANGELOG.rdoc +18 -2
- data/README.rdoc +5 -1
- data/Rakefile +5 -2
- data/VERSION +1 -1
- data/lib/generators/{datamapper.rb → data_mapper.rb} +6 -3
- data/lib/generators/{datamapper → data_mapper}/migration/migration_generator.rb +2 -2
- data/lib/generators/{datamapper → data_mapper}/migration/templates/migration.rb +0 -0
- data/lib/generators/{datamapper → data_mapper}/model/model_generator.rb +27 -3
- data/lib/generators/{datamapper → data_mapper}/model/templates/migration.rb +0 -0
- data/lib/generators/{datamapper → data_mapper}/model/templates/model.rb +4 -2
- data/lib/generators/{datamapper → data_mapper}/observer/observer_generator.rb +2 -2
- data/lib/generators/{datamapper → data_mapper}/observer/templates/observer.rb +1 -1
- data/lib/generators/helpers/migration_helper.rb +53 -0
- data/lib/generators/helpers/model_helper.rb +75 -0
- data/lib/generators/jquery/install/install_generator.rb +6 -6
- data/lib/generators/jquery/install/templates/README +10 -0
- data/lib/generators/{mongomapper.rb → mongo_mapper.rb} +3 -24
- data/lib/generators/mongo_mapper/install/install_generator.rb +30 -0
- data/lib/generators/mongo_mapper/install/templates/database.mongo.yml +25 -0
- data/lib/generators/mongo_mapper/install/templates/mongo_mapper.rb +9 -0
- data/lib/generators/mongo_mapper/model/model_generator.rb +84 -0
- data/lib/generators/mongo_mapper/model/templates/model.rb +36 -0
- data/lib/generators/{mongomapper → mongo_mapper}/observer/observer_generator.rb +2 -2
- data/lib/generators/mongo_mapper/observer/templates/observer.rb +3 -0
- data/lib/generators/mongoid.rb +24 -0
- data/lib/generators/mongoid/install/install_generator.rb +35 -0
- data/lib/generators/mongoid/install/templates/database.mongo.yml +25 -0
- data/lib/generators/mongoid/install/templates/mongoid.rb +12 -0
- data/lib/generators/mongoid/model/model_generator.rb +111 -0
- data/lib/generators/{mongomapper → mongoid}/model/templates/model.rb +11 -9
- data/lib/generators/mustache/install/templates/lib/mustache_rails.rb +1 -3
- data/lib/rails3-generators.rb +1 -1
- data/rails3-generators.gemspec +60 -29
- data/test/lib/generators/data_mapper/migration_generator_test.rb +40 -0
- data/test/lib/generators/data_mapper/model_generator_test.rb +53 -0
- data/test/lib/generators/data_mapper/observer_generator_test.rb +22 -0
- data/test/lib/generators/haml/controller_generator_test.rb +1 -0
- data/test/lib/generators/haml/install_generator_test.rb +1 -0
- data/test/lib/generators/haml/scaffold_generator_test.rb +1 -0
- data/test/lib/generators/haml/testing_helper.rb +1 -0
- data/test/lib/generators/jquery/install_generator_test.rb +0 -1
- data/test/lib/generators/mongo_mapper/install_generator_test.rb +17 -0
- data/test/lib/generators/mongo_mapper/model_generator_test.rb +73 -0
- data/test/lib/generators/mongo_mapper/observer_generator_test.rb +20 -0
- data/test/lib/generators/mongo_mapper/testing_helper.rb +1 -0
- data/test/lib/generators/mongoid/install_generator_test.rb +18 -0
- data/test/lib/generators/mongoid/model_generator_test.rb +72 -0
- data/test/lib/generators/mongoid/testing_helper.rb +1 -0
- data/test/lib/generators/mustache/controller_generator_test.rb +1 -0
- data/test/lib/generators/mustache/scaffold_generator_test.rb +1 -0
- data/test/lib/generators/mustache/testing_helper.rb +1 -0
- data/test/test_helper.rb +31 -28
- metadata +61 -30
- data/lib/generators/jquery/install/templates/config/initializers/jquery.rb.tt +0 -9
- data/lib/generators/mongomapper/model/model_generator.rb +0 -29
- data/test/lib/generators/datamapper/migration_generator_test.rb +0 -13
- data/test/lib/generators/datamapper/model_generator_test.rb +0 -13
- data/test/lib/generators/datamapper/observer_generator_test.rb +0 -13
- data/test/lib/generators/mongomapper/model_generator_test.rb +0 -13
- data/test/lib/generators/mongomapper/observer_generator_test.rb +0 -13
data/.bundle/config
ADDED
data/CHANGELOG.rdoc
CHANGED
@@ -1,8 +1,24 @@
|
|
1
1
|
== TODO
|
2
2
|
* Grow Mustache up.(fix the TODOs and move the source to a mustache-rails like gem)
|
3
3
|
* Write some documentation. (In both the github wiki and the source code)
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
== 0.11.0
|
6
|
+
* enhancements
|
7
|
+
* Added new mongo_mapper generator for mongo mapper 0.8 with lots of extra features [Kristian Mandrup]
|
8
|
+
* Added mongoid generator for mongoid 2.0.beta with features similar to new mongo_mapper [Kristian Mandrup]
|
9
|
+
|
10
|
+
* optimize
|
11
|
+
* renamed datamapper to data_mapper
|
12
|
+
* renamed mongomapper to mongo_mapper.
|
13
|
+
|
14
|
+
* fix
|
15
|
+
* added DataMapper Tests
|
16
|
+
* added MongoMapper Tests
|
17
|
+
|
18
|
+
== 0.10.4
|
19
|
+
* optimize
|
20
|
+
* Update jquery install by removing unneeded initializer file
|
21
|
+
* Update mustache_rails to user autoload_paths instead of load_paths
|
6
22
|
|
7
23
|
== 0.10.3
|
8
24
|
* optimize
|
data/README.rdoc
CHANGED
@@ -38,7 +38,11 @@ Factory Girl: Paul Barry
|
|
38
38
|
|
39
39
|
Authlogic: Jeff Tucker
|
40
40
|
|
41
|
-
|
41
|
+
Mongomapper: Jai-Gouk Kim
|
42
|
+
|
43
|
+
MongoMapper: Kristian Mandrup (for 0.8) - needs testing
|
44
|
+
|
45
|
+
Mongoid: Kristian Mandrup (for 2.0.beta) - needs testing
|
42
46
|
|
43
47
|
Machinist: Darcy Laycock
|
44
48
|
|
data/Rakefile
CHANGED
@@ -9,16 +9,19 @@ begin
|
|
9
9
|
|
10
10
|
gem.name = "rails3-generators"
|
11
11
|
gem.summary = %Q{Rails 3 compatible generators}
|
12
|
-
gem.description = %Q{Rails 3 compatible generators for DataMapper, Haml, Factory-girl, Authlogic, Mongomapper, Shoulda, Formtastic and SimpleForm}
|
12
|
+
gem.description = %Q{Rails 3 compatible generators for DataMapper, Haml, Factory-girl, Authlogic, Mongomapper, Mongoid, Shoulda, Formtastic and SimpleForm}
|
13
13
|
gem.email = "andre@arko.net"
|
14
14
|
gem.homepage = "http://github.com/indirect/rails3-generators"
|
15
|
-
gem.authors = ["Jose Valim", "Anuj Dutta", "Paul Berry", "Jeff Tucker", "Louis T.", "Jai-Gouk Kim", "Darcy Laycock", "Peter Haza", "Peter Gumeson"]
|
15
|
+
gem.authors = ["Jose Valim", "Anuj Dutta", "Paul Berry", "Jeff Tucker", "Louis T.", "Jai-Gouk Kim", "Darcy Laycock", "Peter Haza", "Peter Gumeson", "Kristian Mandrup"]
|
16
16
|
# gem.add_development_dependency "rspec", ">= 1.2.9"
|
17
17
|
gem.post_install_message =
|
18
18
|
%Q{
|
19
19
|
rails3-generators-#{version}
|
20
20
|
Be sure to check out the wiki, http://wiki.github.com/indirect/rails3-generators/,
|
21
21
|
for information about recent changes to this project.
|
22
|
+
|
23
|
+
note: ORM :datamapper has been renamed to :data_mapper
|
24
|
+
note: ORM :mongomapper has been renamed to :mongo_mapper
|
22
25
|
|
23
26
|
note: if you use erb templates add the follow to your generators block to take full advantage of this gem.
|
24
27
|
g.template_engine :erubis
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.11.0
|
@@ -2,14 +2,17 @@ require 'rails/generators/named_base'
|
|
2
2
|
require 'rails/generators/migration'
|
3
3
|
require 'rails/generators/active_model'
|
4
4
|
|
5
|
-
|
5
|
+
require 'generators/helpers/migration_helper'
|
6
|
+
|
7
|
+
module DataMapper
|
6
8
|
module Generators
|
7
9
|
class Base < Rails::Generators::NamedBase #:nodoc:
|
8
|
-
include
|
10
|
+
include Rails3Generators::MigrationHelper
|
11
|
+
# include Rails::Generators::Migration
|
9
12
|
|
10
13
|
def self.source_root
|
11
14
|
@_datamapper_source_root ||= File.expand_path(File.join(File.dirname(__FILE__),
|
12
|
-
'
|
15
|
+
'data_mapper', generator_name, 'templates'))
|
13
16
|
end
|
14
17
|
|
15
18
|
protected
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'generators/
|
1
|
+
require 'generators/data_mapper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module DataMapper
|
4
4
|
module Generators
|
5
5
|
class ModelGenerator < Base
|
6
6
|
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
@@ -13,7 +13,7 @@ module Datamapper
|
|
13
13
|
class_option :parent, :type => :string, :desc => "The parent class for the generated model"
|
14
14
|
|
15
15
|
def create_migration_file
|
16
|
-
if
|
16
|
+
if migration? && parent?
|
17
17
|
file_name = "create_#{file_path.gsub(/\//, '_').pluralize}"
|
18
18
|
migration_template "migration.rb", "db/migrate/#{file_name}.rb"
|
19
19
|
end
|
@@ -23,6 +23,30 @@ module Datamapper
|
|
23
23
|
template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
24
24
|
end
|
25
25
|
|
26
|
+
protected
|
27
|
+
|
28
|
+
def migration?
|
29
|
+
options[:migration]
|
30
|
+
end
|
31
|
+
|
32
|
+
def timestamps?
|
33
|
+
options[:timestamps]
|
34
|
+
end
|
35
|
+
|
36
|
+
def parent?
|
37
|
+
options[:parent]
|
38
|
+
end
|
39
|
+
|
40
|
+
def timestamp_statements
|
41
|
+
%q{
|
42
|
+
property :created_at, DateTime
|
43
|
+
# property :created_on, Date
|
44
|
+
|
45
|
+
property :updated_at, DateTime
|
46
|
+
# property :updated_on, Date
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
26
50
|
hook_for :test_framework
|
27
51
|
end
|
28
52
|
end
|
File without changes
|
@@ -1,5 +1,5 @@
|
|
1
|
-
class <%= class_name %><%= "< #{options[:parent].classify}" if
|
2
|
-
<% unless
|
1
|
+
class <%= class_name %><%= "< #{options[:parent].classify}" if parent? %>
|
2
|
+
<% unless parent? -%>
|
3
3
|
include DataMapper::Resource
|
4
4
|
|
5
5
|
property :id, Serial
|
@@ -7,4 +7,6 @@ class <%= class_name %><%= "< #{options[:parent].classify}" if options[:parent]
|
|
7
7
|
<% attributes.each do |attribute| -%>
|
8
8
|
property :<%= attribute.name %>, <%= attribute.type_class %>
|
9
9
|
<% end -%>
|
10
|
+
|
11
|
+
<%= timestamp_statements if timestamps? %>
|
10
12
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
module Rails3Generators
|
4
|
+
module MigrationHelper
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
|
7
|
+
attr_accessor :migration_number
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def migration_lookup_at(dirname) #:nodoc:
|
11
|
+
Dir.glob("#{dirname}/[0-9]*_*.rb")
|
12
|
+
end
|
13
|
+
|
14
|
+
def migration_exists?(dirname, file_name) #:nodoc:
|
15
|
+
migration_lookup_at(dirname).grep(/\d+_#{file_name}.rb$/).first
|
16
|
+
end
|
17
|
+
|
18
|
+
def current_migration_number(dirname) #:nodoc:
|
19
|
+
migration_lookup_at(dirname).collect do |file|
|
20
|
+
File.basename(file).split("_").first.to_i
|
21
|
+
end.max.to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
def next_migration_number(dirname) #:nodoc:
|
25
|
+
orm = Rails.configuration.generators.options[:rails][:orm]
|
26
|
+
require "rails/generators/#{orm}"
|
27
|
+
"#{orm.to_s.camelize}::Generators::Base".constantize.next_migration_number(dirname)
|
28
|
+
rescue
|
29
|
+
raise NotImplementedError
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.included(base) #:nodoc:
|
34
|
+
base.extend ClassMethods
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def run_migration(options)
|
39
|
+
run "rails g migration #{options}"
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def model_exists?(name)
|
45
|
+
File.exists?(File.join(Rails.root, "app/models/#{name}.rb"))
|
46
|
+
end
|
47
|
+
|
48
|
+
def model_file(name)
|
49
|
+
File.join(Rails.root, "app/models/#{name}.rb")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Rails3Generators
|
2
|
+
module Helpers
|
3
|
+
module Model
|
4
|
+
|
5
|
+
attr_accessor :model_attributes, :model_indexes
|
6
|
+
|
7
|
+
def parse_model_attributes(with_indexes = true)
|
8
|
+
@model_attributes = []
|
9
|
+
@model_indexes = {}
|
10
|
+
#
|
11
|
+
# attributes.each do |arg|
|
12
|
+
# if with_indexes
|
13
|
+
# # extract index markers
|
14
|
+
# if arg.include?('#')
|
15
|
+
# arg.gsub! /#.*$/, ''
|
16
|
+
# model_indexes[arg_name(arg).to_sym] = true
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# if arg.include?(':')
|
21
|
+
# model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
|
22
|
+
# else
|
23
|
+
# model_attributes << Rails::Generators::GeneratedAttribute.new(arg, "string")
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# model_attributes.uniq!
|
27
|
+
#
|
28
|
+
# if model_attributes.empty?
|
29
|
+
# if model_exists?
|
30
|
+
# model_columns_for_attributes.each do |column|
|
31
|
+
# model_attributes << Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
|
32
|
+
# end
|
33
|
+
# else
|
34
|
+
# model_attributes << Rails::Generators::GeneratedAttribute.new('name', 'string')
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
end
|
39
|
+
|
40
|
+
def arg_name(arg)
|
41
|
+
arg.split(':').first
|
42
|
+
end
|
43
|
+
|
44
|
+
def arg_type(arg)
|
45
|
+
arg.split(':')[1] || 'string'
|
46
|
+
end
|
47
|
+
|
48
|
+
def model_name
|
49
|
+
name
|
50
|
+
end
|
51
|
+
|
52
|
+
def model_exists?
|
53
|
+
File.exist? destination_path("app/models/#{singular_name}.rb")
|
54
|
+
end
|
55
|
+
|
56
|
+
def singular_name
|
57
|
+
model_name.underscore
|
58
|
+
end
|
59
|
+
|
60
|
+
def plural_name
|
61
|
+
model_name.underscore.pluralize
|
62
|
+
end
|
63
|
+
|
64
|
+
def class_name
|
65
|
+
model_name.camelize
|
66
|
+
end
|
67
|
+
|
68
|
+
def plural_class_name
|
69
|
+
plural_name.camelize
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
|
@@ -5,13 +5,9 @@ module Jquery
|
|
5
5
|
class InstallGenerator < Rails::Generators::Base
|
6
6
|
extend TemplatePath
|
7
7
|
|
8
|
-
def copy_initializer_files
|
9
|
-
template "config/initializers/jquery.rb.tt", "config/initializers/jquery.rb"
|
10
|
-
end
|
11
|
-
|
12
8
|
def download_jquery_files
|
13
|
-
%w(controls.js dragdrop.js effects.js prototype.js rails.js).each do |
|
14
|
-
remove_file "public/javascripts/#{
|
9
|
+
%w(controls.js dragdrop.js effects.js prototype.js rails.js).each do |js|
|
10
|
+
remove_file "public/javascripts/#{js}"
|
15
11
|
end
|
16
12
|
|
17
13
|
# Downloading latest jQuery.min
|
@@ -20,6 +16,10 @@ module Jquery
|
|
20
16
|
# Downloading latest jQuery drivers
|
21
17
|
get "http://github.com/rails/jquery-ujs/raw/master/src/rails.js", "public/javascripts/rails.js"
|
22
18
|
end
|
19
|
+
|
20
|
+
def show_readme
|
21
|
+
readme "README"
|
22
|
+
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
===============================================================================
|
3
|
+
|
4
|
+
Some manual steps you have to do
|
5
|
+
|
6
|
+
1. Uncomment or add the following to you application.rb file:
|
7
|
+
|
8
|
+
config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
|
9
|
+
|
10
|
+
===============================================================================
|
@@ -1,35 +1,14 @@
|
|
1
1
|
require 'rails/generators/named_base'
|
2
|
-
# require 'rails/generators/migration'
|
3
2
|
require 'rails/generators/active_model'
|
4
3
|
|
5
|
-
module
|
4
|
+
module MongoMapper
|
6
5
|
module Generators
|
7
6
|
class Base < Rails::Generators::NamedBase #:nodoc:
|
8
|
-
# include Rails::Generators::Migration
|
9
7
|
|
10
8
|
def self.source_root
|
11
9
|
@_mongomapper_source_root ||= File.expand_path(File.join(File.dirname(__FILE__),
|
12
|
-
|
10
|
+
'mongo_mapper', generator_name, 'templates'))
|
13
11
|
end
|
14
|
-
|
15
|
-
protected
|
16
|
-
|
17
|
-
# # mongomapper 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
12
|
end
|
34
13
|
|
35
14
|
class ActiveModel < Rails::Generators::ActiveModel #:nodoc:
|
@@ -54,7 +33,7 @@ module Mongomapper
|
|
54
33
|
end
|
55
34
|
|
56
35
|
def update_attributes(params=nil)
|
57
|
-
"#{name}.update(#{params})"
|
36
|
+
"#{name}.update(#{params})"
|
58
37
|
end
|
59
38
|
|
60
39
|
def errors
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'generators/mongo_mapper'
|
2
|
+
|
3
|
+
module MongoMapper
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Base
|
6
|
+
class_option :host, :type => :string, :default => 'localhost', :desc => "Name of the Mongo host use"
|
7
|
+
|
8
|
+
def create_files
|
9
|
+
template "mongo_mapper.rb" , "config/initializers/mongo_mapper.rb"
|
10
|
+
template "database.mongo.yml" , "config/database.mongo.yml"
|
11
|
+
say "Please ensure Gemfile contains: gem '#{orm_gem_name}', '>=0.8.2'"
|
12
|
+
say "For production enviroment DB configuration, set environment variables as indicated in config/database.mongo.yml"
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def database
|
18
|
+
name
|
19
|
+
end
|
20
|
+
|
21
|
+
def orm_gem_name
|
22
|
+
"mongo_mapper"
|
23
|
+
end
|
24
|
+
|
25
|
+
def host
|
26
|
+
options[:host] || 'localhost'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
adapter: mongodb
|
3
|
+
host: <%= host %>
|
4
|
+
# slaves:
|
5
|
+
# - host: slave1.local
|
6
|
+
# port: 27018
|
7
|
+
# - host: slave2.local
|
8
|
+
# port: 27019
|
9
|
+
|
10
|
+
development:
|
11
|
+
<<: *defaults
|
12
|
+
database: <%= database %>_development
|
13
|
+
|
14
|
+
test:
|
15
|
+
<<: *defaults
|
16
|
+
database: <%= database %>_test
|
17
|
+
|
18
|
+
# set these environment variables on your prod server
|
19
|
+
production:
|
20
|
+
<<: *defaults
|
21
|
+
host: <%= ENV['MONGOID_HOST'] %>
|
22
|
+
port: <%= ENV['MONGOID_PORT'] %>
|
23
|
+
username: <%= ENV['MONGOID_USERNAME'] %>
|
24
|
+
password: <%= ENV['MONGOID_PASSWORD'] %>
|
25
|
+
database: <%= ENV['MONGOID_DATABASE'] %>
|