mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #23631 from y-yagi/generate_mailer_views_in_api
generate mailer views in Rails API
This commit is contained in:
commit
cfd61919da
4 changed files with 20 additions and 4 deletions
|
@ -105,7 +105,7 @@ module Rails
|
|||
|
||||
# Configure generators for API only applications. It basically hides
|
||||
# everything that is usually browser related, such as assets and session
|
||||
# migration generators, and completely disable views, helpers and assets
|
||||
# migration generators, and completely disable helpers and assets
|
||||
# so generators such as scaffold won't create them.
|
||||
def self.api_only!
|
||||
hide_namespaces "assets", "helper", "css", "js"
|
||||
|
@ -116,6 +116,10 @@ module Rails
|
|||
helper: false,
|
||||
template_engine: nil
|
||||
)
|
||||
|
||||
if ARGV.first == 'mailer'
|
||||
options[:rails].merge!(template_engine: :erb)
|
||||
end
|
||||
end
|
||||
|
||||
# Remove the color from output.
|
||||
|
|
|
@ -276,9 +276,9 @@ module Rails
|
|||
end
|
||||
end
|
||||
|
||||
def delete_app_views_if_api_option
|
||||
def delete_application_layout_file_if_api_option
|
||||
if options[:api]
|
||||
remove_dir 'app/views'
|
||||
remove_file 'app/views/layouts/application.html.erb'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -160,5 +160,15 @@ module ApplicationTests
|
|||
assert Rails::Generators.options[:rails][:helper]
|
||||
assert_equal :my_template, Rails::Generators.options[:rails][:template_engine]
|
||||
end
|
||||
|
||||
test "api only generator generate mailer views" do
|
||||
add_to_config <<-RUBY
|
||||
config.api_only = true
|
||||
RUBY
|
||||
|
||||
FileUtils.cd(rails_root){ `bin/rails generate mailer notifier foo` }
|
||||
assert File.exist?(File.join(rails_root, "app/views/notifier_mailer/foo.text.erb"))
|
||||
assert File.exist?(File.join(rails_root, "app/views/notifier_mailer/foo.html.erb"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -73,6 +73,8 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase
|
|||
app/controllers
|
||||
app/mailers
|
||||
app/models
|
||||
app/views/layouts/mailer.html.erb
|
||||
app/views/layouts/mailer.text.erb
|
||||
config/environments
|
||||
config/initializers
|
||||
config/locales
|
||||
|
@ -94,7 +96,7 @@ class ApiAppGeneratorTest < Rails::Generators::TestCase
|
|||
def skipped_files
|
||||
%w(app/assets
|
||||
app/helpers
|
||||
app/views
|
||||
app/views/layouts/application.html.erb
|
||||
config/initializers/assets.rb
|
||||
config/initializers/cookies_serializer.rb
|
||||
config/initializers/session_store.rb
|
||||
|
|
Loading…
Reference in a new issue