File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed
lib/inertia_rails/generators
fixtures/package_json_files Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,9 @@ module InertiaRails
44 module Generators
55 module Helper
66 class << self
7- def guess_the_default_framework ( package_json_path = Rails . root . join ( 'package.json' ) )
7+ DEFAULT_PACKAGE_PATH = Rails . root . join ( 'package.json' )
8+
9+ def guess_the_default_framework ( package_json_path = DEFAULT_PACKAGE_PATH )
810 package_json = JSON . parse ( package_json_path . read )
911 dependencies = package_json [ 'dependencies' ] || { }
1012
@@ -25,8 +27,8 @@ def guess_typescript
2527 Rails . root . join ( 'tsconfig.json' ) . exist?
2628 end
2729
28- def guess_inertia_template
29- if Rails . root . join ( 'tailwind.config.js' ) . exist? || Rails . root . join ( 'tailwind.config.ts' ) . exist?
30+ def guess_inertia_template ( package_json_path = DEFAULT_PACKAGE_PATH )
31+ if package_json_path . read . include? ( '"tailwindcss"' )
3032 'inertia_tw_templates'
3133 else
3234 'inertia_templates'
Original file line number Diff line number Diff line change 1+ {
2+ "devDependencies" : {
3+ "tailwindcss" : " 4.0.0"
4+ }
5+ }
Original file line number Diff line number Diff line change 3434 end
3535 end
3636 end
37+
38+ describe '#guess_inertia_template' do
39+ let ( :package_json_path ) { Pathname . new ( File . expand_path ( "spec/fixtures/package_json_files/#{ fixture_file_name } " , Dir . pwd ) ) }
40+
41+ shared_examples 'template detection' do |file_name , expected_template |
42+ let ( :fixture_file_name ) { file_name }
43+
44+ it "returns #{ expected_template . inspect } when inspect \" #{ file_name } \" " do
45+ expect ( described_class . guess_inertia_template ( package_json_path ) ) . to eq ( expected_template )
46+ end
47+ end
48+
49+ it_behaves_like 'template detection' , 'tailwind_package.json' , 'inertia_tw_templates'
50+ it_behaves_like 'template detection' , 'empty_package.json' , 'inertia_templates'
51+ end
3752end
You can’t perform that action at this time.
0 commit comments