padrino-gen 0.9.10 → 0.9.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/Rakefile +4 -53
- data/bin/padrino-gen +2 -4
- data/lib/padrino-gen/command.rb +12 -0
- data/lib/padrino-gen/generators/actions.rb +25 -5
- data/lib/padrino-gen/generators/app/app.rb.tt +17 -19
- data/lib/padrino-gen/generators/app.rb +7 -6
- data/lib/padrino-gen/generators/cli.rb +3 -2
- data/lib/padrino-gen/generators/components/actions.rb +4 -4
- data/lib/padrino-gen/generators/components/mocks/rr.rb +1 -1
- data/lib/padrino-gen/generators/components/orms/activerecord.rb +58 -16
- data/lib/padrino-gen/generators/components/orms/couchrest.rb +6 -5
- data/lib/padrino-gen/generators/components/orms/datamapper.rb +41 -17
- data/lib/padrino-gen/generators/components/orms/mongoid.rb +7 -6
- data/lib/padrino-gen/generators/components/orms/mongomapper.rb +6 -5
- data/lib/padrino-gen/generators/components/orms/sequel.rb +34 -15
- data/lib/padrino-gen/generators/components/scripts/dojo.rb +4 -0
- data/lib/padrino-gen/generators/components/stylesheets/compass/application.scss +43 -0
- data/lib/padrino-gen/generators/components/stylesheets/compass/partials/_base.scss +10 -0
- data/lib/padrino-gen/generators/components/stylesheets/compass.rb +39 -0
- data/lib/padrino-gen/generators/components/stylesheets/less.rb +2 -2
- data/lib/padrino-gen/generators/components/stylesheets/sass.rb +2 -2
- data/lib/padrino-gen/generators/components/tests/bacon.rb +2 -1
- data/lib/padrino-gen/generators/components/tests/cucumber.rb +26 -4
- data/lib/padrino-gen/generators/components/tests/riot.rb +45 -9
- data/lib/padrino-gen/generators/components/tests/rspec.rb +2 -1
- data/lib/padrino-gen/generators/components/tests/shoulda.rb +2 -1
- data/lib/padrino-gen/generators/components/tests/testspec.rb +2 -1
- data/lib/padrino-gen/generators/controller.rb +2 -2
- data/lib/padrino-gen/generators/mailer.rb +6 -8
- data/lib/padrino-gen/generators/model.rb +9 -1
- data/lib/padrino-gen/generators/project/config/apps.rb.tt +24 -26
- data/lib/padrino-gen/generators/project/config/boot.rb +2 -2
- data/lib/padrino-gen/generators/project.rb +23 -16
- data/lib/padrino-gen/generators/templates/Gemfile.tt +1 -1
- data/lib/padrino-gen/generators/templates/controller.rb.tt +2 -2
- data/lib/padrino-gen/generators/templates/mailer.rb.tt +36 -17
- data/lib/padrino-gen/generators/templates/scripts/dojo.js +16 -0
- data/lib/padrino-gen/generators/templates/scripts/mootools-core.js +120 -1
- data/lib/padrino-gen/generators/templates/scripts/right.js +1 -12
- data/lib/padrino-gen/padrino-tasks/activerecord.rb +40 -34
- data/lib/padrino-gen/padrino-tasks/datamapper.rb +39 -24
- data/lib/padrino-gen/padrino-tasks/mongomapper.rb +1 -1
- data/lib/padrino-gen.rb +2 -1
- data/padrino-gen.gemspec +17 -132
- data/test/helper.rb +3 -11
- data/test/test_app_generator.rb +19 -7
- data/test/test_controller_generator.rb +11 -1
- data/test/test_mailer_generator.rb +18 -15
- data/test/test_migration_generator.rb +4 -4
- data/test/test_model_generator.rb +30 -9
- data/test/test_project_generator.rb +163 -33
- metadata +70 -48
- data/lib/padrino-gen/generators/app/controllers/.empty_directory +0 -0
- data/lib/padrino-gen/generators/app/helpers/.empty_directory +0 -0
- data/lib/padrino-gen/generators/app/views/.empty_directory +0 -0
- data/lib/padrino-gen/generators/app/views/layouts/.emptydirectory +0 -0
- data/lib/padrino-gen/generators/project/.gitignore +0 -7
- data/lib/padrino-gen/generators/project/public/images/.empty_directory +0 -0
- data/lib/padrino-gen/generators/project/public/javascripts/.empty_directory +0 -0
- data/lib/padrino-gen/generators/project/public/stylesheets/.empty_directory +0 -0
- data/lib/padrino-gen/generators/project/tmp/.empty_directory +0 -0
- data/lib/padrino-gen/generators/templates/mailer_initializer.rb.tt +0 -19
data/README.rdoc
CHANGED
@@ -40,9 +40,9 @@ The available components and their default options are listed below:
|
|
40
40
|
|
41
41
|
test:: rspec (default), bacon, shoulda, cucumber, testspec, riot
|
42
42
|
renderer:: haml (default), erb
|
43
|
-
stylesheet:: sass (default), less
|
43
|
+
stylesheet:: sass (default), less, compass
|
44
44
|
mock:: none (default), mocha, rr
|
45
|
-
script:: none (default), jquery, prototype, mootools, rightjs, extcore
|
45
|
+
script:: none (default), jquery, prototype, mootools, rightjs, extcore, dojo
|
46
46
|
orm:: none (default), datamapper, mongomapper, mongoid, activerecord, sequel, couchrest
|
47
47
|
|
48
48
|
To learn more about the project generator, check out the guide to
|
data/Rakefile
CHANGED
@@ -1,54 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require File.expand_path("../../padrino-core/lib/padrino-core/version.rb", __FILE__)
|
5
|
-
|
6
|
-
begin
|
7
|
-
require 'jeweler'
|
8
|
-
Jeweler::Tasks.new do |gem|
|
9
|
-
gem.name = "padrino-gen"
|
10
|
-
gem.summary = "Generators for easily creating and building padrino applications"
|
11
|
-
gem.description = "Generators for easily creating and building padrino applications from the console"
|
12
|
-
gem.email = "padrinorb@gmail.com"
|
13
|
-
gem.homepage = "http://github.com/padrino/padrino-framework/tree/master/padrino-gen"
|
14
|
-
gem.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
15
|
-
gem.executables = ["padrino-gen"]
|
16
|
-
gem.rubyforge_project = 'padrino-gen'
|
17
|
-
gem.version = Padrino.version
|
18
|
-
gem.add_runtime_dependency "padrino-core", "= #{Padrino.version}"
|
19
|
-
gem.add_development_dependency "haml", ">= 2.2.1"
|
20
|
-
gem.add_development_dependency "shoulda", ">= 2.10.3"
|
21
|
-
gem.add_development_dependency "mocha", ">= 0.9.7"
|
22
|
-
gem.add_development_dependency "rack-test", ">= 0.5.0"
|
23
|
-
gem.add_development_dependency "webrat", ">= 0.5.1"
|
24
|
-
gem.add_development_dependency "fakeweb", ">= 1.2.3"
|
25
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
26
|
-
end
|
27
|
-
Jeweler::GemcutterTasks.new
|
28
|
-
Jeweler::RubyforgeTasks.new { |r| r.doc_task = :none }
|
29
|
-
rescue LoadError
|
30
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
31
|
-
end
|
1
|
+
# coding:utf-8
|
2
|
+
RAKE_ROOT = __FILE__
|
32
3
|
|
33
|
-
require '
|
34
|
-
|
35
|
-
test.libs << 'test'
|
36
|
-
test.pattern = 'test/**/test_*.rb'
|
37
|
-
test.verbose = true
|
38
|
-
end
|
39
|
-
|
40
|
-
begin
|
41
|
-
require 'rcov/rcovtask'
|
42
|
-
Rcov::RcovTask.new do |rcov|
|
43
|
-
rcov.libs << 'test'
|
44
|
-
rcov.pattern = 'test/**/test_*.rb'
|
45
|
-
rcov.verbose = true
|
46
|
-
rcov.rcov_opts << ['--exclude /Gems/1.8/gems/,/tmp/,padrino-admin,padrino-cache,padrino-core,padrino-helpers,padrino-mailer']
|
47
|
-
end
|
48
|
-
rescue LoadError
|
49
|
-
task :rcov do
|
50
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install relevance-rcov"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
task :default => :test
|
4
|
+
require 'rubygems'
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper')
|
data/bin/padrino-gen
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
|
3
|
+
# We load padrino-gen
|
3
4
|
padrino_gen_path = File.expand_path('../../lib', __FILE__)
|
4
5
|
$:.unshift(padrino_gen_path) if File.directory?(padrino_gen_path) && !$:.include?(padrino_gen_path)
|
5
6
|
|
@@ -7,9 +8,6 @@ $:.unshift(padrino_gen_path) if File.directory?(padrino_gen_path) && !$:.include
|
|
7
8
|
padrino_core_path = File.expand_path('../../../padrino-core/lib', __FILE__)
|
8
9
|
$:.unshift(padrino_core_path) if File.directory?(padrino_core_path) && !$:.include?(padrino_core_path)
|
9
10
|
|
10
|
-
padrino_local_path = Dir.pwd
|
11
|
-
$:.unshift(padrino_local_path) if File.directory?(padrino_local_path) && !$:.include?(padrino_local_path)
|
12
|
-
|
13
11
|
require 'padrino-gen'
|
14
12
|
require 'padrino-gen/generators/cli'
|
15
13
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'padrino-core/command'
|
2
|
+
|
3
|
+
module Padrino
|
4
|
+
##
|
5
|
+
# This method return the correct location of padrino-gen bin or
|
6
|
+
# exec it using Kernel#system with the given args
|
7
|
+
#
|
8
|
+
def self.bin_gen(*args)
|
9
|
+
@_padrino_gen_bin ||= [Padrino.ruby_command, File.expand_path("../../../bin/padrino-gen", __FILE__)]
|
10
|
+
args.empty? ? @_padrino_gen_bin : system(args.unshift(@_padrino_gen_bin).join(" "))
|
11
|
+
end
|
12
|
+
end # Padrino
|
@@ -88,6 +88,12 @@ module Padrino
|
|
88
88
|
File.exist?(destination_root('config/boot.rb'))
|
89
89
|
end
|
90
90
|
|
91
|
+
# Returns the field with an unacceptable name(for symbol) else returns nil
|
92
|
+
def invalid_fields(fields)
|
93
|
+
results = fields.select { |field| field.split(":").first =~ /\W/ }
|
94
|
+
results.empty? ? nil : results
|
95
|
+
end
|
96
|
+
|
91
97
|
# Returns the app_name for the application at root
|
92
98
|
def fetch_app_name(app='app')
|
93
99
|
app_path = destination_root(app, 'app.rb')
|
@@ -107,10 +113,9 @@ module Padrino
|
|
107
113
|
# insert_into_gemfile(name, :group => 'test', :require => 'foo')
|
108
114
|
def insert_into_gemfile(name, options={})
|
109
115
|
after_pattern = options[:group] ? "#{options[:group].to_s.capitalize} requirements\n" : "Component requirements\n"
|
110
|
-
gem_options
|
111
|
-
include_text
|
112
|
-
|
113
|
-
inject_into_file('Gemfile', options[:content], :after => options[:after])
|
116
|
+
gem_options = options.map { |k, v| "#{k.inspect} => #{v.inspect}" }.join(", ")
|
117
|
+
include_text = "gem '#{name}'" << (gem_options.present? ? ", #{gem_options}" : "") << "\n"
|
118
|
+
inject_into_file('Gemfile', include_text, :after => after_pattern)
|
114
119
|
end
|
115
120
|
|
116
121
|
## Return true if our project has test component
|
@@ -134,6 +139,21 @@ module Padrino
|
|
134
139
|
end
|
135
140
|
end
|
136
141
|
|
142
|
+
# Generates standard and tiny applications within a project
|
143
|
+
def app_skeleton(app, tiny=false)
|
144
|
+
directory("app/", destination_root(app))
|
145
|
+
if tiny # generate tiny structure
|
146
|
+
template "templates/controller.rb.tt", destination_root(app, "controllers.rb")
|
147
|
+
template "templates/helper.rb.tt", destination_root(app, "helpers.rb")
|
148
|
+
@short_name = 'notifier'
|
149
|
+
template "templates/mailer.rb.tt", destination_root(app, "mailers.rb")
|
150
|
+
empty_directory destination_root(app, "views", "mailers")
|
151
|
+
else # generate standard folders
|
152
|
+
empty_directory destination_root("#{app}/controllers/")
|
153
|
+
empty_directory destination_root("#{app}/helpers/")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
137
157
|
module ClassMethods
|
138
158
|
# Defines a class option to allow a component to be chosen and add to component type list
|
139
159
|
# Also builds the available_choices hash of which component choices are supported
|
@@ -167,4 +187,4 @@ module Padrino
|
|
167
187
|
end
|
168
188
|
end # Actions
|
169
189
|
end # Generators
|
170
|
-
end # Padrino
|
190
|
+
end # Padrino
|
@@ -1,27 +1,26 @@
|
|
1
|
-
class <%= @
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
#
|
18
|
-
end
|
1
|
+
class <%= @app_name %> < Padrino::Application
|
2
|
+
register Padrino::Mailer
|
3
|
+
register Padrino::Helpers
|
4
|
+
|
5
|
+
##
|
6
|
+
# Application configuration options
|
7
|
+
#
|
8
|
+
# set :raise_errors, true # Show exceptions (default for development)
|
9
|
+
# set :public, "foo/bar" # Location for static assets (default root/public)
|
10
|
+
# set :reload, false # Reload application files (default in development)
|
11
|
+
# set :default_builder, "foo" # Set a custom form builder (default 'StandardFormBuilder')
|
12
|
+
# set :locale_path, "bar" # Set path for I18n translations (defaults to app/locale/)
|
13
|
+
# enable :sessions # Disabled by default
|
14
|
+
# disable :flash # Disables rack-flash (enabled by default if sessions)
|
15
|
+
# layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application)
|
16
|
+
#
|
19
17
|
|
20
18
|
##
|
21
19
|
# You can configure for a specified environment like:
|
22
20
|
#
|
23
21
|
# configure :development do
|
24
22
|
# set :foo, :bar
|
23
|
+
# disable :asset_stamp # no asset timestamping for dev
|
25
24
|
# end
|
26
25
|
#
|
27
26
|
|
@@ -32,5 +31,4 @@ class <%= @class_name %> < Padrino::Application
|
|
32
31
|
# render 'errors/404'
|
33
32
|
# end
|
34
33
|
#
|
35
|
-
|
36
34
|
end
|
@@ -18,8 +18,9 @@ module Padrino
|
|
18
18
|
|
19
19
|
argument :name, :desc => "The name of your padrino application"
|
20
20
|
|
21
|
-
class_option :root,
|
22
|
-
class_option :destroy,
|
21
|
+
class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
|
22
|
+
class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
|
23
|
+
class_option :tiny, :desc => "Generate tiny app skeleton", :aliases => '-i', :default => false, :type => :boolean
|
23
24
|
|
24
25
|
# Show help if no argv given
|
25
26
|
require_arguments!
|
@@ -27,16 +28,16 @@ module Padrino
|
|
27
28
|
# Copies over the Padrino base admin application
|
28
29
|
def create_app
|
29
30
|
self.destination_root = options[:root]
|
30
|
-
@
|
31
|
+
@app_name = name.gsub(/\W/, "_").underscore.classify
|
31
32
|
if in_app_root?
|
32
|
-
|
33
|
-
append_file destination_root("config/apps.rb"), "\nPadrino.mount(\"#{@
|
33
|
+
app_skeleton(name, options[:tiny])
|
34
|
+
append_file destination_root("config/apps.rb"), "\nPadrino.mount(\"#{@app_name}\").to(\"/#{name.underscore}\")"
|
34
35
|
|
35
36
|
return if self.behavior == :revoke
|
36
37
|
say (<<-TEXT).gsub(/ {10}/,'')
|
37
38
|
|
38
39
|
=================================================================
|
39
|
-
Your #{@
|
40
|
+
Your #{@app_name} application has been installed.
|
40
41
|
This application has been mounted to /#{name.underscore}
|
41
42
|
You can configure a different path by editing 'config/apps.rb'
|
42
43
|
=================================================================
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'thor/group'
|
2
3
|
|
3
4
|
module Padrino
|
@@ -20,10 +21,10 @@ module Padrino
|
|
20
21
|
ENV['PADRINO_LOG_LEVEL'] ||= "test"
|
21
22
|
boot = options[:root] ? File.join(options[:root], 'config/boot.rb') : 'config/boot.rb'
|
22
23
|
if File.exist?(boot)
|
23
|
-
require boot
|
24
|
+
require File.expand_path(boot)
|
24
25
|
else
|
25
26
|
# If we are outside app we need to load support_lite
|
26
|
-
require 'padrino-core/support_lite'
|
27
|
+
require 'padrino-core/support_lite' unless defined?(SupportLite)
|
27
28
|
end
|
28
29
|
rescue Exception => e
|
29
30
|
puts "=> Problem loading config/boot.rb"
|
@@ -57,9 +57,9 @@ module Padrino
|
|
57
57
|
# For migration files
|
58
58
|
# returns the number of the latest(most current) migration file
|
59
59
|
def return_last_migration_number
|
60
|
-
Dir[destination_root('db/migrate/*.rb')].map
|
60
|
+
Dir[destination_root('db/migrate/*.rb')].map { |f|
|
61
61
|
File.basename(f).match(/^(\d+)/)[0].to_i
|
62
|
-
|
62
|
+
}.max.to_i || 0
|
63
63
|
end
|
64
64
|
|
65
65
|
# Return true if the migration already exist
|
@@ -82,10 +82,10 @@ module Padrino
|
|
82
82
|
# For testing components
|
83
83
|
# Injects the test class text into the test_config file for setting up the test gen
|
84
84
|
# insert_test_suite_setup('...CLASS_NAME...')
|
85
|
-
# => inject_into_file("test/test_config.rb", TEST.gsub(/CLASS_NAME/, @
|
85
|
+
# => inject_into_file("test/test_config.rb", TEST.gsub(/CLASS_NAME/, @app_name), :after => "set :environment, :test")
|
86
86
|
def insert_test_suite_setup(suite_text, options={})
|
87
87
|
options.reverse_merge!(:path => "test/test_config.rb")
|
88
|
-
create_file(options[:path], suite_text.gsub(/CLASS_NAME/, @
|
88
|
+
create_file(options[:path], suite_text.gsub(/CLASS_NAME/, @app_name))
|
89
89
|
end
|
90
90
|
|
91
91
|
# For mocking components
|
@@ -4,7 +4,7 @@ def setup_mock
|
|
4
4
|
when 'rspec'
|
5
5
|
inject_into_file 'spec/spec_helper.rb', " conf.mock_with :rr\n", :after => "Spec::Runner.configure do |conf|\n"
|
6
6
|
when 'riot'
|
7
|
-
inject_into_file "test/test_config.rb","require 'riot/rr'\n", :after => "\"/../config/boot\"\n"
|
7
|
+
inject_into_file "test/test_config.rb","require 'riot/rr'\n", :after => "\"/../config/boot\")\n"
|
8
8
|
else
|
9
9
|
insert_mocking_include "RR::Adapters::RRMethods", :path => "test/test_config.rb"
|
10
10
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
AR = (<<-AR)
|
1
|
+
AR = (<<-AR) unless defined?(AR)
|
2
2
|
##
|
3
3
|
# You can use other adapters like:
|
4
4
|
#
|
@@ -15,18 +15,15 @@ AR = (<<-AR).gsub(/^ {10}/, '') unless defined?(AR)
|
|
15
15
|
# }
|
16
16
|
#
|
17
17
|
ActiveRecord::Base.configurations[:development] = {
|
18
|
-
|
19
|
-
:database => Padrino.root('db', "development.db")
|
18
|
+
!DB_DEVELOPMENT!
|
20
19
|
}
|
21
20
|
|
22
21
|
ActiveRecord::Base.configurations[:production] = {
|
23
|
-
|
24
|
-
:database => Padrino.root('db', "production.db")
|
22
|
+
!DB_PRODUCTION!
|
25
23
|
}
|
26
24
|
|
27
25
|
ActiveRecord::Base.configurations[:test] = {
|
28
|
-
|
29
|
-
:database => Padrino.root('db', "test.db")
|
26
|
+
!DB_TEST!
|
30
27
|
}
|
31
28
|
|
32
29
|
# Setup our logger
|
@@ -49,26 +46,71 @@ ActiveSupport.escape_html_entities_in_json = false
|
|
49
46
|
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env])
|
50
47
|
AR
|
51
48
|
|
49
|
+
MYSQL = (<<-MYSQL)
|
50
|
+
:adapter => 'mysql',
|
51
|
+
:encoding => 'utf8',
|
52
|
+
:reconnect => false,
|
53
|
+
:database => !DB_NAME!,
|
54
|
+
:pool => 5,
|
55
|
+
:username => 'root',
|
56
|
+
:password => '',
|
57
|
+
:host => 'localhost',
|
58
|
+
:socket => '/tmp/mysql.sock'
|
59
|
+
MYSQL
|
60
|
+
|
61
|
+
POSTGRES = (<<-POSTGRES)
|
62
|
+
:adapter => 'postgresql',
|
63
|
+
:database => !DB_NAME!,
|
64
|
+
:username => 'root',
|
65
|
+
:password => '',
|
66
|
+
:host => 'localhost',
|
67
|
+
:port => 5432
|
68
|
+
POSTGRES
|
69
|
+
|
70
|
+
SQLITE = (<<-SQLITE)
|
71
|
+
:adapter => 'sqlite3',
|
72
|
+
:database => !DB_NAME!
|
73
|
+
SQLITE
|
74
|
+
|
75
|
+
|
52
76
|
def setup_orm
|
53
|
-
|
77
|
+
ar = AR
|
78
|
+
case options[:adapter]
|
79
|
+
when 'mysql'
|
80
|
+
ar.gsub! /!DB_DEVELOPMENT!/, MYSQL.gsub(/!DB_NAME!/,"\"#{name}_development\"")
|
81
|
+
ar.gsub! /!DB_PRODUCTION!/, MYSQL.gsub(/!DB_NAME!/,"\"#{name}_production\"")
|
82
|
+
ar.gsub! /!DB_TEST/, MYSQL.gsub(/!DB_NAME!/,"\"#{name}_test\"")
|
83
|
+
require_dependencies 'mysql'
|
84
|
+
when 'postgres'
|
85
|
+
ar.gsub! /!DB_DEVELOPMENT!/, POSTGRES.gsub(/!DB_NAME!/,"\"#{name}_development\"")
|
86
|
+
ar.gsub! /!DB_PRODUCTION!/, POSTGRES.gsub(/!DB_NAME!/,"\"#{name}_production\"")
|
87
|
+
ar.gsub! /!DB_TEST!/, POSTGRES.gsub(/!DB_NAME!/,"\"#{name}_test\"")
|
88
|
+
require_dependencies 'pg', :require => 'postgres'
|
89
|
+
else
|
90
|
+
ar.gsub! /!DB_DEVELOPMENT!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db', \"#{name}_development.db\")")
|
91
|
+
ar.gsub! /!DB_PRODUCTION!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db', \"#{name}_production.db\")")
|
92
|
+
ar.gsub! /!DB_TEST!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db', \"#{name}_test.db\")")
|
93
|
+
require_dependencies 'sqlite3-ruby', :require => 'sqlite3'
|
94
|
+
end
|
54
95
|
require_dependencies 'activerecord', :require => 'active_record'
|
55
|
-
create_file("config/database.rb",
|
96
|
+
create_file("config/database.rb", ar)
|
56
97
|
empty_directory('app/models')
|
57
98
|
end
|
58
99
|
|
59
|
-
AR_MODEL = (<<-MODEL)
|
100
|
+
AR_MODEL = (<<-MODEL) unless defined?(AR_MODEL)
|
60
101
|
class !NAME! < ActiveRecord::Base
|
61
102
|
|
62
103
|
end
|
63
104
|
MODEL
|
64
105
|
|
65
|
-
|
66
|
-
|
106
|
+
# options => { :fields => ["title:string", "body:string"], :app => 'app' }
|
107
|
+
def create_model_file(name, options={})
|
108
|
+
model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
|
67
109
|
model_contents = AR_MODEL.gsub(/!NAME!/, name.to_s.downcase.camelize)
|
68
110
|
create_file(model_path, model_contents,:skip => true)
|
69
111
|
end
|
70
112
|
|
71
|
-
AR_MIGRATION = (<<-MIGRATION)
|
113
|
+
AR_MIGRATION = (<<-MIGRATION) unless defined?(AR_MIGRATION)
|
72
114
|
class !FILECLASS! < ActiveRecord::Migration
|
73
115
|
def self.up
|
74
116
|
!UP!
|
@@ -80,13 +122,13 @@ class !FILECLASS! < ActiveRecord::Migration
|
|
80
122
|
end
|
81
123
|
MIGRATION
|
82
124
|
|
83
|
-
AR_MODEL_UP_MG = (<<-MIGRATION).gsub(
|
125
|
+
AR_MODEL_UP_MG = (<<-MIGRATION).gsub(/^/, ' ') unless defined?(AR_MODEL_UP_MG)
|
84
126
|
create_table :!TABLE! do |t|
|
85
127
|
!FIELDS!
|
86
128
|
end
|
87
129
|
MIGRATION
|
88
130
|
|
89
|
-
AR_MODEL_DOWN_MG = (<<-MIGRATION)
|
131
|
+
AR_MODEL_DOWN_MG = (<<-MIGRATION) unless defined?(AR_MODEL_DOWN_MG)
|
90
132
|
drop_table :!TABLE!
|
91
133
|
MIGRATION
|
92
134
|
|
@@ -97,7 +139,7 @@ def create_model_migration(migration_name, name, columns)
|
|
97
139
|
:up => AR_MODEL_UP_MG, :down => AR_MODEL_DOWN_MG)
|
98
140
|
end
|
99
141
|
|
100
|
-
AR_CHANGE_MG = (<<-MIGRATION).gsub(
|
142
|
+
AR_CHANGE_MG = (<<-MIGRATION).gsub(/^/, ' ') unless defined?(AR_CHANGE_MG)
|
101
143
|
change_table :!TABLE! do |t|
|
102
144
|
!COLUMNS!
|
103
145
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
COUCHREST = (<<-COUCHREST)
|
1
|
+
COUCHREST = (<<-COUCHREST) unless defined?(COUCHREST)
|
2
2
|
case Padrino.env
|
3
3
|
when :development then COUCHDB_NAME = '!NAME!_development'
|
4
4
|
when :production then COUCHDB_NAME = '!NAME!_production'
|
@@ -14,7 +14,7 @@ def setup_orm
|
|
14
14
|
empty_directory('app/models')
|
15
15
|
end
|
16
16
|
|
17
|
-
CR_MODEL = (<<-MODEL)
|
17
|
+
CR_MODEL = (<<-MODEL) unless defined?(CR_MODEL)
|
18
18
|
class !NAME! < CouchRest::ExtendedDocument
|
19
19
|
include CouchRest::Validation
|
20
20
|
|
@@ -26,9 +26,10 @@ class !NAME! < CouchRest::ExtendedDocument
|
|
26
26
|
end
|
27
27
|
MODEL
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
# options => { :fields => ["title:string", "body:string"], :app => 'app' }
|
30
|
+
def create_model_file(name, options={})
|
31
|
+
model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
|
32
|
+
field_tuples = options[:fields].collect { |value| value.split(":") }
|
32
33
|
column_declarations = field_tuples.collect { |field, kind| "property :#{field}" }.join("\n ")
|
33
34
|
model_contents = CR_MODEL.gsub(/!NAME!/, name.to_s.camelize)
|
34
35
|
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
DM = (<<-DM)
|
1
|
+
DM = (<<-DM) unless defined?(DM)
|
2
2
|
##
|
3
3
|
# A MySQL connection:
|
4
4
|
# DataMapper.setup(:default, 'mysql://user:password@localhost/the_database_name')
|
@@ -6,23 +6,46 @@ DM = (<<-DM).gsub(/^ {10}/, '') unless defined?(DM)
|
|
6
6
|
# # A Postgres connection:
|
7
7
|
# DataMapper.setup(:default, 'postgres://user:password@localhost/the_database_name')
|
8
8
|
#
|
9
|
+
# # A Sqlite3 connection
|
10
|
+
# DataMapper.setup(:default, "sqlite3://" + Padrino.root('db', "development.db"))
|
11
|
+
#
|
12
|
+
|
9
13
|
|
10
14
|
DataMapper.logger = logger
|
11
15
|
|
12
16
|
case Padrino.env
|
13
|
-
when :development then DataMapper.setup(:default,
|
14
|
-
when :production then DataMapper.setup(:default,
|
15
|
-
when :test then DataMapper.setup(:default,
|
17
|
+
when :development then DataMapper.setup(:default, !DB_DEVELOPMENT!)
|
18
|
+
when :production then DataMapper.setup(:default, !DB_PRODUCTION!)
|
19
|
+
when :test then DataMapper.setup(:default, !DB_TEST!)
|
16
20
|
end
|
17
21
|
DM
|
18
22
|
|
19
23
|
def setup_orm
|
20
|
-
|
21
|
-
|
24
|
+
dm = DM
|
25
|
+
require_dependencies 'data_mapper'
|
26
|
+
require_dependencies case options[:adapter]
|
27
|
+
when 'mysql'
|
28
|
+
dm.gsub!(/!DB_DEVELOPMENT!/,"\"mysql://root@localhost/#{name}_development\"")
|
29
|
+
dm.gsub!(/!DB_PRODUCTION!/,"\"mysql://root@localhost/#{name}_production\"")
|
30
|
+
dm.gsub!(/!DB_TEST!/,"\"mysql://root@localhost/#{name}_test\"")
|
31
|
+
'dm-mysql-adapter'
|
32
|
+
when 'postgres'
|
33
|
+
dm.gsub!(/!DB_DEVELOPMENT!/,"\"postgres://root@localhost/#{name}_development\"")
|
34
|
+
dm.gsub!(/!DB_PRODUCTION!/,"\"postgres://root@localhost/#{name}_production\"")
|
35
|
+
dm.gsub!(/!DB_TEST!/,"\"postgres://root@localhost/#{name}_test\"")
|
36
|
+
'dm-postgres-adapter'
|
37
|
+
else
|
38
|
+
dm.gsub!(/!DB_DEVELOPMENT!/,"\"sqlite3://\" + Padrino.root('db', \"#{name}_development.db\")")
|
39
|
+
dm.gsub!(/!DB_PRODUCTION!/,"\"sqlite3://\" + Padrino.root('db', \"#{name}_production.db\")")
|
40
|
+
dm.gsub!(/!DB_TEST!/,"\"sqlite3://\" + Padrino.root('db', \"#{name}_test.db\")")
|
41
|
+
'dm-sqlite-adapter'
|
42
|
+
end
|
43
|
+
|
44
|
+
create_file("config/database.rb", dm)
|
22
45
|
empty_directory('app/models')
|
23
46
|
end
|
24
47
|
|
25
|
-
DM_MODEL = (<<-MODEL)
|
48
|
+
DM_MODEL = (<<-MODEL) unless defined?(DM_MODEL)
|
26
49
|
class !NAME!
|
27
50
|
include DataMapper::Resource
|
28
51
|
|
@@ -32,17 +55,18 @@ class !NAME!
|
|
32
55
|
end
|
33
56
|
MODEL
|
34
57
|
|
35
|
-
|
36
|
-
|
58
|
+
# options => { :fields => ["title:string", "body:string"], :app => 'app' }
|
59
|
+
def create_model_file(name, options={})
|
60
|
+
model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
|
37
61
|
model_contents = DM_MODEL.gsub(/!NAME!/, name.to_s.downcase.camelize)
|
38
|
-
field_tuples = fields.collect { |value| value.split(":") }
|
62
|
+
field_tuples = options[:fields].collect { |value| value.split(":") }
|
39
63
|
field_tuples.collect! { |field, kind| kind =~ /datetime/i ? [field, 'DateTime'] : [field, kind] } # fix datetime
|
40
64
|
column_declarations = field_tuples.collect { |field, kind|"property :#{field}, #{kind.camelize}" }.join("\n ")
|
41
65
|
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
42
66
|
create_file(model_path, model_contents)
|
43
67
|
end
|
44
68
|
|
45
|
-
DM_MIGRATION = (<<-MIGRATION)
|
69
|
+
DM_MIGRATION = (<<-MIGRATION) unless defined?(DM_MIGRATION)
|
46
70
|
migration !VERSION!, :!FILENAME! do
|
47
71
|
up do
|
48
72
|
!UP!
|
@@ -54,24 +78,24 @@ migration !VERSION!, :!FILENAME! do
|
|
54
78
|
end
|
55
79
|
MIGRATION
|
56
80
|
|
57
|
-
DM_MODEL_UP_MG = (<<-MIGRATION).gsub(
|
81
|
+
DM_MODEL_UP_MG = (<<-MIGRATION).gsub(/^/, ' ') unless defined?(DM_MODEL_UP_MG)
|
58
82
|
create_table :!TABLE! do
|
59
|
-
column :id, Integer, :serial => true
|
83
|
+
column :id, DataMapper::Property::Integer, :serial => true
|
60
84
|
!FIELDS!
|
61
85
|
end
|
62
86
|
MIGRATION
|
63
87
|
|
64
|
-
DM_MODEL_DOWN_MG = (<<-MIGRATION)
|
88
|
+
DM_MODEL_DOWN_MG = (<<-MIGRATION) unless defined?(DM_MODEL_DOWN_MG)
|
65
89
|
drop_table :!TABLE!
|
66
90
|
MIGRATION
|
67
91
|
|
68
92
|
def create_model_migration(migration_name, name, columns)
|
69
93
|
output_model_migration(migration_name, name, columns,
|
70
|
-
:column_format => Proc.new { |field, kind| "column :#{field},
|
94
|
+
:column_format => Proc.new { |field, kind| "column :#{field}, DataMapper::Property::#{kind.classify}" },
|
71
95
|
:base => DM_MIGRATION, :up => DM_MODEL_UP_MG, :down => DM_MODEL_DOWN_MG)
|
72
96
|
end
|
73
97
|
|
74
|
-
DM_CHANGE_MG = (<<-MIGRATION).gsub(
|
98
|
+
DM_CHANGE_MG = (<<-MIGRATION).gsub(/^/, ' ') unless defined?(DM_CHANGE_MG)
|
75
99
|
modify_table :!TABLE! do
|
76
100
|
!COLUMNS!
|
77
101
|
end
|
@@ -80,7 +104,7 @@ MIGRATION
|
|
80
104
|
def create_migration_file(migration_name, name, columns)
|
81
105
|
output_migration_file(migration_name, name, columns,
|
82
106
|
:base => DM_MIGRATION, :change_format => DM_CHANGE_MG,
|
83
|
-
:add => Proc.new { |field, kind| "add_column :#{field},
|
107
|
+
:add => Proc.new { |field, kind| "add_column :#{field}, DataMapper::Property::#{kind.classify}" },
|
84
108
|
:remove => Proc.new { |field, kind| "drop_column :#{field}" }
|
85
109
|
)
|
86
110
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
MONGOID = (<<-MONGO)
|
1
|
+
MONGOID = (<<-MONGO) unless defined?(MONGOID)
|
2
2
|
|
3
3
|
# Connection.new takes host, port
|
4
4
|
host = 'localhost'
|
@@ -29,11 +29,11 @@ MONGO
|
|
29
29
|
def setup_orm
|
30
30
|
require_dependencies 'bson_ext', :require => 'mongo'
|
31
31
|
require_dependencies 'mongoid'
|
32
|
-
create_file("config/database.rb", MONGOID.gsub(/!NAME!/, name.underscore))
|
32
|
+
create_file("config/database.rb", MONGOID.gsub(/!NAME!/, name.underscore.gsub('.','_')))
|
33
33
|
empty_directory('app/models')
|
34
34
|
end
|
35
35
|
|
36
|
-
MONGOID_MODEL = (<<-MODEL)
|
36
|
+
MONGOID_MODEL = (<<-MODEL) unless defined?(MONGOID_MODEL)
|
37
37
|
class !NAME!
|
38
38
|
include Mongoid::Document
|
39
39
|
include Mongoid::Timestamps # adds created_at and updated_at fields
|
@@ -50,9 +50,10 @@ class !NAME!
|
|
50
50
|
end
|
51
51
|
MODEL
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
# options => { :fields => ["title:string", "body:string"], :app => 'app' }
|
54
|
+
def create_model_file(name, options={})
|
55
|
+
model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
|
56
|
+
field_tuples = options[:fields].collect { |value| value.split(":") }
|
56
57
|
column_declarations = field_tuples.collect { |field, kind| "field :#{field}, :type => #{kind.camelize}" }.join("\n ")
|
57
58
|
model_contents = MONGOID_MODEL.gsub(/!NAME!/, name.to_s.camelize)
|
58
59
|
model_contents.gsub!(/!FIELDS!/, column_declarations)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
MONGO = (<<-MONGO)
|
1
|
+
MONGO = (<<-MONGO) unless defined?(MONGO)
|
2
2
|
MongoMapper.connection = Mongo::Connection.new('localhost', nil, :logger => logger)
|
3
3
|
|
4
4
|
case Padrino.env
|
@@ -15,7 +15,7 @@ def setup_orm
|
|
15
15
|
empty_directory('app/models')
|
16
16
|
end
|
17
17
|
|
18
|
-
MM_MODEL = (<<-MODEL)
|
18
|
+
MM_MODEL = (<<-MODEL) unless defined?(MM_MODEL)
|
19
19
|
class !NAME!
|
20
20
|
include MongoMapper::Document
|
21
21
|
|
@@ -25,9 +25,10 @@ class !NAME!
|
|
25
25
|
end
|
26
26
|
MODEL
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
# options => { :fields => ["title:string", "body:string"], :app => 'app' }
|
29
|
+
def create_model_file(name, options={})
|
30
|
+
model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
|
31
|
+
field_tuples = options[:fields].collect { |value| value.split(":") }
|
31
32
|
column_declarations = field_tuples.collect { |field, kind| "key :#{field}, #{kind.camelize}" }.join("\n ")
|
32
33
|
model_contents = MM_MODEL.gsub(/!NAME!/, name.to_s.camelize)
|
33
34
|
model_contents.gsub!(/!FIELDS!/, column_declarations)
|