From de259a37e78ae7768bbf2eca421880fc389d535a Mon Sep 17 00:00:00 2001 From: Xavier MALPARTY Date: Tue, 19 Dec 2023 14:07:57 +0700 Subject: [PATCH] Add tests to the CRUD layout --- .../app/views/layouts/application.html.slim.tt | 2 +- .../spec/variants/web/app/template_spec.rb | 6 +----- .template/variants/web/app/template.rb | 18 +++++++++++++----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.template/addons/crud/app/views/layouts/application.html.slim.tt b/.template/addons/crud/app/views/layouts/application.html.slim.tt index f51a4f853..b966bd8f4 100644 --- a/.template/addons/crud/app/views/layouts/application.html.slim.tt +++ b/.template/addons/crud/app/views/layouts/application.html.slim.tt @@ -1,5 +1,5 @@ doctype html -html lang= I18n.locale +html lang=I18n.locale head meta charset="utf-8" meta name="viewport" content="width=device-width, initial-scale=1.0" diff --git a/.template/spec/variants/web/app/template_spec.rb b/.template/spec/variants/web/app/template_spec.rb index d296d6dbc..6760951c8 100644 --- a/.template/spec/variants/web/app/template_spec.rb +++ b/.template/spec/variants/web/app/template_spec.rb @@ -22,7 +22,7 @@ end it 'loads the javascript entry file in the layout' do - expect(file('app/views/layouts/application.html.erb')).to contain('<%= javascript_include_tag "application"') + expect(file('app/views/layouts/application.html.slim')).to contain('javascript_include_tag "application"') end it 'imports necessary modules' do @@ -103,9 +103,5 @@ it 'includes the localization concern in the application controller' do expect(file('app/controllers/application_controller.rb')).to contain('include Localization') end - - it 'modifies the html tag to attach the current locale' do - expect(file('app/views/layouts/application.html.erb')).to contain("") - end end end diff --git a/.template/variants/web/app/template.rb b/.template/variants/web/app/template.rb index ab983770f..108c66320 100644 --- a/.template/variants/web/app/template.rb +++ b/.template/variants/web/app/template.rb @@ -3,15 +3,22 @@ # Javascript directory 'app/javascript' -if File.exist?('app/views/layouts/application.html.erb') - insert_into_file 'app/views/layouts/application.html.erb', before: %r{} do +erb_layout_file = 'app/views/layouts/application.html.erb' +slim_layout_file = 'app/views/layouts/application.html.slim' +layout_file = nil + +layout_file = erb_layout_file if File.exist?(erb_layout_file) +layout_file = slim_layout_file if File.exist?(slim_layout_file) + +if layout_file + insert_into_file layout_file, before: %r{} do <<~ERB.indent(2) <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %> ERB end else @template_errors.add <<~ERROR - Cannot include javascript into `app/views/layouts/application.html.erb` + Cannot include javascript into `app/views/layouts/application.html.{erb|slim}` Content: <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %> ERROR end @@ -33,11 +40,12 @@ RUBY end -if File.exist?('app/views/layouts/application.html.erb') +if erb_layout_file gsub_file 'app/views/layouts/application.html.erb', // do "" end -else +# The slim layout (CRUD addon) already has the lang attribute +elsif slim_layout_file.blank? @template_errors.add <<~ERROR Cannot insert the lang attribute into html tag into `app/views/layouts/application.html.erb` Content: