padrino-gen 0.9.14 → 0.9.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/LICENSE +1 -1
  2. data/README.rdoc +17 -2
  3. data/Rakefile +1 -2
  4. data/bin/padrino-gen +2 -3
  5. data/lib/padrino-gen.rb +2 -2
  6. data/lib/padrino-gen/generators/actions.rb +62 -8
  7. data/lib/padrino-gen/generators/app.rb +2 -1
  8. data/lib/padrino-gen/generators/cli.rb +3 -3
  9. data/lib/padrino-gen/generators/components/orms/activerecord.rb +10 -9
  10. data/lib/padrino-gen/generators/components/orms/couchrest.rb +1 -1
  11. data/lib/padrino-gen/generators/components/orms/datamapper.rb +11 -9
  12. data/lib/padrino-gen/generators/components/orms/mongoid.rb +1 -1
  13. data/lib/padrino-gen/generators/components/orms/mongomapper.rb +1 -1
  14. data/lib/padrino-gen/generators/components/orms/mongomatic.rb +85 -0
  15. data/lib/padrino-gen/generators/components/orms/ohm.rb +72 -0
  16. data/lib/padrino-gen/generators/components/orms/sequel.rb +12 -11
  17. data/lib/padrino-gen/generators/components/renderers/erubis.rb +3 -0
  18. data/lib/padrino-gen/generators/components/renderers/liquid.rb +4 -0
  19. data/lib/padrino-gen/generators/components/stylesheets/compass.rb +3 -3
  20. data/lib/padrino-gen/generators/components/stylesheets/compass/application.scss +1 -1
  21. data/lib/padrino-gen/generators/components/stylesheets/less.rb +12 -23
  22. data/lib/padrino-gen/generators/components/stylesheets/sass.rb +6 -16
  23. data/lib/padrino-gen/generators/components/stylesheets/scss.rb +16 -0
  24. data/lib/padrino-gen/generators/components/tests/riot.rb +5 -23
  25. data/lib/padrino-gen/generators/controller.rb +1 -1
  26. data/lib/padrino-gen/generators/mailer.rb +3 -1
  27. data/lib/padrino-gen/generators/migration.rb +1 -1
  28. data/lib/padrino-gen/generators/model.rb +1 -1
  29. data/lib/padrino-gen/generators/plugin.rb +47 -0
  30. data/lib/padrino-gen/generators/project.rb +39 -22
  31. data/lib/padrino-gen/generators/project/config/boot.rb +12 -0
  32. data/lib/padrino-gen/generators/runner.rb +90 -0
  33. data/lib/padrino-gen/generators/templates/initializer.rb.tt +5 -0
  34. data/lib/padrino-gen/generators/templates/mailer.rb.tt +10 -0
  35. data/lib/padrino-gen/padrino-tasks/datamapper.rb +8 -7
  36. data/padrino-gen.gemspec +11 -12
  37. data/test/fixtures/admin_template.rb +7 -0
  38. data/test/fixtures/example_template.rb +14 -0
  39. data/test/fixtures/git_template.rb +4 -0
  40. data/test/fixtures/plugin_template.rb +13 -0
  41. data/test/fixtures/rake_template.rb +9 -0
  42. data/test/helper.rb +64 -2
  43. data/test/test_app_generator.rb +16 -1
  44. data/test/test_controller_generator.rb +1 -1
  45. data/test/test_generator.rb +1 -1
  46. data/test/test_mailer_generator.rb +11 -1
  47. data/test/test_model_generator.rb +64 -20
  48. data/test/test_plugin_generator.rb +123 -0
  49. data/test/test_project_generator.rb +134 -77
  50. metadata +37 -103
@@ -0,0 +1,72 @@
1
+ OHM = (<<-OHM) unless defined?(OHM)
2
+ # Ohm does not have the concept of namespaces
3
+ # This means that you will not be able to have
4
+ # a distinct test,development or production database
5
+ #
6
+ # You can, however, run multiple redis servers on the same host
7
+ # and point to them based on the environment:
8
+ #
9
+ # case Padrino.env
10
+ # when :development then Ohm.connect(:port => 6379)
11
+ # when :production then Ohm.connect(:port => 6380)
12
+ # when :test then Ohm.connect(:port => 6381)
13
+ # end
14
+
15
+ # Alternatively, you can try specifying a difference :db
16
+ # which, outside of confirmation, appears to provide distinct
17
+ # namespaces from testing
18
+ # case Padrino.env
19
+ # when :development then Ohm.connect(:db => 0)
20
+ # when :production then Ohm.connect(:db => 1)
21
+ # when :test then Ohm.connect(:db => 2)
22
+ # end
23
+ OHM
24
+
25
+ def setup_orm
26
+ ohm = OHM
27
+ require_dependencies 'json'
28
+ require_dependencies 'ohm', :require => 'ohm'
29
+ require_dependencies 'ohm-contrib', :require => 'ohm/contrib'
30
+ create_file("config/database.rb", ohm)
31
+ empty_directory('app/models')
32
+ end
33
+
34
+ OHM_MODEL = (<<-MODEL) unless defined?(OHM_MODEL)
35
+ class !NAME! < Ohm::Model
36
+ include Ohm::Timestamping
37
+ include Ohm::Typecast
38
+
39
+ # Examples:
40
+ # attribute :name
41
+ # attribute :email, String
42
+ # reference :venue, Venue
43
+ # set :participants, Person
44
+ # counter :votes
45
+ #
46
+ # index :name
47
+ #
48
+ # def validate
49
+ # assert_present :name
50
+ # end
51
+
52
+ !FIELDS!
53
+ end
54
+ MODEL
55
+
56
+ # options => { :fields => ["title:string", "body:string"], :app => 'app' }
57
+ def create_model_file(name, options={})
58
+ model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
59
+ field_tuples = options[:fields].collect { |value| value.split(":") }
60
+ column_declarations = field_tuples.collect { |field, kind| "attribute :#{field}, #{kind.camelize}" }.join("\n ")
61
+ model_contents = OHM_MODEL.gsub(/!NAME!/, name.to_s.camelize)
62
+ model_contents.gsub!(/!FIELDS!/, column_declarations)
63
+ create_file(model_path, model_contents)
64
+ end
65
+
66
+ def create_model_migration(filename, name, fields)
67
+ # NO MIGRATION NEEDED
68
+ end
69
+
70
+ def create_migration_file(migration_name, name, columns)
71
+ # NO MIGRATION NEEDED
72
+ end
@@ -10,22 +10,23 @@ SEQUEL
10
10
 
11
11
  def setup_orm
12
12
  sequel = SEQUEL
13
- require_dependencies 'sequel'
13
+ db = @app_name.underscore
14
+ require_dependencies 'sequel'
14
15
  require_dependencies case options[:adapter]
15
16
  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\"")
17
+ sequel.gsub!(/!DB_DEVELOPMENT!/, "\"mysql://localhost/#{db}_development\"")
18
+ sequel.gsub!(/!DB_PRODUCTION!/, "\"mysql://localhost/#{db}_production\"")
19
+ sequel.gsub!(/!DB_TEST!/,"\"mysql://localhost/#{db}_test\"")
19
20
  'mysql'
20
21
  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\"")
22
+ sequel.gsub!(/!DB_DEVELOPMENT!/, "\"postgres://localhost/#{db}_development\"")
23
+ sequel.gsub!(/!DB_PRODUCTION!/, "\"postgres://localhost/#{db}_production\"")
24
+ sequel.gsub!(/!DB_TEST!/,"\"postgres://localhost/#{db}_test\"")
24
25
  'pg'
25
26
  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\")")
27
+ sequel.gsub!(/!DB_DEVELOPMENT!/,"\"sqlite://\" + Padrino.root('db', \"#{db}_development.db\")")
28
+ sequel.gsub!(/!DB_PRODUCTION!/,"\"sqlite://\" + Padrino.root('db', \"#{db}_production.db\")")
29
+ sequel.gsub!(/!DB_TEST!/,"\"sqlite://\" + Padrino.root('db', \"#{db}_test.db\")")
29
30
  'sqlite3-ruby'
30
31
  end
31
32
  create_file("config/database.rb", sequel)
@@ -87,4 +88,4 @@ def create_migration_file(migration_name, name, columns)
87
88
  :add => Proc.new { |field, kind| "add_column :#{field}, #{kind.camelize}" },
88
89
  :remove => Proc.new { |field, kind| "drop_column :#{field}" }
89
90
  )
90
- end
91
+ end
@@ -0,0 +1,3 @@
1
+ def setup_renderer
2
+ require_dependencies 'erubis'
3
+ end
@@ -0,0 +1,4 @@
1
+ def setup_renderer
2
+ require_dependencies 'liquid', :version => "= 2.1.2"
3
+ require_dependencies 'liquify'
4
+ end
@@ -6,7 +6,7 @@ COMPASS_INIT = (<<-COMPASS).gsub(/^ {10}/, '') unless defined?(COMPASS_INIT)
6
6
  module CompassInitializer
7
7
  def self.registered(app)
8
8
  require 'sass/plugin/rack'
9
-
9
+
10
10
  Compass.configuration do |config|
11
11
  config.project_path = Padrino.root
12
12
  config.sass_dir = "app/stylesheets"
@@ -17,10 +17,10 @@ module CompassInitializer
17
17
  config.javascripts_dir = "public/javascripts"
18
18
  config.output_style = :compressed
19
19
  end
20
-
20
+
21
21
  Compass.configure_sass_plugin!
22
22
  Compass.handle_configuration_change!
23
-
23
+
24
24
  app.use Sass::Plugin::Rack
25
25
  end
26
26
  end
@@ -29,7 +29,7 @@ body.bp {
29
29
  }
30
30
 
31
31
  form.bp {
32
- @include blueprint-form;
32
+ @include blueprint-form;
33
33
  }
34
34
 
35
35
  .two-col {
@@ -1,33 +1,22 @@
1
- LESS_INIT = (<<-LESS).gsub(/^ {10}/, '') unless defined?(LESS_INIT)
1
+ LESS_INIT = (<<-LESS).gsub(/^ {6}/, '')
2
2
  # Enables support for Less template reloading for rack.
3
3
  # Store Less files by default within 'app/stylesheets/'
4
4
  # See http://github.com/kelredd/rack-less for more details.
5
-
6
- module LessInitializer
7
- def self.registered(app)
8
- require 'rack/less'
9
- # optional - use as necessary
10
- Rack::Less.configure do |config|
11
- config.compress = true
12
- # other configs ...
13
- end
14
- app.use Rack::Less,
15
- :root => app.root,
16
- :source => 'stylesheets/',
17
- :public => 'public/',
18
- :hosted_at => '/stylesheets'
19
- end
5
+ require 'rack/less'
6
+ # optional - use as necessary
7
+ Rack::Less.configure do |config|
8
+ config.compress = true
9
+ # other configs ...
20
10
  end
21
-
11
+ app.use Rack::Less,
12
+ :root => app.root,
13
+ :source => 'stylesheets/',
14
+ :public => 'public/',
15
+ :hosted_at => '/stylesheets'
22
16
  LESS
23
17
 
24
- LESS_REGISTER = (<<-LESSR).gsub(/^ {10}/, '') unless defined?(LESS_REGISTER)
25
- register LessInitializer\n
26
- LESSR
27
-
28
18
  def setup_stylesheet
29
19
  require_dependencies 'less', 'rack-less'
30
- create_file destination_root('/lib/less_plugin.rb'), LESS_INIT
31
- inject_into_file destination_root('/app/app.rb'), LESS_REGISTER, :after => "register Padrino::Helpers\n"
20
+ initializer :less, LESS_INIT
32
21
  empty_directory destination_root('/app/stylesheets')
33
22
  end
@@ -1,25 +1,15 @@
1
- SASS_INIT = (<<-SASS).gsub(/^ {10}/, '') unless defined?(SASS_INIT)
1
+ SASS_INIT = (<<-SASS).gsub(/^ {6}/, '')
2
2
  # Enables support for SASS template reloading in rack applications.
3
3
  # See http://nex-3.com/posts/88-sass-supports-rack for more details.
4
4
  # Store SASS files (by default) within 'app/stylesheets'
5
-
6
- module SassInitializer
7
- def self.registered(app)
8
- require 'sass/plugin/rack'
9
- Sass::Plugin.options[:template_location] = Padrino.root("app/stylesheets")
10
- Sass::Plugin.options[:css_location] = Padrino.root("public/stylesheets")
11
- app.use Sass::Plugin::Rack
12
- end
13
- end
5
+ require 'sass/plugin/rack'
6
+ Sass::Plugin.options[:template_location] = Padrino.root("app/stylesheets")
7
+ Sass::Plugin.options[:css_location] = Padrino.root("public/stylesheets")
8
+ app.use Sass::Plugin::Rack
14
9
  SASS
15
10
 
16
- SASS_REGISTER = (<<-SASSR).gsub(/^ {10}/, '') unless defined?(SASS_REGISTER)
17
- register SassInitializer\n
18
- SASSR
19
-
20
11
  def setup_stylesheet
21
12
  require_dependencies 'haml'
22
- create_file destination_root('/lib/sass_plugin.rb'), SASS_INIT
23
- inject_into_file destination_root('/app/app.rb'), SASS_REGISTER, :after => "register Padrino::Helpers\n"
13
+ initializer :sass, SASS_INIT
24
14
  empty_directory destination_root('/app/stylesheets')
25
15
  end
@@ -0,0 +1,16 @@
1
+ SCSS_INIT = (<<-SCSS).gsub(/^ {6}/, '')
2
+ # Enables support for SCSS template reloading in rack applications.
3
+ # See http://nex-3.com/posts/88-sass-supports-rack for more details.
4
+ # Store SCSS files (by default) within 'app/stylesheets'
5
+ require 'sass/plugin/rack'
6
+ Sass::Plugin.options[:syntax] = :scss
7
+ Sass::Plugin.options[:template_location] = Padrino.root("app/stylesheets")
8
+ Sass::Plugin.options[:css_location] = Padrino.root("public/stylesheets")
9
+ app.use Sass::Plugin::Rack
10
+ SCSS
11
+
12
+ def setup_stylesheet
13
+ require_dependencies 'haml'
14
+ initializer :scss, SCSS_INIT
15
+ empty_directory destination_root('/app/stylesheets')
16
+ end
@@ -3,35 +3,17 @@ PADRINO_ENV = 'test' unless defined?(PADRINO_ENV)
3
3
  require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
4
4
 
5
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
6
  # Takes either an app class or a block argument.
8
7
  # app { Padrino.application }
9
8
  # app { CLASS_NAME.tap { |app| } }
10
9
 
11
10
  class Riot::Situation
12
11
  include Rack::Test::Methods
12
+ ##
13
+ # You can handle all padrino applications using instead:
14
+ # Padrino.application
15
+ CLASS_NAME.tap { |app| }
13
16
 
14
- # The Rack app under test.
15
- def 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
17
  end
36
18
 
37
19
  class Riot::Context
@@ -102,4 +84,4 @@ end
102
84
  def generate_model_test(name)
103
85
  riot_contents = RIOT_MODEL_TEST.gsub(/!NAME!/, name.to_s.camelize)
104
86
  create_file destination_root("test/models/#{name.to_s.underscore}_test.rb"), riot_contents, :skip => true
105
- end
87
+ end
@@ -41,7 +41,7 @@ module Padrino
41
41
  include_component_module_for(:test)
42
42
  generate_controller_test(name) if test?
43
43
  else
44
- say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
44
+ say "You are not at the root of a Padrino application! (config/boot.rb not found)"
45
45
  end
46
46
  end
47
47
  end # Controller
@@ -18,6 +18,7 @@ module Padrino
18
18
  desc "Description:\n\n\tpadrino-gen mailer generates a new Padrino mailer"
19
19
 
20
20
  argument :name, :desc => "The name of your padrino mailer"
21
+ argument :actions, :desc => "The delivery actions to add to your mailer", :type => :array, :default => []
21
22
  class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
22
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
@@ -32,12 +33,13 @@ module Padrino
32
33
  check_app_existence(app)
33
34
  self.behavior = :revoke if options[:destroy]
34
35
  @app_name = fetch_app_name(app)
36
+ @actions = actions.map{|a| a.to_sym}
35
37
  @short_name = name.to_s.gsub(/mailer/i, '').underscore.downcase
36
38
  @mailer_basename = @short_name.underscore
37
39
  template "templates/mailer.rb.tt", destination_root(app, "mailers", "#{@mailer_basename}.rb")
38
40
  empty_directory destination_root(app, 'views', 'mailers', @mailer_basename)
39
41
  else
40
- say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
42
+ say "You are not at the root of a Padrino application! (config/boot.rb not found)"
41
43
  end
42
44
  end
43
45
  end # Mailer
@@ -36,7 +36,7 @@ module Padrino
36
36
  raise SystemExit
37
37
  end
38
38
  else
39
- say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
39
+ say "You are not at the root of a Padrino application! (config/boot.rb not found)"
40
40
  end
41
41
  end
42
42
  end # Migration
@@ -48,7 +48,7 @@ module Padrino
48
48
  generate_model_test(name) if test?
49
49
  create_model_migration(migration_name, name, fields) unless options[:skip_migration]
50
50
  else
51
- say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
51
+ say "You are not at the root of a Padrino application! (config/boot.rb not found)"
52
52
  end
53
53
  end
54
54
  end # Model
@@ -0,0 +1,47 @@
1
+ require 'padrino-core/cli/base' unless defined?(Padrino::Cli::Base)
2
+
3
+ module Padrino
4
+ module Generators
5
+ class Plugin < Thor::Group
6
+ PLUGIN_URL = 'http://github.com/padrino/padrino-recipes/tree/master/plugins'
7
+ # Add this generator to our padrino-gen
8
+ Padrino::Generators.add_generator(:plugin, self)
9
+
10
+ # Define the source plugin root
11
+ def self.source_root; File.expand_path(File.dirname(__FILE__)); end
12
+ def self.banner; "padrino-gen plugin [plugin_identifier] [options]"; end
13
+
14
+ # Include related modules
15
+ include Thor::Actions
16
+ include Padrino::Generators::Actions
17
+ include Padrino::Generators::Runner
18
+
19
+ desc "Description:\n\n\tpadrino-gen plugin sets up a plugin within a Padrino application"
20
+
21
+ argument :plugin_file, :desc => "The name or path to the Padrino plugin", :optional => true
22
+
23
+ class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
24
+ class_option :list, :desc => "list available plugins", :aliases => '-l', :default => false, :type => :boolean
25
+ class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
26
+ # Show help if no argv given
27
+ require_arguments!
28
+
29
+ # Create the Padrino Plugin
30
+ def setup_plugin
31
+ if options[:list] # list method ran here
32
+ plugins = open(PLUGIN_URL).read.scan(%r{/plugins/(\w+)_plugin.rb}).uniq
33
+ say "Available plugins:", :green
34
+ say plugins.map { |plugin| " - #{plugin}" }.join("\n")
35
+ else # executing the plugin instructions
36
+ if in_app_root?
37
+ self.behavior = :revoke if options[:destroy]
38
+ self.destination_root = options[:root]
39
+ execute_runner(:plugin, plugin_file)
40
+ else
41
+ say "You are not at the root of a Padrino application! (config/boot.rb not found)"
42
+ end
43
+ end
44
+ end
45
+ end # Plugins
46
+ end # Generators
47
+ end # Padrino
@@ -14,26 +14,28 @@ module Padrino
14
14
  # Include related modules
15
15
  include Thor::Actions
16
16
  include Padrino::Generators::Actions
17
+ include Padrino::Generators::Runner
17
18
  include Padrino::Generators::Components::Actions
18
19
 
19
20
  desc "Description:\n\n\tpadrino-gen project generates a new Padrino project"
20
21
 
21
22
  argument :name, :desc => "The name of your padrino project"
22
23
 
23
- class_option :app , :desc => "The application name", :aliases => '-n', :default => nil, :type => :string
24
- class_option :run_bundle, :desc => "Run bundle install", :aliases => '-b', :default => false, :type => :boolean
25
- class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
26
- class_option :dev, :desc => "Use padrino from a git checkout", :default => false, :type => :boolean
27
- class_option :tiny, :desc => "Generate tiny app skeleton", :aliases => '-i', :default => false, :type => :boolean
28
- class_option :adapter, :desc => "SQL adapter for ORM (sqlite, mysql, postgres)", :aliases => '-a', :default => "sqlite", :type => :string
24
+ class_option :app , :desc => "The application name", :aliases => '-n', :default => nil, :type => :string
25
+ class_option :bundle, :desc => "Run bundle install", :aliases => '-b', :default => false, :type => :boolean
26
+ class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
27
+ class_option :dev, :desc => "Use padrino from a git checkout", :default => false, :type => :boolean
28
+ class_option :tiny, :desc => "Generate tiny app skeleton", :aliases => '-i', :default => false, :type => :boolean
29
+ class_option :adapter, :desc => "SQL adapter for ORM (sqlite, mysql, postgres)", :aliases => '-a', :default => "sqlite", :type => :string
30
+ class_option :template, :desc => "Generate project from template", :aliases => '-p', :default => nil, :type => :string
29
31
 
30
32
  # Definitions for the available customizable components
31
- component_option :orm, "database engine", :aliases => '-d', :choices => [:activerecord, :datamapper, :mongomapper, :mongoid, :sequel, :couchrest], :default => :none
33
+ component_option :orm, "database engine", :aliases => '-d', :choices => [:activerecord, :datamapper, :mongomapper, :mongoid, :sequel, :couchrest, :ohm, :mongomatic], :default => :none
32
34
  component_option :test, "testing framework", :aliases => '-t', :choices => [:rspec, :shoulda, :cucumber, :bacon, :testspec, :riot], :default => :none
33
35
  component_option :mock, "mocking library", :aliases => '-m', :choices => [:mocha, :rr], :default => :none
34
36
  component_option :script, "javascript library", :aliases => '-s', :choices => [:jquery, :prototype, :rightjs, :mootools, :extcore, :dojo], :default => :none
35
- component_option :renderer, "template engine", :aliases => '-e', :choices => [:haml, :erb], :default => :haml
36
- component_option :stylesheet, "stylesheet engine", :aliases => '-c', :choices => [:less, :sass, :compass], :default => :none
37
+ component_option :renderer, "template engine", :aliases => '-e', :choices => [:haml, :erb, :erubis, :liquid], :default => :haml
38
+ component_option :stylesheet, "stylesheet engine", :aliases => '-c', :choices => [:less, :sass, :compass, :scss], :default => :none
37
39
 
38
40
  # Show help if no argv given
39
41
  require_arguments!
@@ -42,44 +44,59 @@ module Padrino
42
44
  def setup_project
43
45
  @app_name = (options[:app] || name).gsub(/\W/, "_").underscore.camelize
44
46
  self.destination_root = File.join(options[:root], name)
45
- directory("project/", destination_root)
46
- app_skeleton('app', options[:tiny])
47
- store_component_config('.components')
48
- template "templates/Gemfile.tt", destination_root("Gemfile")
47
+ if options[:template] # Run the template to create project
48
+ execute_runner(:template, options[:template])
49
+ else # generate project without template
50
+ directory("project/", destination_root)
51
+ app_skeleton('app', options[:tiny])
52
+ store_component_config('.components')
53
+ template "templates/Gemfile.tt", destination_root("Gemfile")
54
+ end
49
55
  end
50
56
 
51
57
  # For each component, retrieve a valid choice and then execute the associated generator
52
58
  def setup_components
59
+ return if options[:template]
60
+ @_components = options.dup.slice(*self.class.component_types)
53
61
  self.class.component_types.each do |comp|
54
- choice = resolve_valid_choice(comp)
62
+ choice = @_components[comp] = resolve_valid_choice(comp)
55
63
  execute_component_setup(comp, choice)
56
64
  end
65
+ store_component_config('.components')
57
66
  end
58
67
 
59
68
  # Bundle all required components using bundler and Gemfile
60
69
  def bundle_dependencies
61
- if options[:run_bundle]
62
- say "Bundling application dependencies using bundler...", :yellow
63
- in_root { run 'bundle install' }
70
+ if options[:bundle]
71
+ run_bundler
64
72
  end
65
73
  end
66
74
 
67
75
  # Finish message
68
- def finish
69
- unless options[:run_bundle]
70
- say (<<-TEXT).gsub(/ {10}/,'')
76
+ def finish_message
77
+ if options[:bundle]
78
+ text = (<<-TEXT).gsub(/ {10}/,'')
71
79
 
72
80
  =================================================================
73
81
  #{name} is ready for development! Next, follow these steps:
74
82
  =================================================================
75
83
  1) cd #{name}
76
- 2) bundle install
77
84
  =================================================================
78
85
 
79
86
  TEXT
80
87
  else
81
- say "Project '#{name}' has been generated and all dependencies bundled!"
88
+ text = (<<-TEXT).gsub(/ {10}/,'')
89
+
90
+ =================================================================
91
+ #{name} is ready for development! Next, follow these steps:
92
+ =================================================================
93
+ 1) cd #{name}
94
+ 2) bundle install
95
+ =================================================================
96
+
97
+ TEXT
82
98
  end
99
+ say(text)
83
100
  end
84
101
  end # Project
85
102
  end # Generators