padrino-gen 0.11.3 → 0.11.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/README.rdoc +1 -1
  3. data/lib/padrino-gen.rb +14 -22
  4. data/lib/padrino-gen/command.rb +4 -5
  5. data/lib/padrino-gen/generators/actions.rb +63 -48
  6. data/lib/padrino-gen/generators/app.rb +15 -17
  7. data/lib/padrino-gen/generators/app/app.rb.tt +2 -2
  8. data/lib/padrino-gen/generators/cli.rb +9 -9
  9. data/lib/padrino-gen/generators/component.rb +62 -0
  10. data/lib/padrino-gen/generators/components/actions.rb +48 -57
  11. data/lib/padrino-gen/generators/components/mocks/mocha.rb +2 -1
  12. data/lib/padrino-gen/generators/components/mocks/rr.rb +1 -1
  13. data/lib/padrino-gen/generators/components/orms/minirecord.rb +2 -2
  14. data/lib/padrino-gen/generators/components/orms/mongoid.rb +7 -7
  15. data/lib/padrino-gen/generators/components/orms/ohm.rb +3 -3
  16. data/lib/padrino-gen/generators/components/stylesheets/compass.rb +1 -1
  17. data/lib/padrino-gen/generators/components/stylesheets/compass/partials/_base.scss +5 -3
  18. data/lib/padrino-gen/generators/components/stylesheets/less.rb +1 -1
  19. data/lib/padrino-gen/generators/components/stylesheets/sass.rb +1 -1
  20. data/lib/padrino-gen/generators/components/stylesheets/scss.rb +1 -1
  21. data/lib/padrino-gen/generators/controller.rb +6 -10
  22. data/lib/padrino-gen/generators/mailer.rb +7 -11
  23. data/lib/padrino-gen/generators/migration.rb +4 -9
  24. data/lib/padrino-gen/generators/model.rb +6 -12
  25. data/lib/padrino-gen/generators/plugin.rb +9 -12
  26. data/lib/padrino-gen/generators/project.rb +18 -28
  27. data/lib/padrino-gen/generators/runner.rb +25 -25
  28. data/lib/padrino-gen/padrino-tasks/activerecord.rb +11 -12
  29. data/lib/padrino-gen/padrino-tasks/datamapper.rb +3 -3
  30. data/lib/padrino-gen/padrino-tasks/mongoid.rb +9 -9
  31. data/lib/padrino-gen/padrino-tasks/mongomapper.rb +4 -5
  32. data/lib/padrino-gen/padrino-tasks/sequel.rb +1 -2
  33. data/test/helper.rb +1 -1
  34. data/test/test_component_generator.rb +85 -0
  35. data/test/test_generator.rb +1 -1
  36. data/test/test_plugin_generator.rb +1 -1
  37. data/test/test_project_generator.rb +11 -4
  38. metadata +12 -15
@@ -11,7 +11,7 @@ ActiveRecord::Base.configurations[:test] = {
11
11
  !DB_TEST!
12
12
  }
13
13
 
14
- # Setup our logger
14
+ # Setup our logger.
15
15
  ActiveRecord::Base.logger = logger
16
16
 
17
17
  # Raise exception on mass assignment protection for Active Record models.
@@ -30,7 +30,7 @@ ActiveRecord::Base.store_full_sti_class = true
30
30
  # Use ISO 8601 format for JSON serialized times and dates.
31
31
  ActiveSupport.use_standard_json_time_format = true
32
32
 
33
- # Don't escape HTML entities in JSON, leave that for the #json_escape helper
33
+ # Don't escape HTML entities in JSON, leave that for the json_escape helper
34
34
  # if you're including raw JSON in an HTML page.
35
35
  ActiveSupport.escape_html_entities_in_json = false
36
36
 
@@ -1,5 +1,5 @@
1
1
  MONGOID = (<<-MONGO) unless defined?(MONGOID)
2
- # Connection.new takes host, port
2
+ # Connection.new takes host and port
3
3
  host = 'localhost'
4
4
  port = Mongo::Connection::DEFAULT_PORT
5
5
 
@@ -11,7 +11,7 @@ end
11
11
 
12
12
  Mongoid.database = Mongo::Connection.new(host, port).db(database_name)
13
13
 
14
- # You can also configure Mongoid this way
14
+ # You can also configure Mongoid this way:
15
15
  # Mongoid.configure do |config|
16
16
  # name = @settings["database"]
17
17
  # host = @settings["host"]
@@ -22,11 +22,11 @@ Mongoid.database = Mongo::Connection.new(host, port).db(database_name)
22
22
  # ]
23
23
  # end
24
24
  #
25
- # More installation and setup notes are on http://mongoid.org/
25
+ # More installation and setup notes are on http://mongoid.org/.
26
26
  MONGO
27
27
 
28
28
  MONGOID3 = (<<-MONGO) unless defined?(MONGOID3)
29
- # Connection.new takes host, port
29
+ # Connection.new takes host and port.
30
30
 
31
31
  host = 'localhost'
32
32
  port = 27017
@@ -37,7 +37,7 @@ database_name = case Padrino.env
37
37
  when :test then '!NAME!_test'
38
38
  end
39
39
 
40
- # Use MONGO_URI if it's set as an environmental variable
40
+ # Use MONGO_URI if it's set as an environmental variable.
41
41
  Mongoid::Config.sessions =
42
42
  if ENV['MONGO_URI']
43
43
  {default: {uri: ENV['MONGO_URI'] }}
@@ -47,7 +47,7 @@ Mongoid::Config.sessions =
47
47
 
48
48
  # If you want to use a YML file for config, use this instead:
49
49
  #
50
- #  Mongoid.load!(File.join(Padrino.root, 'config', 'database.yml'), Padrino.env)
50
+ # Mongoid.load!(File.join(Padrino.root, 'config', 'database.yml'), Padrino.env)
51
51
  #
52
52
  # And add a config/database.yml file like this:
53
53
  # development:
@@ -55,7 +55,7 @@ Mongoid::Config.sessions =
55
55
  # default:
56
56
  # database: !NAME!_development
57
57
  # hosts:
58
- # - localhost:27017
58
+ # - localhost:27017
59
59
  # production:
60
60
  # sessions:
61
61
  # default:
@@ -1,7 +1,7 @@
1
1
  OHM = (<<-OHM) unless defined?(OHM)
2
- # Ohm does not have the concept of namespaces
2
+ # Ohm does not have the concept of namespaces.
3
3
  # This means that you will not be able to have
4
- # a distinct test,development or production database
4
+ # a distinct test, development, or production database.
5
5
  #
6
6
  # You can, however, run multiple redis servers on the same host
7
7
  # and point to them based on the environment:
@@ -14,7 +14,7 @@ OHM = (<<-OHM) unless defined?(OHM)
14
14
 
15
15
  # Alternatively, you can try specifying a difference :db
16
16
  # which, outside of confirmation, appears to provide distinct
17
- # namespaces from testing
17
+ # namespaces from testing:
18
18
  # case Padrino.env
19
19
  # when :development then Ohm.connect(:db => 0)
20
20
  # when :production then Ohm.connect(:db => 1)
@@ -1,7 +1,7 @@
1
1
  COMPASS_INIT = <<-COMPASS unless defined?(COMPASS_INIT)
2
2
  # Enables support for Compass, a stylesheet authoring framework based on SASS.
3
3
  # See http://compass-style.org/ for more details.
4
- # Store Compass/SASS files (by default) within 'app/stylesheets'
4
+ # Store Compass/SASS files (by default) within 'app/stylesheets'.
5
5
 
6
6
  module CompassInitializer
7
7
  def self.registered(app)
@@ -1,10 +1,12 @@
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:
1
+ // Here is where you can define your constants for your application and to
2
+ // configure the blueprint framework. Feel free to delete these if you want
3
+ // keep the defaults:
3
4
 
4
5
  $blueprint-grid-columns: 24;
5
6
  $blueprint-container-size: 950px;
6
7
  $blueprint-grid-margin: 10px;
7
8
 
8
9
  // 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
+ // Or you can set !blueprint_grid_width to a fixed value and
11
+ // unset !blueprint_container_size -- it will be calculated for you.
10
12
  $blueprint-grid-width: ($blueprint-container-size + $blueprint-grid-margin) / $blueprint-grid-columns - $blueprint-grid-margin;
@@ -1,6 +1,6 @@
1
1
  LESS_INIT = <<-LESS unless defined?(LESS_INIT)
2
2
  # Enables support for Less template reloading for rack.
3
- # Store Less files by default within 'app/stylesheets/'
3
+ # Store Less files by default within 'app/stylesheets/'.
4
4
  # See http://github.com/kelredd/rack-less for more details.
5
5
  require 'rack/less'
6
6
  # optional - use as necessary
@@ -1,7 +1,7 @@
1
1
  SASS_INIT = <<-SASS unless defined?(SASS_INIT)
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
- # Store SASS files (by default) within 'app/stylesheets'
4
+ # Store SASS files (by default) within 'app/stylesheets'.
5
5
  require 'sass/plugin/rack'
6
6
  Sass::Plugin.options[:template_location] = Padrino.root("app/stylesheets")
7
7
  Sass::Plugin.options[:css_location] = Padrino.root("public/stylesheets")
@@ -1,7 +1,7 @@
1
1
  SCSS_INIT = <<-SCSS unless defined?(SCSS_INIT)
2
2
  # Enables support for SCSS template reloading in rack applications.
3
3
  # See http://nex-3.com/posts/88-sass-supports-rack for more details.
4
- # Store SCSS files (by default) within 'app/stylesheets'
4
+ # Store SCSS files (by default) within 'app/stylesheets'.
5
5
  require 'sass/plugin/rack'
6
6
  Sass::Plugin.options[:syntax] = :scss
7
7
  Sass::Plugin.options[:template_location] = Padrino.root("app/stylesheets")
@@ -5,15 +5,11 @@ module Padrino
5
5
  #
6
6
  class Controller < Thor::Group
7
7
 
8
- # Add this generator to our padrino-gen
9
8
  Padrino::Generators.add_generator(:controller, self)
10
9
 
11
- # Define the source template root
12
10
  def self.source_root; File.expand_path(File.dirname(__FILE__)); end
13
- # Defines the banner for this CLI generator
14
11
  def self.banner; "padrino-gen controller [name]"; end
15
12
 
16
- # Include related modules
17
13
  include Thor::Actions
18
14
  include Padrino::Generators::Actions
19
15
  include Padrino::Generators::Components::Actions
@@ -30,12 +26,12 @@ module Padrino
30
26
  class_option :parent, :desc => 'The parent of the controller', :aliases => '-p', :default => '', :type => :string
31
27
  class_option :provides, :desc => 'the formats provided by the controller', :aliases => '-f', :default => '', :type => :string
32
28
 
33
- # Show help if no argv given
29
+ # Show help if no ARGV given
34
30
  require_arguments!
35
31
 
32
+ ##
36
33
  # Execute controller generation
37
34
  #
38
- # @api private
39
35
  def create_controller
40
36
  self.destination_root = options[:root]
41
37
  if in_app_root?
@@ -47,7 +43,7 @@ module Padrino
47
43
  @actions = controller_actions(fields)
48
44
  @controller = name.to_s.underscore
49
45
  @layout = options[:layout] if options[:layout] && !options[:layout].empty?
50
-
46
+
51
47
  block_opts = []
52
48
  block_opts << ":parent => :#{options[:parent]}" if options[:parent] && !options[:parent].empty?
53
49
  block_opts << ":provides => [#{options[:provides]}]" if options[:provides] && !options[:provides].empty?
@@ -63,6 +59,6 @@ module Padrino
63
59
  say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
64
60
  end
65
61
  end
66
- end # Controller
67
- end # Generators
68
- end # Padrino
62
+ end
63
+ end
64
+ end
@@ -5,15 +5,11 @@ module Padrino
5
5
  #
6
6
  class Mailer < Thor::Group
7
7
 
8
- # Add this generator to our padrino-gen
9
8
  Padrino::Generators.add_generator(:mailer, self)
10
9
 
11
- # Define the source template root
12
10
  def self.source_root; File.expand_path(File.dirname(__FILE__)); end
13
- # Defines the banner for this CLI generator
14
11
  def self.banner; 'padrino-gen mailer [name]'; end
15
12
 
16
- # Include related modules
17
13
  include Thor::Actions
18
14
  include Padrino::Generators::Actions
19
15
  include Padrino::Generators::Components::Actions
@@ -27,12 +23,12 @@ module Padrino
27
23
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
28
24
  class_option :namespace, :desc => 'The name space of your padrino project', :aliases => '-n', :default => '', :type => :string
29
25
 
30
- # Show help if no argv given
26
+ # Show help if no ARGV given.
31
27
  require_arguments!
32
28
 
33
- # Execute mailer generation
29
+ ##
30
+ # Execute mailer generation.
34
31
  #
35
- # @api private
36
32
  def create_mailer
37
33
  self.destination_root = options[:root]
38
34
  if in_app_root?
@@ -42,7 +38,7 @@ module Padrino
42
38
  @project_name = options[:namespace].underscore.camelize
43
39
  @project_name = fetch_project_name(app) if @project_name.empty?
44
40
  @app_name = fetch_app_name(app)
45
- @actions = actions.map{|a| a.to_sym}
41
+ @actions = actions.map(&:to_sym)
46
42
  @short_name = name.to_s.gsub(/_mailer/i, '').underscore.downcase
47
43
  @mailer_basename = @short_name.underscore
48
44
  template "templates/mailer.rb.tt", destination_root(app, 'mailers', "#{@mailer_basename}.rb")
@@ -51,6 +47,6 @@ module Padrino
51
47
  say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
52
48
  end
53
49
  end
54
- end # Mailer
55
- end # Generators
56
- end # Padrino
50
+ end
51
+ end
52
+ end
@@ -4,16 +4,11 @@ module Padrino
4
4
  # Responsible for generating migration files for the appropriate ORM component.
5
5
  #
6
6
  class Migration < Thor::Group
7
-
8
- # Add this generator to our padrino-gen
9
7
  Padrino::Generators.add_generator(:migration, self)
10
8
 
11
- # Define the source template root
12
9
  def self.source_root; File.expand_path(File.dirname(__FILE__)); end
13
- # Defines the banner for this CLI generator
14
10
  def self.banner; "padrino-gen migration [name] [fields]"; end
15
11
 
16
- # Include related modules
17
12
  include Thor::Actions
18
13
  include Padrino::Generators::Actions
19
14
  include Padrino::Generators::Components::Actions
@@ -25,7 +20,7 @@ module Padrino
25
20
  class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
26
21
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
27
22
 
28
- # Show help if no argv given
23
+ # Show help if no ARGV given.
29
24
  require_arguments!
30
25
 
31
26
  # Creates the migration file within a Padrino project.
@@ -43,6 +38,6 @@ module Padrino
43
38
  say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
44
39
  end
45
40
  end
46
- end # Migration
47
- end # Generators
48
- end # Padrino
41
+ end
42
+ end
43
+ end
@@ -1,19 +1,14 @@
1
1
  module Padrino
2
2
  module Generators
3
3
  ##
4
- # Responsible for generating new models for the specified ORM component within a project or application.
4
+ # Responsible for generating new models for the specified ORM component.
5
5
  #
6
6
  class Model < Thor::Group
7
-
8
- # Add this generator to our padrino-gen
9
7
  Padrino::Generators.add_generator(:model, self)
10
8
 
11
- # Define the source template root
12
9
  def self.source_root; File.expand_path(File.dirname(__FILE__)); end
13
- # Defines the banner for this CLI generator
14
10
  def self.banner; "padrino-gen model [name] [fields]"; end
15
11
 
16
- # Include related modules
17
12
  include Thor::Actions
18
13
  include Padrino::Generators::Actions
19
14
  include Padrino::Generators::Components::Actions
@@ -27,12 +22,11 @@ module Padrino
27
22
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
28
23
  class_option :skip_migration, :aliases => '-s', :default => false, :type => :boolean
29
24
 
30
- # Show help if no argv given
25
+ # Show help if no ARGV given.
31
26
  require_arguments!
32
27
 
33
- # Execute the model generation
28
+ # Execute the model generation.
34
29
  #
35
- # @api private
36
30
  def create_model
37
31
  self.destination_root = options[:root]
38
32
  if in_app_root?
@@ -58,6 +52,6 @@ module Padrino
58
52
  say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
59
53
  end
60
54
  end
61
- end # Model
62
- end # Generators
63
- end # Padrino
55
+ end
56
+ end
57
+ end
@@ -7,17 +7,13 @@ module Padrino
7
7
  # Responsible for executing plugins instructions within a Padrino project.
8
8
  #
9
9
  class Plugin < Thor::Group
10
- # Defines the default URL for official padrino recipe plugins
10
+ # Defines the default URL for official padrino recipe plugins.
11
11
  PLUGIN_URL = 'https://github.com/padrino/padrino-recipes/tree/master/plugins'
12
- # Add this generator to our padrino-gen
13
12
  Padrino::Generators.add_generator(:plugin, self)
14
13
 
15
- # Define the source plugin root
16
14
  def self.source_root; File.expand_path(File.dirname(__FILE__)); end
17
- # Defines the banner for this CLI generator
18
15
  def self.banner; "padrino-gen plugin [plugin_identifier] [options]"; end
19
16
 
20
- # Include related modules
21
17
  include Thor::Actions
22
18
  include Padrino::Generators::Actions
23
19
  include Padrino::Generators::Runner
@@ -29,14 +25,15 @@ module Padrino
29
25
  class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
30
26
  class_option :list, :desc => "list available plugins", :aliases => '-l', :default => false, :type => :boolean
31
27
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
32
- # Show help if no argv given
28
+
29
+ # Show help if no ARGV given.
33
30
  require_arguments!
34
31
 
35
- # Create the Padrino Plugin
32
+ ##
33
+ # Create the Padrino Plugin.
36
34
  #
37
- # @api private
38
35
  def setup_plugin
39
- if options[:list] || plugin_file.nil? # list method ran here
36
+ if options[:list] || plugin_file.nil?
40
37
  list_plugins
41
38
  else # executing the plugin instructions
42
39
  self.destination_root = options[:root]
@@ -65,6 +62,6 @@ module Padrino
65
62
  say plugins.map { |plugin| " - #{plugin}" }.join("\n")
66
63
  end
67
64
  end
68
- end # Plugins
69
- end # Generators
70
- end # Padrino
65
+ end
66
+ end
67
+ end
@@ -7,16 +7,11 @@ module Padrino
7
7
  # Responsible for generating new Padrino projects based on the specified project components.
8
8
  #
9
9
  class Project < Thor::Group
10
-
11
- # Add this generator to our padrino-gen
12
10
  Padrino::Generators.add_generator(:project, self)
13
11
 
14
- # Define the source template root
15
12
  def self.source_root; File.expand_path(File.dirname(__FILE__)); end
16
- # Defines the banner for this CLI generator
17
13
  def self.banner; "padrino-gen project [name] [options]"; end
18
14
 
19
- # Include related modules
20
15
  include Thor::Actions
21
16
  include Padrino::Generators::Actions
22
17
  include Padrino::Generators::Runner
@@ -36,20 +31,15 @@ module Padrino
36
31
  class_option :gem, :desc => 'Generate project as a gem', :aliases => '-g', :default => false, :type => :boolean
37
32
  class_option :migration_format, :desc => 'Filename format for migrations (number, timestamp)', :default => 'number', :type => :string
38
33
 
39
- # Definitions for the available customizable components
40
- component_option :orm, 'database engine', :aliases => '-d', :choices => [:activerecord, :minirecord, :datamapper, :mongomapper, :mongoid, :sequel, :couchrest, :ohm, :mongomatic, :ripple], :default => :none
41
- component_option :test, 'testing framework', :aliases => '-t', :choices => [:rspec, :shoulda, :cucumber, :bacon, :testspec, :riot, :minitest], :default => :none
42
- component_option :mock, 'mocking library', :aliases => '-m', :choices => [:mocha, :rr], :default => :none
43
- component_option :script, 'javascript library', :aliases => '-s', :choices => [:jquery, :prototype, :rightjs, :mootools, :extcore, :dojo], :default => :none
44
- component_option :renderer, 'template engine', :aliases => '-e', :choices => [:haml, :erb, :liquid, :slim], :default => :slim
45
- component_option :stylesheet, 'stylesheet engine', :aliases => '-c', :choices => [:less, :sass, :compass, :scss], :default => :none
34
+ # Definitions for the available customizable components.
35
+ defines_component_options
46
36
 
47
- # Show help if no argv given
37
+ # Show help if no ARGV given.
48
38
  require_arguments!
49
39
 
50
- # Copies over the Padrino base application App
40
+ ##
41
+ # Copies over the Padrino base application app.
51
42
  #
52
- # @api private
53
43
  def setup_project
54
44
  valid_constant? name
55
45
  app = (options[:app] || "App")
@@ -78,9 +68,9 @@ module Padrino
78
68
  end
79
69
  end
80
70
 
81
- # For each component, retrieve a valid choice and then execute the associated generator
71
+ ##
72
+ # For each component, retrieve a valid choice and then execute the associated generator.
82
73
  #
83
- # @api private
84
74
  def setup_components
85
75
  return if options[:template]
86
76
  @_components = options.dup.slice(*self.class.component_types)
@@ -93,18 +83,18 @@ module Padrino
93
83
  store_component_choice(:migration_format, options[:migration_format])
94
84
  end
95
85
 
96
- # Bundle all required components using bundler and Gemfile
86
+ ##
87
+ # Bundle all required components using bundler and Gemfile.
97
88
  #
98
- # @api private
99
89
  def bundle_dependencies
100
90
  if options[:bundle]
101
91
  run_bundler
102
92
  end
103
93
  end
104
94
 
105
- # Finish message
95
+ ##
96
+ # Finish message.
106
97
  #
107
- # @api private
108
98
  def finish_message
109
99
  say
110
100
  say '=' * 65, :green
@@ -116,21 +106,21 @@ module Padrino
116
106
  say
117
107
  end
118
108
 
119
- # Returns the git author name config or a fill-in value
109
+ ##
110
+ # Returns the git author name config or a fill-in value.
120
111
  #
121
- # @api private
122
112
  def git_author_name
123
113
  git_author_name = `git config user.name`.chomp rescue ''
124
114
  git_author_name.empty? ? "TODO: Write your name" : git_author_name
125
115
  end
126
116
 
127
- # Returns the git author email config or a fill-in value
117
+ ##
118
+ # Returns the git author email config or a fill-in value.
128
119
  #
129
- # @api private
130
120
  def git_author_email
131
121
  git_author_email = `git config user.email`.chomp rescue ''
132
122
  git_author_email.empty? ? "TODO: Write your email address" : git_author_email
133
123
  end
134
- end # Project
135
- end # Generators
136
- end # Padrino
124
+ end
125
+ end
126
+ end