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.
Files changed (63) hide show
  1. data/README.rdoc +2 -2
  2. data/Rakefile +4 -53
  3. data/bin/padrino-gen +2 -4
  4. data/lib/padrino-gen/command.rb +12 -0
  5. data/lib/padrino-gen/generators/actions.rb +25 -5
  6. data/lib/padrino-gen/generators/app/app.rb.tt +17 -19
  7. data/lib/padrino-gen/generators/app.rb +7 -6
  8. data/lib/padrino-gen/generators/cli.rb +3 -2
  9. data/lib/padrino-gen/generators/components/actions.rb +4 -4
  10. data/lib/padrino-gen/generators/components/mocks/rr.rb +1 -1
  11. data/lib/padrino-gen/generators/components/orms/activerecord.rb +58 -16
  12. data/lib/padrino-gen/generators/components/orms/couchrest.rb +6 -5
  13. data/lib/padrino-gen/generators/components/orms/datamapper.rb +41 -17
  14. data/lib/padrino-gen/generators/components/orms/mongoid.rb +7 -6
  15. data/lib/padrino-gen/generators/components/orms/mongomapper.rb +6 -5
  16. data/lib/padrino-gen/generators/components/orms/sequel.rb +34 -15
  17. data/lib/padrino-gen/generators/components/scripts/dojo.rb +4 -0
  18. data/lib/padrino-gen/generators/components/stylesheets/compass/application.scss +43 -0
  19. data/lib/padrino-gen/generators/components/stylesheets/compass/partials/_base.scss +10 -0
  20. data/lib/padrino-gen/generators/components/stylesheets/compass.rb +39 -0
  21. data/lib/padrino-gen/generators/components/stylesheets/less.rb +2 -2
  22. data/lib/padrino-gen/generators/components/stylesheets/sass.rb +2 -2
  23. data/lib/padrino-gen/generators/components/tests/bacon.rb +2 -1
  24. data/lib/padrino-gen/generators/components/tests/cucumber.rb +26 -4
  25. data/lib/padrino-gen/generators/components/tests/riot.rb +45 -9
  26. data/lib/padrino-gen/generators/components/tests/rspec.rb +2 -1
  27. data/lib/padrino-gen/generators/components/tests/shoulda.rb +2 -1
  28. data/lib/padrino-gen/generators/components/tests/testspec.rb +2 -1
  29. data/lib/padrino-gen/generators/controller.rb +2 -2
  30. data/lib/padrino-gen/generators/mailer.rb +6 -8
  31. data/lib/padrino-gen/generators/model.rb +9 -1
  32. data/lib/padrino-gen/generators/project/config/apps.rb.tt +24 -26
  33. data/lib/padrino-gen/generators/project/config/boot.rb +2 -2
  34. data/lib/padrino-gen/generators/project.rb +23 -16
  35. data/lib/padrino-gen/generators/templates/Gemfile.tt +1 -1
  36. data/lib/padrino-gen/generators/templates/controller.rb.tt +2 -2
  37. data/lib/padrino-gen/generators/templates/mailer.rb.tt +36 -17
  38. data/lib/padrino-gen/generators/templates/scripts/dojo.js +16 -0
  39. data/lib/padrino-gen/generators/templates/scripts/mootools-core.js +120 -1
  40. data/lib/padrino-gen/generators/templates/scripts/right.js +1 -12
  41. data/lib/padrino-gen/padrino-tasks/activerecord.rb +40 -34
  42. data/lib/padrino-gen/padrino-tasks/datamapper.rb +39 -24
  43. data/lib/padrino-gen/padrino-tasks/mongomapper.rb +1 -1
  44. data/lib/padrino-gen.rb +2 -1
  45. data/padrino-gen.gemspec +17 -132
  46. data/test/helper.rb +3 -11
  47. data/test/test_app_generator.rb +19 -7
  48. data/test/test_controller_generator.rb +11 -1
  49. data/test/test_mailer_generator.rb +18 -15
  50. data/test/test_migration_generator.rb +4 -4
  51. data/test/test_model_generator.rb +30 -9
  52. data/test/test_project_generator.rb +163 -33
  53. metadata +70 -48
  54. data/lib/padrino-gen/generators/app/controllers/.empty_directory +0 -0
  55. data/lib/padrino-gen/generators/app/helpers/.empty_directory +0 -0
  56. data/lib/padrino-gen/generators/app/views/.empty_directory +0 -0
  57. data/lib/padrino-gen/generators/app/views/layouts/.emptydirectory +0 -0
  58. data/lib/padrino-gen/generators/project/.gitignore +0 -7
  59. data/lib/padrino-gen/generators/project/public/images/.empty_directory +0 -0
  60. data/lib/padrino-gen/generators/project/public/javascripts/.empty_directory +0 -0
  61. data/lib/padrino-gen/generators/project/public/stylesheets/.empty_directory +0 -0
  62. data/lib/padrino-gen/generators/project/tmp/.empty_directory +0 -0
  63. data/lib/padrino-gen/generators/templates/mailer_initializer.rb.tt +0 -19
@@ -1,32 +1,52 @@
1
- SEQUEL = (<<-SEQUEL).gsub(/^ {10}/, '') unless defined?(SEQUEL)
1
+ SEQUEL = (<<-SEQUEL) unless defined?(SEQUEL)
2
2
  Sequel::Model.plugin(:schema)
3
+ Sequel::Model.raise_on_save_failure = false # Do not throw exceptions on failure
3
4
  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])
5
+ when :development then Sequel.connect(!DB_DEVELOPMENT!, :loggers => [logger])
6
+ when :production then Sequel.connect(!DB_PRODUCTION!, :loggers => [logger])
7
+ when :test then Sequel.connect(!DB_TEST!, :loggers => [logger])
7
8
  end
8
9
  SEQUEL
9
10
 
10
11
  def setup_orm
11
- require_dependencies 'sequel', 'sqlite3-ruby'
12
- create_file("config/database.rb", SEQUEL)
12
+ sequel = SEQUEL
13
+ require_dependencies 'sequel'
14
+ require_dependencies case options[:adapter]
15
+ when 'mysql'
16
+ sequel.gsub!(/!DB_DEVELOPMENT!/, "\"mysql://localhost/#{name}_development\"")
17
+ sequel.gsub!(/!DB_PRODUCTION!/, "\"mysql://localhost/#{name}_production\"")
18
+ sequel.gsub!(/!DB_TEST!/,"\"mysql://localhost/#{name}_test\"")
19
+ 'mysql'
20
+ when 'postgres'
21
+ sequel.gsub!(/!DB_DEVELOPMENT!/, "\"postgres://localhost/#{name}_development\"")
22
+ sequel.gsub!(/!DB_PRODUCTION!/, "\"postgres://localhost/#{name}_production\"")
23
+ sequel.gsub!(/!DB_TEST!/,"\"postgres://localhost/#{name}_test\"")
24
+ 'pg'
25
+ else
26
+ sequel.gsub!(/!DB_DEVELOPMENT!/,"\"sqlite://\" + Padrino.root('db', \"#{name}_development.db\")")
27
+ sequel.gsub!(/!DB_PRODUCTION!/,"\"sqlite://\" + Padrino.root('db', \"#{name}_production.db\")")
28
+ sequel.gsub!(/!DB_TEST!/,"\"sqlite://\" + Padrino.root('db', \"#{name}_test.db\")")
29
+ 'sqlite3-ruby'
30
+ end
31
+ create_file("config/database.rb", sequel)
13
32
  empty_directory('app/models')
14
33
  empty_directory('db/migrate')
15
34
  end
16
35
 
17
- SQ_MODEL = (<<-MODEL).gsub(/^ {10}/, '') unless defined?(SQ_MODEL)
36
+ SQ_MODEL = (<<-MODEL) unless defined?(SQ_MODEL)
18
37
  class !NAME! < Sequel::Model
19
38
 
20
39
  end
21
40
  MODEL
22
41
 
23
- def create_model_file(name, fields)
24
- model_path = destination_root('app/models/', "#{name.to_s.underscore}.rb")
42
+ # options => { :fields => ["title:string", "body:string"], :app => 'app' }
43
+ def create_model_file(name, options={})
44
+ model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
25
45
  model_contents = SQ_MODEL.gsub(/!NAME!/, name.to_s.downcase.camelize)
26
46
  create_file(model_path, model_contents)
27
47
  end
28
48
 
29
- SQ_MIGRATION = (<<-MIGRATION).gsub(/^ {10}/, '') unless defined?(SQ_MIGRATION)
49
+ SQ_MIGRATION = (<<-MIGRATION) unless defined?(SQ_MIGRATION)
30
50
  class !FILECLASS! < Sequel::Migration
31
51
  def up
32
52
  !UP!
@@ -38,15 +58,14 @@ class !FILECLASS! < Sequel::Migration
38
58
  end
39
59
  MIGRATION
40
60
 
41
- SQ_MODEL_UP_MG = (<<-MIGRATION).gsub(/^ {6}/, '') unless defined?(SQ_MODEL_UP_MG)
61
+ SQ_MODEL_UP_MG = (<<-MIGRATION).gsub(/^/, ' ') unless defined?(SQ_MODEL_UP_MG)
42
62
  create_table :!TABLE! do
43
63
  primary_key :id
44
- # <type> <name>
45
64
  !FIELDS!
46
65
  end
47
66
  MIGRATION
48
67
 
49
- SQ_MODEL_DOWN_MG = (<<-MIGRATION).gsub(/^ {10}/, '') unless defined?(SQ_MODEL_DOWN_MG)
68
+ SQ_MODEL_DOWN_MG = (<<-MIGRATION) unless defined?(SQ_MODEL_DOWN_MG)
50
69
  drop_table :!TABLE!
51
70
  MIGRATION
52
71
 
@@ -56,7 +75,7 @@ def create_model_migration(migration_name, name, columns)
56
75
  :base => SQ_MIGRATION, :up => SQ_MODEL_UP_MG, :down => SQ_MODEL_DOWN_MG)
57
76
  end
58
77
 
59
- SQ_CHANGE_MG = (<<-MIGRATION).gsub(/^ {6}/, '') unless defined?(SQ_CHANGE_MG)
78
+ SQ_CHANGE_MG = (<<-MIGRATION).gsub(/^/, ' ') unless defined?(SQ_CHANGE_MG)
60
79
  alter_table :!TABLE! do
61
80
  !COLUMNS!
62
81
  end
@@ -68,4 +87,4 @@ def create_migration_file(migration_name, name, columns)
68
87
  :add => Proc.new { |field, kind| "add_column :#{field}, #{kind.camelize}" },
69
88
  :remove => Proc.new { |field, kind| "drop_column :#{field}" }
70
89
  )
71
- end
90
+ end
@@ -0,0 +1,4 @@
1
+ def setup_script
2
+ copy_file('templates/scripts/dojo.js', destination_root("/public/javascripts/dojo.js"))
3
+ create_file(destination_root('/public/javascripts/application.js'), "// Put your application scripts here")
4
+ end
@@ -0,0 +1,43 @@
1
+ // This import applies a global reset to any page that imports this stylesheet.
2
+ @import "blueprint/reset";
3
+
4
+ // To configure blueprint, edit the partials/base.sass file.
5
+ @import "partials/base";
6
+
7
+ // Import all the default blueprint modules so that we can access their mixins.
8
+ @import "blueprint";
9
+
10
+ // Import the non-default scaffolding module.
11
+ @import "blueprint/scaffolding";
12
+
13
+ // To generate css equivalent to the blueprint css but with your
14
+ // configuration applied, uncomment:
15
+ // @include blueprint
16
+
17
+ // But Compass recommends that you scope your blueprint styles
18
+ // So that you can better control what pages use blueprint
19
+ // when stylesheets are concatenated together.
20
+ @include blueprint-scaffolding("body.bp");
21
+
22
+ body.bp {
23
+ @include blueprint-typography(true);
24
+ @include blueprint-utilities;
25
+ @include blueprint-debug;
26
+ @include blueprint-interaction;
27
+ // Remove the scaffolding when you're ready to start doing visual design.
28
+ // Or leave it in if you're happy with how blueprint looks out-of-the-box
29
+ }
30
+
31
+ form.bp {
32
+ @include blueprint-form;
33
+ }
34
+
35
+ .two-col {
36
+ @include container;
37
+ background-color: #cccccc;
38
+ #header, #footer {
39
+ @include column(24); }
40
+ #sidebar {
41
+ @include column(3); }
42
+ #content {
43
+ @include column(21, true); } }
@@ -0,0 +1,10 @@
1
+ // Here is where you can define your constants for your application and to configure the blueprint framework.
2
+ // Feel free to delete these if you want keep the defaults:
3
+
4
+ $blueprint-grid-columns: 24;
5
+ $blueprint-container-size: 950px;
6
+ $blueprint-grid-margin: 10px;
7
+
8
+ // Use this to calculate the width based on the total width.
9
+ // Or you can set !blueprint_grid_width to a fixed value and unset !blueprint_container_size -- it will be calculated for you.
10
+ $blueprint-grid-width: ($blueprint-container-size + $blueprint-grid-margin) / $blueprint-grid-columns - $blueprint-grid-margin;
@@ -0,0 +1,39 @@
1
+ COMPASS_INIT = (<<-COMPASS).gsub(/^ {10}/, '') unless defined?(COMPASS_INIT)
2
+ # Enables support for Compass, a stylesheet authoring framework based on SASS.
3
+ # See http://compass-style.org/ for more details.
4
+ # Store Compass/SASS files (by default) within 'app/stylesheets'
5
+
6
+ module CompassInitializer
7
+ def self.registered(app)
8
+ require 'sass/plugin/rack'
9
+
10
+ Compass.configuration do |config|
11
+ config.project_path = Padrino.root
12
+ config.sass_dir = "app/stylesheets"
13
+ config.project_type = :stand_alone
14
+ config.http_path = "/"
15
+ config.css_dir = "public/stylesheets"
16
+ config.images_dir = "public/images"
17
+ config.javascripts_dir = "public/javascripts"
18
+ config.output_style = :compressed
19
+ end
20
+
21
+ Compass.configure_sass_plugin!
22
+ Compass.handle_configuration_change!
23
+
24
+ app.use Sass::Plugin::Rack
25
+ end
26
+ end
27
+ COMPASS
28
+
29
+ COMPASS_REGISTER = (<<-COMPASSR).gsub(/^ {10}/, '') unless defined?(COMPASS_REGISTER)
30
+ register CompassInitializer\n
31
+ COMPASSR
32
+
33
+ def setup_stylesheet
34
+ require_dependencies 'compass'
35
+ create_file destination_root('/lib/compass_plugin.rb'), COMPASS_INIT
36
+ inject_into_file destination_root('/app/app.rb'), COMPASS_REGISTER, :after => "register Padrino::Helpers\n"
37
+
38
+ directory "components/stylesheets/compass/", destination_root('/app/stylesheets')
39
+ end
@@ -22,12 +22,12 @@ end
22
22
  LESS
23
23
 
24
24
  LESS_REGISTER = (<<-LESSR).gsub(/^ {10}/, '') unless defined?(LESS_REGISTER)
25
- register LessInitializer\n
25
+ register LessInitializer\n
26
26
  LESSR
27
27
 
28
28
  def setup_stylesheet
29
29
  require_dependencies 'less', 'rack-less'
30
30
  create_file destination_root('/lib/less_plugin.rb'), LESS_INIT
31
- inject_into_file destination_root('/app/app.rb'), LESS_REGISTER, :after => "configure do\n"
31
+ inject_into_file destination_root('/app/app.rb'), LESS_REGISTER, :after => "register Padrino::Helpers\n"
32
32
  empty_directory destination_root('/app/stylesheets')
33
33
  end
@@ -14,12 +14,12 @@ end
14
14
  SASS
15
15
 
16
16
  SASS_REGISTER = (<<-SASSR).gsub(/^ {10}/, '') unless defined?(SASS_REGISTER)
17
- register SassInitializer\n
17
+ register SassInitializer\n
18
18
  SASSR
19
19
 
20
20
  def setup_stylesheet
21
21
  require_dependencies 'haml'
22
22
  create_file destination_root('/lib/sass_plugin.rb'), SASS_INIT
23
- inject_into_file destination_root('/app/app.rb'), SASS_REGISTER, :after => "configure do\n"
23
+ inject_into_file destination_root('/app/app.rb'), SASS_REGISTER, :after => "register Padrino::Helpers\n"
24
24
  empty_directory destination_root('/app/stylesheets')
25
25
  end
@@ -29,7 +29,7 @@ BACON_RAKE = (<<-TEST).gsub(/^ {10}/, '') unless defined?(BACON_RAKE)
29
29
  require 'rake/testtask'
30
30
 
31
31
  Rake::TestTask.new(:test) do |test|
32
- test.pattern = '**/*_test.rb'
32
+ test.pattern = 'test/**/*_test.rb'
33
33
  test.verbose = true
34
34
  end
35
35
  TEST
@@ -47,6 +47,7 @@ TEST
47
47
 
48
48
  # Setup the testing configuration helper and dependencies
49
49
  def setup_test
50
+ require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
50
51
  require_dependencies 'bacon', :group => 'test'
51
52
  insert_test_suite_setup BACON_SETUP, :path => 'test/test_config.rb'
52
53
  create_file destination_root("test/test.rake"), BACON_RAKE
@@ -1,6 +1,6 @@
1
1
  apply_component_for(:rspec, :test)
2
2
 
3
- CUCUMBER_SETUP = (<<-TEST).gsub(/^ {10}/, '') unless defined?(CUCUMBER_SETUP)
3
+ CUCUMBER_SETUP = (<<-TEST) unless defined?(CUCUMBER_SETUP)
4
4
  PADRINO_ENV = 'test' unless defined?(PADRINO_ENV)
5
5
  require File.expand_path(File.dirname(__FILE__) + "/../../config/boot")
6
6
 
@@ -13,12 +13,12 @@ require 'spec/expectations'
13
13
  Capybara.app = CLASS_NAME.tap { |app| }
14
14
  TEST
15
15
 
16
- CUCUMBER_YML = (<<-TEST).gsub(/^ {10}/, '') unless defined?(CUCUMBER_YML)
16
+ CUCUMBER_YML = (<<-TEST) unless defined?(CUCUMBER_YML)
17
17
  default: --tags ~@wip --strict features
18
18
  html_report: --tags ~@wip --strict --format html --out=features_report.html features
19
19
  TEST
20
20
 
21
- CUCUMBER_FEATURE = (<<-TEST).gsub(/^ {10}/, '') unless defined?(CUCUMBER_FEATURE)
21
+ CUCUMBER_FEATURE = (<<-TEST) unless defined?(CUCUMBER_FEATURE)
22
22
  Feature: Addition
23
23
  In order to avoid silly mistakes
24
24
  As a math idiot
@@ -32,7 +32,7 @@ Feature: Addition
32
32
  Then I should see 'Answer: 120'
33
33
  TEST
34
34
 
35
- CUCUMBER_STEP = (<<-TEST).gsub(/^ {10}/, '') unless defined?(CUCUMBER_STEP)
35
+ CUCUMBER_STEP = (<<-TEST) unless defined?(CUCUMBER_STEP)
36
36
  Given /^I visit the calculator page$/ do
37
37
  visit '/add'
38
38
  end
@@ -50,10 +50,32 @@ Then /^I should see '(.*)'$/ do |text|
50
50
  end
51
51
  TEST
52
52
 
53
+ CUCUMBER_URL = (<<-TEST) unless defined?(CUCUMBER_URL)
54
+ module Cucumber
55
+ module Web
56
+ module URLs
57
+ def url_for(*names)
58
+ Capybara.app.url_for(*names)
59
+ end
60
+ alias_method :url, :url_for
61
+
62
+ def absolute_url_for(*names)
63
+ "http://www.example.com" + Capybara.app.url_for(*names)
64
+ end
65
+ alias_method :absolute_url, :absolute_url_for
66
+ end
67
+ end
68
+ end
69
+
70
+ World(Cucumber::Web::URLs)
71
+ TEST
72
+
53
73
  def setup_test
74
+ require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
54
75
  require_dependencies 'cucumber', :group => 'test'
55
76
  require_dependencies 'capybara', :group => 'test'
56
77
  insert_test_suite_setup CUCUMBER_SETUP, :path => "features/support/env.rb"
78
+ create_file destination_root("features/support/url.rb"), CUCUMBER_URL
57
79
  create_file destination_root("features/add.feature"), CUCUMBER_FEATURE
58
80
  create_file destination_root("features/step_definitions/add_steps.rb"), CUCUMBER_STEP
59
81
  create_file destination_root("cucumber.yml"), CUCUMBER_YML
@@ -2,16 +2,51 @@ RIOT_SETUP = (<<-TEST).gsub(/^ {10}/, '') unless defined?(RIOT_SETUP)
2
2
  PADRINO_ENV = 'test' unless defined?(PADRINO_ENV)
3
3
  require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
4
4
 
5
+ # Specify your app using the #app helper inside a context.
6
+ # If you don't specify one, Riot::Rack will recursively look for a config.ru file.
7
+ # Takes either an app class or a block argument.
8
+ # app { Padrino.application }
9
+ # app { CLASS_NAME.tap { |app| } }
10
+
5
11
  class Riot::Situation
6
12
  include Rack::Test::Methods
7
13
 
14
+ # The Rack app under test.
8
15
  def app
9
- ##
10
- # You can handle all padrino applications using instead:
11
- # Padrino.application
12
- CLASS_NAME.tap { |app| }
16
+ defined?(@app) ? @app : build_app
17
+ end
18
+
19
+ private
20
+
21
+ def build_app
22
+ config_file = File.read(find_config_file)
23
+ Rack::Builder.new { instance_eval(config_file) }.to_app
24
+ end
25
+
26
+ def find_config_file
27
+ if Dir.glob("config.ru").length > 0
28
+ File.join(Dir.pwd,"config.ru")
29
+ elsif Dir.pwd != "/"
30
+ Dir.chdir("..") { find_config_file }
31
+ else
32
+ raise "Cannot find config.ru"
33
+ end
34
+ end
35
+ end
36
+
37
+ class Riot::Context
38
+ # Set the Rack app which is to be tested.
39
+ #
40
+ # context "MyApp" do
41
+ # app { [200, {}, "Hello!"] }
42
+ # setup { get '/' }
43
+ # asserts(:status).equals(200)
44
+ # end
45
+ def app(app=nil, &block)
46
+ setup { @app = (app || block) }
13
47
  end
14
48
  end
49
+
15
50
  TEST
16
51
 
17
52
  RIOT_CONTROLLER_TEST = (<<-TEST).gsub(/^ {10}/, '') unless defined?(RIOT_CONTROLLER_TEST)
@@ -32,7 +67,7 @@ RIOT_RAKE = (<<-TEST).gsub(/^ {10}/, '') unless defined?(RIOT_RAKE)
32
67
  require 'rake/testtask'
33
68
 
34
69
  Rake::TestTask.new(:test) do |test|
35
- test.pattern = '**/*_test.rb'
70
+ test.pattern = 'test/**/*_test.rb'
36
71
  test.verbose = true
37
72
  end
38
73
  TEST
@@ -43,15 +78,16 @@ require File.expand_path(File.dirname(__FILE__) + '/../test_config.rb')
43
78
  context "!NAME! Model" do
44
79
  context 'can be created' do
45
80
  setup do
46
- @!DNAME! = !NAME!.new
81
+ !NAME!.new
47
82
  end
48
83
 
49
- asserts("that record is not nil") { !@!DNAME!.nil? }
84
+ asserts("that record is not nil") { !topic.nil? }
50
85
  end
51
86
  end
52
87
  TEST
53
88
 
54
89
  def setup_test
90
+ require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
55
91
  require_dependencies 'riot', :group => 'test'
56
92
  insert_test_suite_setup RIOT_SETUP
57
93
  create_file destination_root("test/test.rake"), RIOT_RAKE
@@ -64,6 +100,6 @@ def generate_controller_test(name)
64
100
  end
65
101
 
66
102
  def generate_model_test(name)
67
- riot_contents = RIOT_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize).gsub(/!DNAME!/, name.to_s.underscore)
103
+ riot_contents = RIOT_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize)
68
104
  create_file destination_root("test/models/#{name.to_s.underscore}_test.rb"), riot_contents, :skip => true
69
- end
105
+ end
@@ -32,7 +32,7 @@ RSPEC_RAKE = (<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_RAKE)
32
32
  require 'spec/rake/spectask'
33
33
 
34
34
  Spec::Rake::SpecTask.new(:spec) do |t|
35
- t.spec_files = Dir['**/*_spec.rb']
35
+ t.spec_files = Dir['spec/**/*_spec.rb']
36
36
  t.spec_opts = %w(-fs --color)
37
37
  end
38
38
  TEST
@@ -49,6 +49,7 @@ end
49
49
  TEST
50
50
 
51
51
  def setup_test
52
+ require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
52
53
  require_dependencies 'rspec', :require => 'spec', :group => 'test'
53
54
  insert_test_suite_setup RSPEC_SETUP, :path => "spec/spec_helper.rb"
54
55
  create_file destination_root("spec/spec.rake"), RSPEC_RAKE
@@ -34,7 +34,7 @@ SHOULDA_RAKE = (<<-TEST).gsub(/^ {10}/, '') unless defined?(SHOULDA_RAKE)
34
34
  require 'rake/testtask'
35
35
 
36
36
  Rake::TestTask.new(:test) do |test|
37
- test.pattern = '**/*_test.rb'
37
+ test.pattern = 'test/**/*_test.rb'
38
38
  test.verbose = true
39
39
  end
40
40
  TEST
@@ -53,6 +53,7 @@ end
53
53
  TEST
54
54
 
55
55
  def setup_test
56
+ require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
56
57
  require_dependencies 'shoulda', :group => 'test'
57
58
  insert_test_suite_setup SHOULDA_SETUP
58
59
  create_file destination_root("test/test.rake"), SHOULDA_RAKE
@@ -29,7 +29,7 @@ TESTSPEC_RAKE = (<<-TEST).gsub(/^ {10}/, '') unless defined?(TESTSPEC_RAKE)
29
29
  require 'rake/testtask'
30
30
 
31
31
  Rake::TestTask.new(:test) do |test|
32
- test.pattern = '**/*_test.rb'
32
+ test.pattern = 'test/**/*_test.rb'
33
33
  test.verbose = true
34
34
  end
35
35
  TEST
@@ -46,6 +46,7 @@ end
46
46
  TEST
47
47
 
48
48
  def setup_test
49
+ require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
49
50
  require_dependencies 'test-spec', :require => 'test/spec', :group => 'test'
50
51
  insert_test_suite_setup TESTSPEC_SETUP
51
52
  create_file destination_root("test/test.rake"), TESTSPEC_RAKE
@@ -20,7 +20,7 @@ module Padrino
20
20
  argument :name, :desc => "The name of your padrino controller"
21
21
  argument :fields, :desc => "The fields for the controller", :type => :array, :default => []
22
22
  class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
23
- class_option :app, :desc => "The application destination", :aliases => '-a', :default => "/app", :type => :string
23
+ class_option :app, :desc => "The application destination path", :aliases => '-a', :default => "/app", :type => :string
24
24
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
25
25
 
26
26
  # Show help if no argv given
@@ -29,7 +29,7 @@ module Padrino
29
29
  def create_controller
30
30
  self.destination_root = options[:root]
31
31
  if in_app_root?
32
- app = options[:app].underscore
32
+ app = options[:app]
33
33
  check_app_existence(app)
34
34
  @app_name = fetch_app_name(app)
35
35
  @actions = controller_actions(fields)
@@ -19,7 +19,7 @@ module Padrino
19
19
 
20
20
  argument :name, :desc => "The name of your padrino mailer"
21
21
  class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
22
- class_option :app, :desc => "The application destination", :aliases => '-a', :default => "/app", :type => :string
22
+ class_option :app, :desc => "The application destination path", :aliases => '-a', :default => "/app", :type => :string
23
23
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
24
24
 
25
25
  # Show help if no argv given
@@ -28,16 +28,14 @@ module Padrino
28
28
  def create_mailer
29
29
  self.destination_root = options[:root]
30
30
  if in_app_root?
31
- app = options[:app].underscore
31
+ app = options[:app]
32
32
  check_app_existence(app)
33
33
  self.behavior = :revoke if options[:destroy]
34
- simple_name = name.to_s.gsub(/mailer/i, '')
35
- @mailer_basename = "#{simple_name.downcase.underscore}_mailer"
36
- @mailer_klass = "#{simple_name.downcase.camelize}Mailer"
37
- template "templates/mailer_initializer.rb.tt", destination_root("lib/mailer.rb"), :skip => true
34
+ @app_name = fetch_app_name(app)
35
+ @short_name = name.to_s.gsub(/mailer/i, '').underscore.downcase
36
+ @mailer_basename = @short_name.underscore
38
37
  template "templates/mailer.rb.tt", destination_root(app, "mailers", "#{@mailer_basename}.rb")
39
- inject_into_file(destination_root(app, "app.rb"), " register MailerInitializer\n", :after => "configure do\n")
40
- empty_directory destination_root(app, 'views', @mailer_basename)
38
+ empty_directory destination_root(app, 'views', 'mailers', @mailer_basename)
41
39
  else
42
40
  say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
43
41
  end
@@ -20,6 +20,7 @@ module Padrino
20
20
  argument :name, :desc => "The name of your padrino model"
21
21
  argument :fields, :desc => "The fields for the model", :type => :array, :default => []
22
22
  class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
23
+ class_option :app, :desc => "The application destination path", :aliases => '-a', :default => "/app", :type => :string
23
24
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
24
25
  class_option :skip_migration, :aliases => "-s", :default => false, :type => :boolean
25
26
 
@@ -29,14 +30,21 @@ module Padrino
29
30
  def create_model
30
31
  self.destination_root = options[:root]
31
32
  if in_app_root?
33
+ app = options[:app]
34
+ check_app_existence(app)
32
35
  self.behavior = :revoke if options[:destroy]
36
+ if invalids = invalid_fields(fields)
37
+ say "Invalid field name:", :red
38
+ say " #{invalids.join(", ")}"
39
+ return
40
+ end
33
41
  unless include_component_module_for(:orm)
34
42
  say "<= You need an ORM adapter for run this generator. Sorry!"
35
43
  raise SystemExit
36
44
  end
37
45
  include_component_module_for(:test)
38
46
  migration_name = "create_#{name.pluralize.underscore}"
39
- create_model_file(name, fields)
47
+ create_model_file(name, :fields => fields, :app => app)
40
48
  generate_model_test(name) if test?
41
49
  create_model_migration(migration_name, name, fields) unless options[:skip_migration]
42
50
  else
@@ -1,28 +1,26 @@
1
- =begin
2
-
3
- This file mounts each application within the Padrino project to a specific path.
4
- You can mount additional applications using any of these below:
5
-
6
- Padrino.mount("blog").to('/blog')
7
- Padrino.mount("blog", :app_class => "BlogApp").to('/blog')
8
- Padrino.mount("blog", :app_file => "/path/to/blog/app.rb").to('/blog')
9
-
10
- You can map also apps to a specified host:
11
-
12
- Padrino.mount_core("Blog").host("blog.example.org")
13
- Padrino.mount("Admin").host("admin.example.org")
14
- Padrino.mount("WebSite").host(/.*\.?example.org/)
15
- Padrino.mount("Foo").to("/foo").host("bar.example.org")
16
-
17
- Note 1: that mounted apps by default should be placed into 'apps/app_name'.
18
- Note 2: if you use host match remember that it's important respect order.
19
-
20
- By default, this file simply mounts the core app which was generated with this project.
21
- However, the mounted core can be modified as needed:
22
-
23
- Padrino.mount_core(:app_file => "/path/to/file", :app_class => "Blog")
24
-
25
- =end
1
+ ##
2
+ # This file mounts each app in the Padrino project to a specified sub-uri.
3
+ # You can mount additional applications using any of these commands below:
4
+ #
5
+ # Padrino.mount("blog").to('/blog')
6
+ # Padrino.mount("blog", :app_class => "BlogApp").to('/blog')
7
+ # Padrino.mount("blog", :app_file => "/path/to/blog/app.rb").to('/blog')
8
+ #
9
+ # You can also map apps to a specified host:
10
+ #
11
+ # Padrino.mount_core("Blog").host("blog.example.org")
12
+ # Padrino.mount("Admin").host("admin.example.org")
13
+ # Padrino.mount("WebSite").host(/.*\.?example.org/)
14
+ # Padrino.mount("Foo").to("/foo").host("bar.example.org")
15
+ #
16
+ # Note 1: Mounted apps (by default) should be placed into the project root at '/app_name'.
17
+ # Note 2: If you use the host matching remember to respect the order of the rules.
18
+ #
19
+ # By default, this file mounts the core app which was generated with this project.
20
+ # However, the mounted core can be modified as needed:
21
+ #
22
+ # Padrino.mount_core(:app_file => "/path/to/file", :app_class => "Blog")
23
+ #
26
24
 
27
25
  # Mounts the core application for this project
28
- Padrino.mount_core("<%= @class_name %>")
26
+ Padrino.mount_core("<%= @app_name %>")
@@ -1,6 +1,6 @@
1
1
  # Defines our constants
2
- PADRINO_ENV = ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= "development" unless defined?(PADRINO_ENV)
3
- PADRINO_ROOT = File.dirname(__FILE__) + '/..' unless defined? PADRINO_ROOT
2
+ PADRINO_ENV = ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= "development" unless defined?(PADRINO_ENV)
3
+ PADRINO_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) unless defined?(PADRINO_ROOT)
4
4
 
5
5
  begin
6
6
  # Require the preresolved locked set of gems.