Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/inertia_rails/generators/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ module InertiaRails
module Generators
module Helper
class << self
def guess_the_default_framework(package_json_path = Rails.root.join('package.json'))
DEFAULT_PACKAGE_PATH = Rails.root.join('package.json')

def guess_the_default_framework(package_json_path = DEFAULT_PACKAGE_PATH)
package_json = JSON.parse(package_json_path.read)
dependencies = package_json['dependencies'] || {}

Expand All @@ -25,8 +27,8 @@ def guess_typescript
Rails.root.join('tsconfig.json').exist?
end

def guess_inertia_template
if Rails.root.join('tailwind.config.js').exist? || Rails.root.join('tailwind.config.ts').exist?
def guess_inertia_template(package_json_path = DEFAULT_PACKAGE_PATH)
if package_json_path.read.include?('"tailwindcss"')
'inertia_tw_templates'
else
'inertia_templates'
Expand Down
5 changes: 5 additions & 0 deletions spec/fixtures/package_json_files/tailwind_package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"tailwindcss": "4.0.0"
}
}
15 changes: 15 additions & 0 deletions spec/generators/generators_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,19 @@
end
end
end

describe '#guess_inertia_template' do
let(:package_json_path) { Pathname.new(File.expand_path("spec/fixtures/package_json_files/#{fixture_file_name}", Dir.pwd)) }

shared_examples 'template detection' do |file_name, expected_template|
let(:fixture_file_name) { file_name }

it "returns #{expected_template.inspect} when inspect \"#{file_name}\"" do
expect(described_class.guess_inertia_template(package_json_path)).to eq(expected_template)
end
end

it_behaves_like 'template detection', 'tailwind_package.json', 'inertia_tw_templates'
it_behaves_like 'template detection', 'empty_package.json', 'inertia_templates'
end
end