padrino-gen 0.9.20 → 0.9.21

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -39,11 +39,11 @@ You can also instruct the generator to skip a certain component to avoid using o
39
39
  The available components and their default options are listed below:
40
40
 
41
41
  test:: rspec (default), bacon, shoulda, cucumber, testspec, riot
42
- renderer:: haml (default), erb, erubis, liquid
42
+ renderer:: haml (default), erb, erubis, liquid, slim
43
43
  stylesheet:: sass (default), less, compass
44
44
  mock:: none (default), mocha, rr
45
45
  script:: none (default), jquery, prototype, mootools, rightjs, extcore, dojo
46
- orm:: none (default), datamapper, mongomapper, mongoid, activerecord, sequel, couchrest
46
+ orm:: none (default), datamapper, mongomapper, mongoid, activerecord, sequel, couchrest, ohm, mongomatic
47
47
 
48
48
  In addition, you can generate projects based on existing templates:
49
49
 
@@ -207,6 +207,15 @@ module Padrino
207
207
  end
208
208
  end
209
209
 
210
+ # Ensure that project name is valid, else raise an NameError
211
+ def valid_constant?(name)
212
+ if name =~ /^\d/
213
+ raise ::NameError, "Project name #{name} cannot start with numbers"
214
+ elsif name =~ /^\W/
215
+ raise ::NameError, "Project name #{name} cannot start with non-word character"
216
+ end
217
+ end
218
+
210
219
  module ClassMethods
211
220
  # Defines a class option to allow a component to be chosen and add to component type list
212
221
  # Also builds the available_choices hash of which component choices are supported
@@ -240,4 +249,4 @@ module Padrino
240
249
  end
241
250
  end # Actions
242
251
  end # Generators
243
- end # Padrino
252
+ end # Padrino
@@ -28,7 +28,7 @@ MONGO
28
28
 
29
29
  def setup_orm
30
30
  require_dependencies 'bson_ext', :require => 'mongo'
31
- require_dependencies 'mongoid'
31
+ require_dependencies 'mongoid', '2.0.0.beta.20'
32
32
  create_file("config/database.rb", MONGOID.gsub(/!NAME!/, @app_name.underscore))
33
33
  empty_directory('app/models')
34
34
  end
@@ -66,4 +66,4 @@ end
66
66
 
67
67
  def create_migration_file(migration_name, name, columns)
68
68
  # NO MIGRATION NEEDED
69
- end
69
+ end
@@ -10,7 +10,7 @@ MONGO
10
10
 
11
11
  def setup_orm
12
12
  require_dependencies 'bson_ext', :require => 'mongo'
13
- require_dependencies 'mongo_mapper'
13
+ require_dependencies 'mongo_mapper', :git => "git://github.com/jnunemaker/mongomapper.git", :branch => "rails3"
14
14
  create_file("config/database.rb", MONGO.gsub(/!NAME!/, @app_name.underscore))
15
15
  empty_directory('app/models')
16
16
  end
@@ -27,7 +27,7 @@ class Riot::Context
27
27
  # asserts(:status).equals(200)
28
28
  # end
29
29
  def app(app=nil, &block)
30
- setup { @app = (app || block) }
30
+ setup { @app = (app || block.call) }
31
31
  end
32
32
  end
33
33
 
@@ -86,4 +86,4 @@ end
86
86
  def generate_model_test(name)
87
87
  riot_contents = RIOT_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize)
88
88
  create_file destination_root("test/models/#{name.to_s.underscore}_test.rb"), riot_contents, :skip => true
89
- end
89
+ end
@@ -34,7 +34,7 @@ module Padrino
34
34
  component_option :test, "testing framework", :aliases => '-t', :choices => [:rspec, :shoulda, :cucumber, :bacon, :testspec, :riot], :default => :none
35
35
  component_option :mock, "mocking library", :aliases => '-m', :choices => [:mocha, :rr], :default => :none
36
36
  component_option :script, "javascript library", :aliases => '-s', :choices => [:jquery, :prototype, :rightjs, :mootools, :extcore, :dojo], :default => :none
37
- component_option :renderer, "template engine", :aliases => '-e', :choices => [:haml, :erb, :erubis, :liquid, :slim], :default => :haml
37
+ component_option :renderer, "template engine", :aliases => '-e', :choices => [:haml, :erb, :liquid, :slim], :default => :haml
38
38
  component_option :stylesheet, "stylesheet engine", :aliases => '-c', :choices => [:less, :sass, :compass, :scss], :default => :none
39
39
 
40
40
  # Show help if no argv given
@@ -42,12 +42,17 @@ module Padrino
42
42
 
43
43
  # Copies over the Padrino base application App
44
44
  def setup_project
45
+ valid_constant?(options[:app] || name)
45
46
  @app_name = (options[:app] || name).gsub(/\W/, "_").underscore.camelize
46
47
  self.destination_root = File.join(options[:root], name)
47
48
  if options[:template] # Run the template to create project
48
49
  execute_runner(:template, options[:template])
49
50
  else # generate project without template
50
51
  directory("project/", destination_root)
52
+ empty_directory destination_root "public/images"
53
+ empty_directory destination_root "public/javascripts"
54
+ empty_directory destination_root "public/stylesheets"
55
+ empty_directory destination_root "tmp"
51
56
  app_skeleton('app', options[:tiny])
52
57
  store_component_config('.components')
53
58
  template "templates/Gemfile.tt", destination_root("Gemfile")
@@ -98,6 +103,7 @@ module Padrino
98
103
  end
99
104
  say(text)
100
105
  end
106
+
101
107
  end # Project
102
108
  end # Generators
103
- end # Padrino
109
+ end # Padrino
@@ -1,17 +1,12 @@
1
1
  # Defines our constants
2
2
  PADRINO_ENV = ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= "development" unless defined?(PADRINO_ENV)
3
3
  PADRINO_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) unless defined?(PADRINO_ROOT)
4
-
5
- begin
6
- # Require the preresolved locked set of gems.
7
- require File.expand_path('../../.bundle/environment', __FILE__)
8
- rescue LoadError
9
- # Fallback on doing the resolve at runtime.
10
- require 'rubygems'
11
- require 'bundler'
12
- Bundler.setup
13
- end
14
-
4
+ # Load Bundler
5
+ require 'rubygems'
6
+ require 'bundler'
7
+ # Only have default and environemtn gems
8
+ Bundler.setup(:default, PADRINO_ENV.to_sym)
9
+ # Only require default and environment gems
15
10
  Bundler.require(:default, PADRINO_ENV.to_sym)
16
11
  puts "=> Located #{Padrino.bundle} Gemfile for #{Padrino.env}"
17
12
 
@@ -27,4 +22,4 @@ end
27
22
  Padrino.after_load do
28
23
  end
29
24
 
30
- Padrino.load!
25
+ Padrino.load!
@@ -342,7 +342,7 @@ if defined?(ActiveRecord)
342
342
  locale = "#{lang}:" + "\n" +
343
343
  " models:" + "\n" +
344
344
  " #{m}:" + "\n" +
345
- " name: #{klass.human}" + "\n" +
345
+ " name: #{klass.human_name}" + "\n" +
346
346
  " attributes:" + "\n" +
347
347
  columns.collect { |c| " #{c}: #{klass.human_attribute_name(c)}" }.join("\n")
348
348
  print "created a new for #{lang.to_s.upcase} Lang ... "; $stdout.flush
@@ -0,0 +1,115 @@
1
+ if defined?(Mongoid)
2
+ namespace :mi do
3
+
4
+ desc 'Drops all the collections for the database for the current Padrino.env'
5
+ task :drop => :environment do
6
+ Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
7
+ end
8
+
9
+ # Helper to retrieve a list of models.
10
+ def get_mongoid_models
11
+ documents = []
12
+ Dir.glob('app/models/*.rb').sort.each do |file|
13
+ model_path = file[0..-4].split('/')[2..-1]
14
+
15
+ begin
16
+ klass = model_path.map(&:classify).join('::').constantize
17
+ if klass.ancestors.include?(Mongoid::Document) && !klass.embedded
18
+ documents << klass
19
+ end
20
+ rescue => e
21
+ # Just for non-mongoid objects that dont have the embedded
22
+ # attribute at the class level.
23
+ end
24
+ end
25
+
26
+ documents
27
+ end
28
+
29
+ desc 'Create the indexes defined on your mongoid models'
30
+ task :create_indexes => :environment do
31
+ get_mongoid_models.each { |model| model.create_indexes }
32
+ end
33
+
34
+ def convert_ids(obj)
35
+ if obj.is_a?(String) && obj =~ /^[a-f0-9]{24}$/
36
+ BSON::ObjectId(obj)
37
+ elsif obj.is_a?(Array)
38
+ obj.map do |v|
39
+ convert_ids(v)
40
+ end
41
+ elsif obj.is_a?(Hash)
42
+ obj.each do |k, v|
43
+ obj[k] = convert_ids(v)
44
+ end
45
+ else
46
+ obj
47
+ end
48
+ end
49
+
50
+ def collection_names
51
+ @collection_names ||= get_mongoid_models.map{ |d| d.collection.name }.uniq
52
+ end
53
+
54
+ desc "Convert string objectids in mongo database to ObjectID type"
55
+ task :objectid_convert => :environment do
56
+ collection_names.each do |collection_name|
57
+ puts "Converting #{collection_name} to use ObjectIDs"
58
+
59
+ # get old collection
60
+ collection = Mongoid.master.collection(collection_name)
61
+
62
+ # get new collection (a clean one)
63
+ collection.db["#{collection_name}_new"].drop
64
+ new_collection = collection.db["#{collection_name}_new"]
65
+
66
+ # convert collection documents
67
+ collection.find({}, :timeout => false, :sort => "_id") do |cursor|
68
+ cursor.each do |doc|
69
+ new_doc = convert_ids(doc)
70
+ new_collection.insert(new_doc, :safe => true)
71
+ end
72
+ end
73
+
74
+ puts "Done! Converted collection is in #{new_collection.name}\n\n"
75
+ end
76
+
77
+ # no errors. great! now rename _new to collection_name
78
+ collection_names.each do |collection_name|
79
+ collection = Mongoid.master.collection(collection_name)
80
+ new_collection = collection.db["#{collection_name}_new"]
81
+
82
+ # swap collection to _old
83
+ puts "Moving #{collection.name} to #{collection_name}_old"
84
+ collection.db["#{collection_name}_old"].drop
85
+
86
+ begin
87
+ collection.rename("#{collection_name}_old")
88
+ rescue Exception => e
89
+ puts "Unable to rename database #{collection_name} to #{collection_name}_old"
90
+ puts "reason: #{e.message}\n\n"
91
+ end
92
+
93
+ # swap _new to collection
94
+ puts "Moving #{new_collection.name} to #{collection_name}\n\n"
95
+
96
+ begin
97
+ new_collection.rename(collection_name)
98
+ rescue Exception => e
99
+ puts "Unable to rename database #{new_collection.name} to #{collection_name}"
100
+ puts "reason: #{e.message}\n\n"
101
+ end
102
+ end
103
+
104
+ puts "DONE! Run `padrino rake mi:cleanup_old_collections` to remove old collections"
105
+ end
106
+
107
+ desc "Clean up old collections backed up by objectid_convert"
108
+ task :cleanup_old_collections => :environment do
109
+ collection_names.each do |collection_name|
110
+ collection = Mongoid.master.collection(collection_name)
111
+ collection.db["#{collection.name}_old"].drop
112
+ end
113
+ end
114
+ end
115
+ end
@@ -19,6 +19,9 @@ class TestProjectGenerator < Test::Unit::TestCase
19
19
  assert_match_in_file(/Padrino.mount\("SampleProject"\).to\('\/'\)/,"#{@apptmp}/sample_project/config/apps.rb")
20
20
  assert_file_exists("#{@apptmp}/sample_project/config/boot.rb")
21
21
  assert_file_exists("#{@apptmp}/sample_project/public/favicon.ico")
22
+ assert_dir_exists("#{@apptmp}/sample_project/public/images")
23
+ assert_dir_exists("#{@apptmp}/sample_project/public/javascripts")
24
+ assert_dir_exists("#{@apptmp}/sample_project/public/stylesheets")
22
25
  assert_dir_exists("#{@apptmp}/sample_project/app/views")
23
26
  assert_dir_exists("#{@apptmp}/sample_project/app/views/layouts")
24
27
  end
@@ -30,6 +33,11 @@ class TestProjectGenerator < Test::Unit::TestCase
30
33
  assert_match_in_file(/Padrino.mount\("ProjectCom"\).to\('\/'\)/,"#{@apptmp}/project.com/config/apps.rb")
31
34
  end
32
35
 
36
+ should "raise an Error when given invalid constant names" do
37
+ assert_raise(::NameError) { silence_logger { generate(:project, "123asdf", "--root=#{@apptmp}") } }
38
+ assert_raise(::NameError) { silence_logger { generate(:project, "./sample_project", "--root=#{@apptmp}") } }
39
+ end
40
+
33
41
  should "display the right path" do
34
42
  buffer = silence_logger { generate(:project, 'project', "--root=/tmp") }
35
43
  assert_file_exists("/tmp/project")
@@ -53,6 +61,9 @@ class TestProjectGenerator < Test::Unit::TestCase
53
61
  assert_file_exists("#{@apptmp}/sample_project/app/controllers.rb")
54
62
  assert_file_exists("#{@apptmp}/sample_project/app/helpers.rb")
55
63
  assert_file_exists("#{@apptmp}/sample_project/app/mailers.rb")
64
+ assert_dir_exists("#{@apptmp}/sample_project/public/images")
65
+ assert_dir_exists("#{@apptmp}/sample_project/public/javascripts")
66
+ assert_dir_exists("#{@apptmp}/sample_project/public/stylesheets")
56
67
  assert_dir_exists("#{@apptmp}/sample_project/app/views/mailers")
57
68
  assert_dir_exists("#{@apptmp}/sample_project/app/views/layouts")
58
69
  assert_match_in_file(/:notifier/,"#{@apptmp}/sample_project/app/mailers.rb")
@@ -319,12 +330,6 @@ class TestProjectGenerator < Test::Unit::TestCase
319
330
  assert_match_in_file(/gem 'haml'/, "#{@apptmp}/sample_project/Gemfile")
320
331
  end
321
332
 
322
- should "properly generate for erubis" do
323
- buffer = silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--renderer=erubis','--script=none') }
324
- assert_match(/Applying.*?erubis.*?renderer/,buffer)
325
- assert_match_in_file(/gem 'erubis'/, "#{@apptmp}/sample_project/Gemfile")
326
- end
327
-
328
333
  should "properly generate for liquid" do
329
334
  buffer = silence_logger { generate(:project, 'sample_project', "--root=#{@apptmp}", '--renderer=liquid','--script=none') }
330
335
  assert_match(/Applying.*?liquid.*?renderer/,buffer)
@@ -507,4 +512,4 @@ class TestProjectGenerator < Test::Unit::TestCase
507
512
  end
508
513
 
509
514
  end
510
- end
515
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-gen
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
4
+ hash: 17
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 20
10
- version: 0.9.20
9
+ - 21
10
+ version: 0.9.21
11
11
  platform: ruby
12
12
  authors:
13
13
  - Padrino Team
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2011-01-19 00:00:00 -08:00
21
+ date: 2011-02-28 00:00:00 -08:00
22
22
  default_executable: padrino-gen
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -29,12 +29,12 @@ dependencies:
29
29
  requirements:
30
30
  - - "="
31
31
  - !ruby/object:Gem::Version
32
- hash: 19
32
+ hash: 17
33
33
  segments:
34
34
  - 0
35
35
  - 9
36
- - 20
37
- version: 0.9.20
36
+ - 21
37
+ version: 0.9.21
38
38
  type: :runtime
39
39
  version_requirements: *id001
40
40
  - !ruby/object:Gem::Dependency
@@ -100,7 +100,6 @@ files:
100
100
  - lib/padrino-gen/generators/components/orms/ohm.rb
101
101
  - lib/padrino-gen/generators/components/orms/sequel.rb
102
102
  - lib/padrino-gen/generators/components/renderers/erb.rb
103
- - lib/padrino-gen/generators/components/renderers/erubis.rb
104
103
  - lib/padrino-gen/generators/components/renderers/haml.rb
105
104
  - lib/padrino-gen/generators/components/renderers/liquid.rb
106
105
  - lib/padrino-gen/generators/components/renderers/slim.rb
@@ -131,7 +130,6 @@ files:
131
130
  - lib/padrino-gen/generators/project/config/boot.rb
132
131
  - lib/padrino-gen/generators/project/config.ru
133
132
  - lib/padrino-gen/generators/project/public/favicon.ico
134
- - lib/padrino-gen/generators/project/public/index.html
135
133
  - lib/padrino-gen/generators/project.rb
136
134
  - lib/padrino-gen/generators/runner.rb
137
135
  - lib/padrino-gen/generators/templates/controller.rb.tt
@@ -148,6 +146,7 @@ files:
148
146
  - lib/padrino-gen/generators/templates/scripts/right.js
149
147
  - lib/padrino-gen/padrino-tasks/activerecord.rb
150
148
  - lib/padrino-gen/padrino-tasks/datamapper.rb
149
+ - lib/padrino-gen/padrino-tasks/mongoid.rb
151
150
  - lib/padrino-gen/padrino-tasks/mongomapper.rb
152
151
  - lib/padrino-gen/padrino-tasks/seed.rb
153
152
  - lib/padrino-gen/padrino-tasks/sequel.rb
@@ -199,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
198
  requirements: []
200
199
 
201
200
  rubyforge_project: padrino-gen
202
- rubygems_version: 1.3.7
201
+ rubygems_version: 1.5.2
203
202
  signing_key:
204
203
  specification_version: 3
205
204
  summary: Generators for easily creating and building padrino applications
@@ -1,3 +0,0 @@
1
- def setup_renderer
2
- require_dependencies 'erubis'
3
- end
@@ -1,48 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
- <head>
6
- <title>
7
- Welcome to Padrino
8
- </title>
9
- <style type="text/css">
10
- body{
11
- font-family:Helvetica,Arial,sans-serif;
12
- line-height:150%;
13
- }
14
- ul,li{
15
- list-style-type:none;
16
- margin:0px;
17
- padding:5px 0px 5px 0px;
18
- margin-left:5px;
19
- }
20
- a{
21
- color:#333;
22
- }
23
- </style>
24
- </head>
25
- <body>
26
- <h1>
27
- Welcome to Padrino.rb
28
- </h1>
29
- <p>
30
- Thanks for choosing Padrino for your Development.<br />
31
- To get you started you we collected some Tutorials and Links:<br />
32
- </p>
33
- <ul>
34
- <li>
35
- <a href="http://www.padrinorb.com/guides/blog-tutorial">Blog Tutorial</a>
36
- </li>
37
- <li>
38
- <a href="http://www.padrinorb.com/guides/generators">Generators</a>
39
- </li>
40
- <li>
41
- <a href="http://www.padrinorb.com/guides/development-commands">Development Commands</a>
42
- </li>
43
- </ul>
44
- <p>
45
- To define a new default site for your project please delete this <em>index.html</em> file from the <em>public</em> directory.
46
- </p>
47
- </body>
48
- </html>