padrino-gen 0.9.9 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/README.rdoc +10 -10
  2. data/Rakefile +4 -15
  3. data/bin/padrino-gen +3 -0
  4. data/lib/padrino-gen/generators/actions.rb +10 -4
  5. data/lib/padrino-gen/generators/app/app.rb.tt +2 -2
  6. data/lib/padrino-gen/generators/components/mocks/mocha.rb +9 -0
  7. data/lib/padrino-gen/generators/components/mocks/rr.rb +11 -0
  8. data/lib/padrino-gen/generators/components/orms/activerecord.rb +112 -0
  9. data/lib/padrino-gen/generators/components/orms/couchrest.rb +44 -0
  10. data/lib/padrino-gen/generators/components/orms/datamapper.rb +86 -0
  11. data/lib/padrino-gen/generators/components/orms/mongoid.rb +68 -0
  12. data/lib/padrino-gen/generators/components/orms/mongomapper.rb +43 -0
  13. data/lib/padrino-gen/generators/components/orms/sequel.rb +71 -0
  14. data/lib/padrino-gen/generators/components/renderers/erb.rb +3 -0
  15. data/lib/padrino-gen/generators/components/renderers/haml.rb +3 -0
  16. data/lib/padrino-gen/generators/components/scripts/extcore.rb +4 -0
  17. data/lib/padrino-gen/generators/components/scripts/jquery.rb +4 -0
  18. data/lib/padrino-gen/generators/components/scripts/mootools.rb +4 -0
  19. data/lib/padrino-gen/generators/components/scripts/prototype.rb +5 -0
  20. data/lib/padrino-gen/generators/components/scripts/rightjs.rb +4 -0
  21. data/lib/padrino-gen/generators/components/stylesheets/less.rb +33 -0
  22. data/lib/padrino-gen/generators/components/stylesheets/sass.rb +25 -0
  23. data/lib/padrino-gen/generators/components/tests/bacon.rb +64 -0
  24. data/lib/padrino-gen/generators/components/tests/cucumber.rb +63 -0
  25. data/lib/padrino-gen/generators/components/tests/riot.rb +69 -0
  26. data/lib/padrino-gen/generators/components/tests/rspec.rb +66 -0
  27. data/lib/padrino-gen/generators/components/tests/shoulda.rb +70 -0
  28. data/lib/padrino-gen/generators/components/tests/testspec.rb +63 -0
  29. data/lib/padrino-gen/generators/controller.rb +4 -4
  30. data/lib/padrino-gen/generators/project/config/apps.rb.tt +12 -4
  31. data/lib/padrino-gen/generators/project/config/boot.rb +1 -1
  32. data/lib/padrino-gen/generators/project.rb +1 -1
  33. data/lib/padrino-gen/generators/templates/controller.rb.tt +1 -1
  34. data/lib/padrino-gen/generators/templates/scripts/ext-core.js +8 -0
  35. data/lib/padrino-gen/generators/templates/scripts/jquery.js +150 -15
  36. data/lib/padrino-gen/padrino-tasks/activerecord.rb +1 -1
  37. data/lib/padrino-gen/padrino-tasks/mongomapper.rb +1 -1
  38. data/lib/padrino-gen/padrino-tasks/sequel.rb +37 -0
  39. data/lib/padrino-gen.rb +9 -2
  40. data/padrino-gen.gemspec +30 -28
  41. data/test/helper.rb +5 -0
  42. data/test/test_app_generator.rb +11 -19
  43. data/test/test_cli.rb +4 -6
  44. data/test/test_controller_generator.rb +43 -33
  45. data/test/test_mailer_generator.rb +11 -17
  46. data/test/test_migration_generator.rb +42 -47
  47. data/test/test_model_generator.rb +90 -89
  48. data/test/test_project_generator.rb +43 -39
  49. metadata +30 -28
  50. data/VERSION +0 -1
  51. data/lib/padrino-gen/generators/components/mocks/mocha_gen.rb +0 -20
  52. data/lib/padrino-gen/generators/components/mocks/rr_gen.rb +0 -22
  53. data/lib/padrino-gen/generators/components/orms/activerecord_gen.rb +0 -123
  54. data/lib/padrino-gen/generators/components/orms/couchrest_gen.rb +0 -56
  55. data/lib/padrino-gen/generators/components/orms/datamapper_gen.rb +0 -97
  56. data/lib/padrino-gen/generators/components/orms/mongoid_gen.rb +0 -80
  57. data/lib/padrino-gen/generators/components/orms/mongomapper_gen.rb +0 -55
  58. data/lib/padrino-gen/generators/components/orms/sequel_gen.rb +0 -83
  59. data/lib/padrino-gen/generators/components/renderers/erb_gen.rb +0 -14
  60. data/lib/padrino-gen/generators/components/renderers/haml_gen.rb +0 -15
  61. data/lib/padrino-gen/generators/components/scripts/jquery_gen.rb +0 -15
  62. data/lib/padrino-gen/generators/components/scripts/mootools_gen.rb +0 -15
  63. data/lib/padrino-gen/generators/components/scripts/prototype_gen.rb +0 -16
  64. data/lib/padrino-gen/generators/components/scripts/rightjs_gen.rb +0 -15
  65. data/lib/padrino-gen/generators/components/stylesheets/less_gen.rb +0 -43
  66. data/lib/padrino-gen/generators/components/stylesheets/sass_gen.rb +0 -35
  67. data/lib/padrino-gen/generators/components/tests/bacon_test_gen.rb +0 -75
  68. data/lib/padrino-gen/generators/components/tests/cucumber_test_gen.rb +0 -76
  69. data/lib/padrino-gen/generators/components/tests/riot_test_gen.rb +0 -80
  70. data/lib/padrino-gen/generators/components/tests/rspec_test_gen.rb +0 -85
  71. data/lib/padrino-gen/generators/components/tests/shoulda_test_gen.rb +0 -81
  72. data/lib/padrino-gen/generators/components/tests/testspec_test_gen.rb +0 -74
data/README.rdoc CHANGED
@@ -7,7 +7,7 @@ Padrino comes preloaded with flexible code generators powered in part by the exc
7
7
  both in creating new applications and building on existing ones. The generators have been built to be as library agnostic
8
8
  as possible, supporting a myriad of test frameworks, js libraries, mocking libraries, etc.
9
9
 
10
- See the guide for {Padrino Generators}[http://wiki.github.com/padrino/padrino-framework/generators] for a
10
+ See the guide for {Padrino Generators}[http://www.padrinorb.com/guides/generators] for a
11
11
  more in-depth look at the system.
12
12
 
13
13
  === Application Generator
@@ -42,11 +42,11 @@ test:: rspec (default), bacon, shoulda, cucumber, testspec, riot
42
42
  renderer:: haml (default), erb
43
43
  stylesheet:: sass (default), less
44
44
  mock:: none (default), mocha, rr
45
- script:: none (default), jquery, prototype, mootools, rightjs
46
- orm:: none (default), mongomapper, mongoid, activerecord, sequel, couchrest
45
+ script:: none (default), jquery, prototype, mootools, rightjs, extcore
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
49
- {Padrino Generators}[http://wiki.github.com/padrino/padrino-framework/generators].
49
+ {Padrino Generators}[http://www.padrinorb.com/guides/generators].
50
50
 
51
51
  === Sub App Generator
52
52
 
@@ -70,7 +70,7 @@ By default these apps are mounted under:
70
70
  but you can edit config/apps.rb and change it.
71
71
 
72
72
  To learn more about the subapp generator, check out the guide to
73
- {Padrino Generators}[http://wiki.github.com/padrino/padrino-framework/generators].
73
+ {Padrino Generators}[http://www.padrinorb.com/guides/generators].
74
74
 
75
75
  === Model Generator
76
76
 
@@ -91,7 +91,7 @@ You can also specify desired fields to be contained within your User model:
91
91
  $ padrino-gen model User name:string age:integer email:string
92
92
 
93
93
  To learn more about the model generator, check out the guide to
94
- {Padrino Generators}[http://wiki.github.com/padrino/padrino-framework/generators].
94
+ {Padrino Generators}[http://www.padrinorb.com/guides/generators].
95
95
 
96
96
  === Migration Generator
97
97
 
@@ -108,7 +108,7 @@ Using the migration generator is as simple as:
108
108
  $ padrino-gen migration RemoveFieldsFromUsers
109
109
 
110
110
  To learn more about the migration generator, check out the guide to
111
- {Padrino Generators}[http://wiki.github.com/padrino/padrino-framework/generators].
111
+ {Padrino Generators}[http://www.padrinorb.com/guides/generators].
112
112
 
113
113
  === Controller Generator
114
114
 
@@ -128,7 +128,7 @@ You can also specify desired actions to be added to your controller:
128
128
  $ padrino-gen controller Admin get:index get:new post:create
129
129
 
130
130
  To learn more about the controller generator, check out the guide to
131
- {Padrino Generators}[http://wiki.github.com/padrino/padrino-framework/generators].
131
+ {Padrino Generators}[http://www.padrinorb.com/guides/generators].
132
132
 
133
133
  === Mailer Generator
134
134
 
@@ -141,8 +141,8 @@ Using the mailer generator is as simple as:
141
141
  $ padrino-gen mailer UserNotifier
142
142
 
143
143
  To learn more about the mailer generator, check out the guide to
144
- {Padrino Generators}[http://wiki.github.com/padrino/padrino-framework/generators].
144
+ {Padrino Generators}[http://www.padrinorb.com/guides/generators].
145
145
 
146
146
  == Copyright
147
147
 
148
- Copyright (c) 2010 Padrino. See LICENSE for details.
148
+ Copyright (c) 2010 Padrino. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
 
4
- GEM_VERSION = File.read(File.dirname(__FILE__) + '/VERSION')
4
+ require File.expand_path("../../padrino-core/lib/padrino-core/version.rb", __FILE__)
5
5
 
6
6
  begin
7
7
  require 'jeweler'
@@ -14,7 +14,8 @@ begin
14
14
  gem.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
15
15
  gem.executables = ["padrino-gen"]
16
16
  gem.rubyforge_project = 'padrino-gen'
17
- gem.add_runtime_dependency "padrino-core", "= #{GEM_VERSION}"
17
+ gem.version = Padrino.version
18
+ gem.add_runtime_dependency "padrino-core", "= #{Padrino.version}"
18
19
  gem.add_development_dependency "haml", ">= 2.2.1"
19
20
  gem.add_development_dependency "shoulda", ">= 2.10.3"
20
21
  gem.add_development_dependency "mocha", ">= 0.9.7"
@@ -50,16 +51,4 @@ rescue LoadError
50
51
  end
51
52
  end
52
53
 
53
- # task :test => :check_dependencies
54
-
55
- task :default => :test
56
-
57
- require 'rake/rdoctask'
58
- Rake::RDocTask.new do |rdoc|
59
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
60
-
61
- rdoc.rdoc_dir = 'rdoc'
62
- rdoc.title = "padrino-gen #{version}"
63
- rdoc.rdoc_files.include('README*')
64
- rdoc.rdoc_files.include('lib/**/*.rb')
65
- end
54
+ task :default => :test
data/bin/padrino-gen CHANGED
@@ -7,6 +7,9 @@ $:.unshift(padrino_gen_path) if File.directory?(padrino_gen_path) && !$:.include
7
7
  padrino_core_path = File.expand_path('../../../padrino-core/lib', __FILE__)
8
8
  $:.unshift(padrino_core_path) if File.directory?(padrino_core_path) && !$:.include?(padrino_core_path)
9
9
 
10
+ padrino_local_path = Dir.pwd
11
+ $:.unshift(padrino_local_path) if File.directory?(padrino_local_path) && !$:.include?(padrino_local_path)
12
+
10
13
  require 'padrino-gen'
11
14
  require 'padrino-gen/generators/cli'
12
15
 
@@ -1,6 +1,7 @@
1
1
  module Padrino
2
2
  module Generators
3
3
  class AppRootNotFound < RuntimeError; end
4
+
4
5
  module Actions
5
6
 
6
7
  def self.included(base)
@@ -12,14 +13,19 @@ module Padrino
12
13
  def execute_component_setup(component, choice)
13
14
  return true && say("Skipping generator for #{component} component...", :yellow) if choice.to_s == 'none'
14
15
  say "Applying '#{choice}' (#{component})...", :yellow
15
- self.class.send(:include, generator_module_for(choice, component))
16
+ apply_component_for(choice, component)
16
17
  send("setup_#{component}") if respond_to?("setup_#{component}")
17
18
  end
18
19
 
19
20
  # Returns the related module for a given component and option
20
21
  # generator_module_for('rr', :mock)
21
- def generator_module_for(choice, component)
22
- "Padrino::Generators::Components::#{component.to_s.capitalize.pluralize}::#{choice.to_s.capitalize}Gen".constantize
22
+ def apply_component_for(choice, component)
23
+ # I need to override Thor#apply because for unknow reason :verobse => false break tasks.
24
+ path = File.expand_path(File.dirname(__FILE__) + "/components/#{component.to_s.pluralize}/#{choice}.rb")
25
+ say_status :apply, "#{component.to_s.pluralize}/#{choice}"
26
+ shell.padding += 1
27
+ instance_eval(open(path).read)
28
+ shell.padding -= 1
23
29
  end
24
30
 
25
31
  # Includes the component module for the given component and choice
@@ -29,7 +35,7 @@ module Padrino
29
35
  def include_component_module_for(component, choice=nil)
30
36
  choice = fetch_component_choice(component) unless choice
31
37
  return false if choice.to_s == 'none'
32
- self.class.send(:include, generator_module_for(choice, component))
38
+ apply_component_for(choice, component)
33
39
  end
34
40
 
35
41
  # Returns the component choice stored within the .component file of an application
@@ -5,13 +5,13 @@ class <%= @class_name %> < Padrino::Application
5
5
  #
6
6
  # set :raise_errors, true # Show exceptions (default for development)
7
7
  # set :public, "foo/bar" # Location for static assets (default root/public)
8
- # set :sessions, false # Enabled by default
9
8
  # set :reload, false # Reload application files (default in development)
10
9
  # set :default_builder, "foo" # Set a custom form builder (default 'StandardFormBuilder')
11
10
  # set :locale_path, "bar" # Set path for I18n translations (default your_app/locales)
11
+ # enable :sessions # Disabled by default
12
+ # disable :flash # Disables rack-flash (enabled by default if sessions)
12
13
  # disable :padrino_helpers # Disables padrino markup helpers (enabled by default if present)
13
14
  # disable :padrino_mailer # Disables padrino mailer (enabled by default if present)
14
- # disable :flash # Disables rack-flash (enabled by default)
15
15
  # enable :authentication # Enable padrino-admin authentication (disabled by default)
16
16
  # layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application)
17
17
  #
@@ -0,0 +1,9 @@
1
+ def setup_mock
2
+ require_dependencies 'mocha', :group => 'test'
3
+ case options[:test].to_s
4
+ when 'rspec'
5
+ inject_into_file 'spec/spec_helper.rb', " conf.mock_with :mocha\n", :after => "Spec::Runner.configure do |conf|\n"
6
+ else
7
+ insert_mocking_include "Mocha::API"
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ def setup_mock
2
+ require_dependencies 'rr', :group => 'test'
3
+ case options[:test].to_s
4
+ when 'rspec'
5
+ inject_into_file 'spec/spec_helper.rb', " conf.mock_with :rr\n", :after => "Spec::Runner.configure do |conf|\n"
6
+ when 'riot'
7
+ inject_into_file "test/test_config.rb","require 'riot/rr'\n", :after => "\"/../config/boot\"\n"
8
+ else
9
+ insert_mocking_include "RR::Adapters::RRMethods", :path => "test/test_config.rb"
10
+ end
11
+ end
@@ -0,0 +1,112 @@
1
+ AR = (<<-AR).gsub(/^ {10}/, '') unless defined?(AR)
2
+ ##
3
+ # You can use other adapters like:
4
+ #
5
+ # ActiveRecord::Base.configurations[:development] = {
6
+ # :adapter => 'mysql',
7
+ # :encoding => 'utf8',
8
+ # :reconnect => false,
9
+ # :database => 'your_database',
10
+ # :pool => 5,
11
+ # :username => 'root',
12
+ # :password => '',
13
+ # :host => 'localhost',
14
+ # :socket => '/tmp/mysql.sock'
15
+ # }
16
+ #
17
+ ActiveRecord::Base.configurations[:development] = {
18
+ :adapter => 'sqlite3',
19
+ :database => Padrino.root('db', "development.db")
20
+ }
21
+
22
+ ActiveRecord::Base.configurations[:production] = {
23
+ :adapter => 'sqlite3',
24
+ :database => Padrino.root('db', "production.db")
25
+ }
26
+
27
+ ActiveRecord::Base.configurations[:test] = {
28
+ :adapter => 'sqlite3',
29
+ :database => Padrino.root('db', "test.db")
30
+ }
31
+
32
+ # Setup our logger
33
+ ActiveRecord::Base.logger = logger
34
+
35
+ # Include Active Record class name as root for JSON serialized output.
36
+ ActiveRecord::Base.include_root_in_json = true
37
+
38
+ # Store the full class name (including module namespace) in STI type column.
39
+ ActiveRecord::Base.store_full_sti_class = true
40
+
41
+ # Use ISO 8601 format for JSON serialized times and dates.
42
+ ActiveSupport.use_standard_json_time_format = true
43
+
44
+ # Don't escape HTML entities in JSON, leave that for the #json_escape helper.
45
+ # if you're including raw json in an HTML page.
46
+ ActiveSupport.escape_html_entities_in_json = false
47
+
48
+ # Now we can estabilish connection with our db
49
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env])
50
+ AR
51
+
52
+ def setup_orm
53
+ require_dependencies 'sqlite3-ruby', :require => 'sqlite3'
54
+ require_dependencies 'activerecord', :require => 'active_record'
55
+ create_file("config/database.rb", AR)
56
+ empty_directory('app/models')
57
+ end
58
+
59
+ AR_MODEL = (<<-MODEL).gsub(/^ {10}/, '')
60
+ class !NAME! < ActiveRecord::Base
61
+
62
+ end
63
+ MODEL
64
+
65
+ def create_model_file(name, fields)
66
+ model_path = destination_root('app/models/', "#{name.to_s.underscore}.rb")
67
+ model_contents = AR_MODEL.gsub(/!NAME!/, name.to_s.downcase.camelize)
68
+ create_file(model_path, model_contents,:skip => true)
69
+ end
70
+
71
+ AR_MIGRATION = (<<-MIGRATION).gsub(/^ {10}/, '')
72
+ class !FILECLASS! < ActiveRecord::Migration
73
+ def self.up
74
+ !UP!
75
+ end
76
+
77
+ def self.down
78
+ !DOWN!
79
+ end
80
+ end
81
+ MIGRATION
82
+
83
+ AR_MODEL_UP_MG = (<<-MIGRATION).gsub(/^ {6}/, '')
84
+ create_table :!TABLE! do |t|
85
+ !FIELDS!
86
+ end
87
+ MIGRATION
88
+
89
+ AR_MODEL_DOWN_MG = (<<-MIGRATION).gsub(/^ {10}/, '')
90
+ drop_table :!TABLE!
91
+ MIGRATION
92
+
93
+ def create_model_migration(migration_name, name, columns)
94
+ output_model_migration(migration_name, name, columns,
95
+ :base => AR_MIGRATION,
96
+ :column_format => Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
97
+ :up => AR_MODEL_UP_MG, :down => AR_MODEL_DOWN_MG)
98
+ end
99
+
100
+ AR_CHANGE_MG = (<<-MIGRATION).gsub(/^ {6}/, '')
101
+ change_table :!TABLE! do |t|
102
+ !COLUMNS!
103
+ end
104
+ MIGRATION
105
+
106
+ def create_migration_file(migration_name, name, columns)
107
+ output_migration_file(migration_name, name, columns,
108
+ :base => AR_MIGRATION, :change_format => AR_CHANGE_MG,
109
+ :add => Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
110
+ :remove => Proc.new { |field, kind| "t.remove :#{field}" }
111
+ )
112
+ end
@@ -0,0 +1,44 @@
1
+ COUCHREST = (<<-COUCHREST).gsub(/^ {10}/, '') unless defined?(COUCHREST)
2
+ case Padrino.env
3
+ when :development then COUCHDB_NAME = '!NAME!_development'
4
+ when :production then COUCHDB_NAME = '!NAME!_production'
5
+ when :test then COUCHDB_NAME = '!NAME!_test'
6
+ end
7
+ COUCHDB = CouchRest.database!(COUCHDB_NAME)
8
+ COUCHREST
9
+
10
+ def setup_orm
11
+ require_dependencies 'couchrest'
12
+ require_dependencies 'json_pure'
13
+ create_file("config/database.rb", COUCHREST.gsub(/!NAME!/, name.underscore))
14
+ empty_directory('app/models')
15
+ end
16
+
17
+ CR_MODEL = (<<-MODEL).gsub(/^ {10}/, '') unless defined?(CR_MODEL)
18
+ class !NAME! < CouchRest::ExtendedDocument
19
+ include CouchRest::Validation
20
+
21
+ use_database COUCHDB
22
+
23
+ unique_id :id
24
+ # property <name>
25
+ !FIELDS!
26
+ end
27
+ MODEL
28
+
29
+ def create_model_file(name, fields)
30
+ model_path = destination_root('app/models/', "#{name.to_s.underscore}.rb")
31
+ field_tuples = fields.collect { |value| value.split(":") }
32
+ column_declarations = field_tuples.collect { |field, kind| "property :#{field}" }.join("\n ")
33
+ model_contents = CR_MODEL.gsub(/!NAME!/, name.to_s.camelize)
34
+ model_contents.gsub!(/!FIELDS!/, column_declarations)
35
+ create_file(model_path, model_contents)
36
+ end
37
+
38
+ def create_model_migration(filename, name, fields)
39
+ # NO MIGRATION NEEDED
40
+ end
41
+
42
+ def create_migration_file(migration_name, name, columns)
43
+ # NO MIGRATION NEEDED
44
+ end
@@ -0,0 +1,86 @@
1
+ DM = (<<-DM).gsub(/^ {10}/, '') unless defined?(DM)
2
+ ##
3
+ # A MySQL connection:
4
+ # DataMapper.setup(:default, 'mysql://user:password@localhost/the_database_name')
5
+ #
6
+ # # A Postgres connection:
7
+ # DataMapper.setup(:default, 'postgres://user:password@localhost/the_database_name')
8
+ #
9
+
10
+ DataMapper.logger = logger
11
+
12
+ case Padrino.env
13
+ when :development then DataMapper.setup(:default, "sqlite3://" + Padrino.root('db', "development.db"))
14
+ when :production then DataMapper.setup(:default, "sqlite3://" + Padrino.root('db', "production.db"))
15
+ when :test then DataMapper.setup(:default, "sqlite3://" + Padrino.root('db', "test.db"))
16
+ end
17
+ DM
18
+
19
+ def setup_orm
20
+ require_dependencies 'data_objects', 'do_sqlite3', 'datamapper'
21
+ create_file("config/database.rb", DM)
22
+ empty_directory('app/models')
23
+ end
24
+
25
+ DM_MODEL = (<<-MODEL).gsub(/^ {10}/, '') unless defined?(DM_MODEL)
26
+ class !NAME!
27
+ include DataMapper::Resource
28
+
29
+ # property <name>, <type>
30
+ property :id, Serial
31
+ !FIELDS!
32
+ end
33
+ MODEL
34
+
35
+ def create_model_file(name, fields)
36
+ model_path = destination_root('app/models/', "#{name.to_s.underscore}.rb")
37
+ model_contents = DM_MODEL.gsub(/!NAME!/, name.to_s.downcase.camelize)
38
+ field_tuples = fields.collect { |value| value.split(":") }
39
+ field_tuples.collect! { |field, kind| kind =~ /datetime/i ? [field, 'DateTime'] : [field, kind] } # fix datetime
40
+ column_declarations = field_tuples.collect { |field, kind|"property :#{field}, #{kind.camelize}" }.join("\n ")
41
+ model_contents.gsub!(/!FIELDS!/, column_declarations)
42
+ create_file(model_path, model_contents)
43
+ end
44
+
45
+ DM_MIGRATION = (<<-MIGRATION).gsub(/^ {10}/, '') unless defined?(DM_MIGRATION)
46
+ migration !VERSION!, :!FILENAME! do
47
+ up do
48
+ !UP!
49
+ end
50
+
51
+ down do
52
+ !DOWN!
53
+ end
54
+ end
55
+ MIGRATION
56
+
57
+ DM_MODEL_UP_MG = (<<-MIGRATION).gsub(/^ {6}/, '') unless defined?(DM_MODEL_UP_MG)
58
+ create_table :!TABLE! do
59
+ column :id, Integer, :serial => true
60
+ !FIELDS!
61
+ end
62
+ MIGRATION
63
+
64
+ DM_MODEL_DOWN_MG = (<<-MIGRATION).gsub(/^ {10}/, '') unless defined?(DM_MODEL_DOWN_MG)
65
+ drop_table :!TABLE!
66
+ MIGRATION
67
+
68
+ def create_model_migration(migration_name, name, columns)
69
+ output_model_migration(migration_name, name, columns,
70
+ :column_format => Proc.new { |field, kind| "column :#{field}, \"#{kind.upcase}\"" },
71
+ :base => DM_MIGRATION, :up => DM_MODEL_UP_MG, :down => DM_MODEL_DOWN_MG)
72
+ end
73
+
74
+ DM_CHANGE_MG = (<<-MIGRATION).gsub(/^ {6}/, '') unless defined?(DM_CHANGE_MG)
75
+ modify_table :!TABLE! do
76
+ !COLUMNS!
77
+ end
78
+ MIGRATION
79
+
80
+ def create_migration_file(migration_name, name, columns)
81
+ output_migration_file(migration_name, name, columns,
82
+ :base => DM_MIGRATION, :change_format => DM_CHANGE_MG,
83
+ :add => Proc.new { |field, kind| "add_column :#{field}, #{kind.camelize}" },
84
+ :remove => Proc.new { |field, kind| "drop_column :#{field}" }
85
+ )
86
+ end
@@ -0,0 +1,68 @@
1
+ MONGOID = (<<-MONGO).gsub(/^ {10}/, '') unless defined?(MONGOID)
2
+
3
+ # Connection.new takes host, port
4
+ host = 'localhost'
5
+ port = Mongo::Connection::DEFAULT_PORT
6
+
7
+ database_name = case Padrino.env
8
+ when :development then '!NAME!_development'
9
+ when :production then '!NAME!_production'
10
+ when :test then '!NAME!_test'
11
+ end
12
+
13
+ Mongoid.database = Mongo::Connection.new(host, port).db(database_name)
14
+
15
+ # You can also configure Mongoid this way
16
+ # Mongoid.configure do |config|
17
+ # name = @settings["database"]
18
+ # host = @settings["host"]
19
+ # config.master = Mongo::Connection.new.db(name)
20
+ # config.slaves = [
21
+ # Mongo::Connection.new(host, @settings["slave_one"]["port"], :slave_ok => true).db(name),
22
+ # Mongo::Connection.new(host, @settings["slave_two"]["port"], :slave_ok => true).db(name)
23
+ # ]
24
+ # end
25
+ #
26
+ # More installation and setup notes are on http://mongoid.org/docs/
27
+ MONGO
28
+
29
+ def setup_orm
30
+ require_dependencies 'bson_ext', :require => 'mongo'
31
+ require_dependencies 'mongoid'
32
+ create_file("config/database.rb", MONGOID.gsub(/!NAME!/, name.underscore))
33
+ empty_directory('app/models')
34
+ end
35
+
36
+ MONGOID_MODEL = (<<-MODEL).gsub(/^ {10}/, '') unless defined?(MONGOID_MODEL)
37
+ class !NAME!
38
+ include Mongoid::Document
39
+ include Mongoid::Timestamps # adds created_at and updated_at fields
40
+
41
+ # field <name>, :type => <type>, :default => <value>
42
+ !FIELDS!
43
+
44
+ # You can define indexes on documents using the index macro:
45
+ # index :field <, :unique => true>
46
+
47
+ # You can create a composite key in mongoid to replace the default id using the key macro:
48
+ # key :field <, :another_field, :one_more ....>
49
+
50
+ end
51
+ MODEL
52
+
53
+ def create_model_file(name, fields)
54
+ model_path = destination_root('app/models/', "#{name.to_s.underscore}.rb")
55
+ field_tuples = fields.collect { |value| value.split(":") }
56
+ column_declarations = field_tuples.collect { |field, kind| "field :#{field}, :type => #{kind.camelize}" }.join("\n ")
57
+ model_contents = MONGOID_MODEL.gsub(/!NAME!/, name.to_s.camelize)
58
+ model_contents.gsub!(/!FIELDS!/, column_declarations)
59
+ create_file(model_path, model_contents)
60
+ end
61
+
62
+ def create_model_migration(filename, name, fields)
63
+ # NO MIGRATION NEEDED
64
+ end
65
+
66
+ def create_migration_file(migration_name, name, columns)
67
+ # NO MIGRATION NEEDED
68
+ end
@@ -0,0 +1,43 @@
1
+ MONGO = (<<-MONGO).gsub(/^ {10}/, '') unless defined?(MONGO)
2
+ MongoMapper.connection = Mongo::Connection.new('localhost', nil, :logger => logger)
3
+
4
+ case Padrino.env
5
+ when :development then MongoMapper.database = '!NAME!_development'
6
+ when :production then MongoMapper.database = '!NAME!_production'
7
+ when :test then MongoMapper.database = '!NAME!_test'
8
+ end
9
+ MONGO
10
+
11
+ def setup_orm
12
+ require_dependencies 'mongo_ext', :require => 'mongo'
13
+ require_dependencies 'mongo_mapper'
14
+ create_file("config/database.rb", MONGO.gsub(/!NAME!/, name.underscore))
15
+ empty_directory('app/models')
16
+ end
17
+
18
+ MM_MODEL = (<<-MODEL).gsub(/^ {10}/, '') unless defined?(MM_MODEL)
19
+ class !NAME!
20
+ include MongoMapper::Document
21
+
22
+ # key <name>, <type>
23
+ !FIELDS!
24
+ timestamps!
25
+ end
26
+ MODEL
27
+
28
+ def create_model_file(name, fields)
29
+ model_path = destination_root('app/models/', "#{name.to_s.underscore}.rb")
30
+ field_tuples = fields.collect { |value| value.split(":") }
31
+ column_declarations = field_tuples.collect { |field, kind| "key :#{field}, #{kind.camelize}" }.join("\n ")
32
+ model_contents = MM_MODEL.gsub(/!NAME!/, name.to_s.camelize)
33
+ model_contents.gsub!(/!FIELDS!/, column_declarations)
34
+ create_file(model_path, model_contents)
35
+ end
36
+
37
+ def create_model_migration(filename, name, fields)
38
+ # NO MIGRATION NEEDED
39
+ end
40
+
41
+ def create_migration_file(migration_name, name, columns)
42
+ # NO MIGRATION NEEDED
43
+ end
@@ -0,0 +1,71 @@
1
+ SEQUEL = (<<-SEQUEL).gsub(/^ {10}/, '') unless defined?(SEQUEL)
2
+ Sequel::Model.plugin(:schema)
3
+ DB = case Padrino.env
4
+ when :development then Sequel.connect("sqlite://" + Padrino.root('db', "development.db"), :loggers => [logger])
5
+ when :production then Sequel.connect("sqlite://" + Padrino.root('db', "production.db"), :loggers => [logger])
6
+ when :test then Sequel.connect("sqlite://" + Padrino.root('db', "test.db"), :loggers => [logger])
7
+ end
8
+ SEQUEL
9
+
10
+ def setup_orm
11
+ require_dependencies 'sequel', 'sqlite3-ruby'
12
+ create_file("config/database.rb", SEQUEL)
13
+ empty_directory('app/models')
14
+ empty_directory('db/migrate')
15
+ end
16
+
17
+ SQ_MODEL = (<<-MODEL).gsub(/^ {10}/, '') unless defined?(SQ_MODEL)
18
+ class !NAME! < Sequel::Model
19
+
20
+ end
21
+ MODEL
22
+
23
+ def create_model_file(name, fields)
24
+ model_path = destination_root('app/models/', "#{name.to_s.underscore}.rb")
25
+ model_contents = SQ_MODEL.gsub(/!NAME!/, name.to_s.downcase.camelize)
26
+ create_file(model_path, model_contents)
27
+ end
28
+
29
+ SQ_MIGRATION = (<<-MIGRATION).gsub(/^ {10}/, '') unless defined?(SQ_MIGRATION)
30
+ class !FILECLASS! < Sequel::Migration
31
+ def up
32
+ !UP!
33
+ end
34
+
35
+ def down
36
+ !DOWN!
37
+ end
38
+ end
39
+ MIGRATION
40
+
41
+ SQ_MODEL_UP_MG = (<<-MIGRATION).gsub(/^ {6}/, '') unless defined?(SQ_MODEL_UP_MG)
42
+ create_table :!TABLE! do
43
+ primary_key :id
44
+ # <type> <name>
45
+ !FIELDS!
46
+ end
47
+ MIGRATION
48
+
49
+ SQ_MODEL_DOWN_MG = (<<-MIGRATION).gsub(/^ {10}/, '') unless defined?(SQ_MODEL_DOWN_MG)
50
+ drop_table :!TABLE!
51
+ MIGRATION
52
+
53
+ def create_model_migration(migration_name, name, columns)
54
+ output_model_migration(migration_name, name, columns,
55
+ :column_format => Proc.new { |field, kind| "#{kind.camelize} :#{field}" },
56
+ :base => SQ_MIGRATION, :up => SQ_MODEL_UP_MG, :down => SQ_MODEL_DOWN_MG)
57
+ end
58
+
59
+ SQ_CHANGE_MG = (<<-MIGRATION).gsub(/^ {6}/, '') unless defined?(SQ_CHANGE_MG)
60
+ alter_table :!TABLE! do
61
+ !COLUMNS!
62
+ end
63
+ MIGRATION
64
+
65
+ def create_migration_file(migration_name, name, columns)
66
+ output_migration_file(migration_name, name, columns,
67
+ :base => SQ_MIGRATION, :change_format => SQ_CHANGE_MG,
68
+ :add => Proc.new { |field, kind| "add_column :#{field}, #{kind.camelize}" },
69
+ :remove => Proc.new { |field, kind| "drop_column :#{field}" }
70
+ )
71
+ end
@@ -0,0 +1,3 @@
1
+ def setup_renderer
2
+ # Nothing to do
3
+ end
@@ -0,0 +1,3 @@
1
+ def setup_renderer
2
+ require_dependencies 'haml'
3
+ end
@@ -0,0 +1,4 @@
1
+ def setup_script
2
+ copy_file('templates/scripts/ext-core.js', destination_root("/public/javascripts/ext-core.js"))
3
+ create_file(destination_root('/public/javascripts/application.js'), "// Put your application scripts here")
4
+ end
@@ -0,0 +1,4 @@
1
+ def setup_script
2
+ copy_file('templates/scripts/jquery.js', destination_root("/public/javascripts/jquery.js"))
3
+ create_file(destination_root('/public/javascripts/application.js'), "// Put your application scripts here")
4
+ end
@@ -0,0 +1,4 @@
1
+ def setup_script
2
+ copy_file('templates/scripts/mootools-core.js', destination_root("/public/javascripts/mootools-core.js"))
3
+ create_file(destination_root('/public/javascripts/application.js'), "// Put your application scripts here")
4
+ end
@@ -0,0 +1,5 @@
1
+ def setup_script
2
+ copy_file('templates/scripts/protopak.js', destination_root("/public/javascripts/protopak.js"))
3
+ copy_file('templates/scripts/lowpro.js', destination_root("/public/javascripts/lowpro.js"))
4
+ create_file(destination_root('/public/javascripts/application.js'), "// Put your application scripts here")
5
+ end
@@ -0,0 +1,4 @@
1
+ def setup_script
2
+ copy_file('templates/scripts/right.js', destination_root("/public/javascripts/right.js"))
3
+ create_file(destination_root('/public/javascripts/application.js'), "// Put your application scripts here")
4
+ end