diff options
Diffstat (limited to 'railties/lib/rails/generators')
9 files changed, 67 insertions, 16 deletions
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index edd1e8cbdf..9b9ae72e18 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -261,7 +261,14 @@ module Rails end def run_bundle - bundle_command('install') unless options[:skip_gemfile] || options[:skip_bundle] || options[:pretend] + command = "install --binstubs" + command << " --shebang ruby-local-exec" if detect_ruby_local_exec + + bundle_command(command) unless options[:skip_gemfile] || options[:skip_bundle] || options[:pretend] + end + + def detect_ruby_local_exec + ENV["PATH"].split(":").find { |path| File.file?(File.join(path, "ruby-local-exec")) } end def empty_directory_with_keep_file(destination, config = {}) diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index 593d2acfc7..68df1d1ec8 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -84,8 +84,4 @@ # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new - - # Default the production mode queue to an synchronous queue. You will probably - # want to replace this with an out-of-process queueing solution. - # config.queue = ActiveSupport::SynchronousQueue.new end diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt index a5ef0cd9cd..3c9c787948 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt @@ -33,7 +33,4 @@ # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - - # Use the synchronous queue to run jobs immediately. - config.queue = ActiveSupport::SynchronousQueue.new end diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore index 52abb32479..25a742dff0 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore +++ b/railties/lib/rails/generators/rails/app/templates/gitignore @@ -4,7 +4,7 @@ # or operating system, you probably want to add a global ignore instead: # git config --global core.excludesfile '~/.gitignore_global' -# Ignore bundler config +# Ignore bundler config. /.bundle # Ignore the default SQLite database. diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb index 60d202c5ef..dd636ed3cf 100644 --- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb @@ -9,6 +9,15 @@ module Rails class_option :stylesheets, type: :boolean, desc: "Generate Stylesheets" class_option :stylesheet_engine, desc: "Engine for Stylesheets" + class_option :html, type: :boolean, default: true, + desc: "Generate a scaffold with HTML output" + + def handle_skip + if !options[:html] || !options[:stylesheets] + @options = @options.merge(stylesheet_engine: false) + end + end + hook_for :scaffold_controller, required: true hook_for :assets do |assets| @@ -16,7 +25,9 @@ module Rails end hook_for :stylesheet_engine do |stylesheet_engine| - invoke stylesheet_engine, [controller_name] if options[:stylesheets] && behavior == :invoke + if behavior == :invoke + invoke stylesheet_engine, [controller_name] + end end end end diff --git a/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb b/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb index 4f36b612ae..32fa54a362 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +++ b/railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb @@ -10,8 +10,17 @@ module Rails class_option :orm, banner: "NAME", type: :string, required: true, desc: "ORM to generate the controller for" + class_option :html, type: :boolean, default: true, + desc: "Generate a scaffold with HTML output" + argument :attributes, type: :array, default: [], banner: "field:type field:type" + def handle_skip + unless options[:html] + @options = @options.merge(template_engine: false, helper: false) + end + end + def create_controller_files template "controller.rb", File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb") end diff --git a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb index 4d08b01e60..4baad85e9e 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +++ b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb @@ -12,7 +12,9 @@ class <%= controller_class_name %>Controller < ApplicationController @<%= plural_table_name %> = <%= orm_class.all(class_name) %> respond_to do |format| + <%- if options[:html] -%> format.html # index.html.erb + <%- end -%> format.json { render json: <%= "@#{plural_table_name}" %> } end end @@ -21,11 +23,14 @@ class <%= controller_class_name %>Controller < ApplicationController # GET <%= route_url %>/1.json def show respond_to do |format| + <%- if options[:html] -%> format.html # show.html.erb + <%- end -%> format.json { render json: <%= "@#{singular_table_name}" %> } end end + <%- if options[:html] -%> # GET <%= route_url %>/new # GET <%= route_url %>/new.json def new @@ -40,6 +45,7 @@ class <%= controller_class_name %>Controller < ApplicationController # GET <%= route_url %>/1/edit def edit end + <%- end -%> # POST <%= route_url %> # POST <%= route_url %>.json @@ -48,10 +54,14 @@ class <%= controller_class_name %>Controller < ApplicationController respond_to do |format| if @<%= orm_instance.save %> + <%- if options[:html] -%> format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %> } + <%- end -%> format.json { render json: <%= "@#{singular_table_name}" %>, status: :created, location: <%= "@#{singular_table_name}" %> } else + <%- if options[:html] -%> format.html { render action: "new" } + <%- end -%> format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity } end end @@ -62,10 +72,14 @@ class <%= controller_class_name %>Controller < ApplicationController def update respond_to do |format| if @<%= orm_instance.update_attributes("#{singular_table_name}_params") %> + <%- if options[:html] -%> format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> } + <%- end -%> format.json { head :no_content } else + <%- if options[:html] -%> format.html { render action: "edit" } + <%- end -%> format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity } end end @@ -77,7 +91,9 @@ class <%= controller_class_name %>Controller < ApplicationController @<%= orm_instance.destroy %> respond_to do |format| + <%- if options[:html] -%> format.html { redirect_to <%= index_helper %>_url } + <%- end -%> format.json { head :no_content } end end @@ -88,8 +104,11 @@ class <%= controller_class_name %>Controller < ApplicationController @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %> end - # Use this method to whitelist the permissible parameters. Example: params.require(:person).permit(:name, :age) - # Also, you can specialize this method with per-user checking of permissible attributes. + # Use this method to whitelist the permissible parameters. Example: + # params.require(:person).permit(:name, :age) + # + # Also, you can specialize this method with per-user checking of permissible + # attributes. def <%= "#{singular_table_name}_params" %> <%- if attributes_names.empty? -%> params[<%= ":#{singular_table_name}" %>] diff --git a/railties/lib/rails/generators/test_unit/model/model_generator.rb b/railties/lib/rails/generators/test_unit/model/model_generator.rb index 2801749ffe..2826a3ffa1 100644 --- a/railties/lib/rails/generators/test_unit/model/model_generator.rb +++ b/railties/lib/rails/generators/test_unit/model/model_generator.rb @@ -3,6 +3,9 @@ require 'rails/generators/test_unit' module TestUnit # :nodoc: module Generators # :nodoc: class ModelGenerator < Base # :nodoc: + + RESERVED_YAML_KEYWORDS = %w(y yes n no true false on off null) + argument :attributes, type: :array, default: [], banner: "field:type field:type" class_option :fixture, type: :boolean @@ -19,6 +22,15 @@ module TestUnit # :nodoc: template 'fixtures.yml', File.join('test/fixtures', class_path, "#{plural_file_name}.yml") end end + + private + def yaml_key_value(key, value) + if RESERVED_YAML_KEYWORDS.include?(key.downcase) + "'#{key}': #{value}" + else + "#{key}: #{value}" + end + end end end end diff --git a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml index 7625ff975c..c9d505c84a 100644 --- a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml +++ b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml @@ -3,17 +3,17 @@ <% unless attributes.empty? -%> one: <% attributes.each do |attribute| -%> - <%= attribute.column_name %>: <%= attribute.default %> + <%= yaml_key_value(attribute.column_name, attribute.default) %> <%- if attribute.polymorphic? -%> - <%= "#{attribute.name}_type: #{attribute.human_name}" %> + <%= yaml_key_value("#{attribute.name}_type", attribute.human_name) %> <%- end -%> <% end -%> two: <% attributes.each do |attribute| -%> - <%= attribute.column_name %>: <%= attribute.default %> + <%= yaml_key_value(attribute.column_name, attribute.default) %> <%- if attribute.polymorphic? -%> - <%= "#{attribute.name}_type: #{attribute.human_name}" %> + <%= yaml_key_value("#{attribute.name}_type", attribute.human_name) %> <%- end -%> <% end -%> <% else -%> |