Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 0 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 3.0
NewCops: enable
Expand Down
210 changes: 0 additions & 210 deletions .rubocop_todo.yml

This file was deleted.

2 changes: 2 additions & 0 deletions app/controllers/inertia_rails/static_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module InertiaRails
class StaticController < InertiaRails.configuration.parent_controller.constantize
def static
Expand Down
17 changes: 9 additions & 8 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
Pathname.new(__FILE__).realpath)

require "rubygems"
require "bundler/setup"
require "rails/all"
require "inertia_rails"
require 'rubygems'
require 'bundler/setup'
require 'rails/all'
require 'inertia_rails'

require "irb"
require 'irb'
IRB.start(__FILE__)
3 changes: 2 additions & 1 deletion bin/generate_scaffold_example
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ Dir.chdir(app_dir) do
system("bin/rails g inertia:install --no-interactive --force --vite #{generator_args} --verbose", exception: true)

# Generate a scaffold
system('bin/rails g inertia:scaffold user name email admin:boolean password:digest avatar:attachment', exception: true)
system('bin/rails g inertia:scaffold user name email admin:boolean password:digest avatar:attachment',
exception: true)
system('bin/rails g inertia:scaffold post content:text published_at:date gallery:attachments', exception: true)
system('bin/rails db:migrate', exception: true)

Expand Down
11 changes: 8 additions & 3 deletions lib/generators/inertia/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ def install_typescript
add_dependencies(*FRAMEWORKS[framework]['packages_ts'])

say 'Copying adding scripts to package.json'
run 'npm pkg set scripts.check="svelte-check --tsconfig ./tsconfig.json && tsc -p tsconfig.node.json"' if svelte?
run 'npm pkg set scripts.check="vue-tsc -p tsconfig.app.json && tsc -p tsconfig.node.json"' if framework == 'vue'
if svelte?
run 'npm pkg set scripts.check="svelte-check --tsconfig ./tsconfig.json && tsc -p tsconfig.node.json"'
end
if framework == 'vue'
run 'npm pkg set scripts.check="vue-tsc -p tsconfig.app.json && tsc -p tsconfig.node.json"'
end
run 'npm pkg set scripts.check="tsc -p tsconfig.app.json && tsc -p tsconfig.node.json"' if framework == 'react'
end

Expand Down Expand Up @@ -262,8 +266,9 @@ def vite_tag
end

def inertia_resolved_version
package = "@inertiajs/core@#{options[:inertia_version]}"
@inertia_resolved_version ||= Gem::Version.new(
`npm show @inertiajs/core@#{options[:inertia_version]} version --json | tail -n2 | head -n1 | tr -d '", '`.strip
`npm show #{package} version --json | tail -n2 | head -n1 | tr -d '", '`.strip
)
end

Expand Down
3 changes: 2 additions & 1 deletion lib/inertia_rails/action_filter.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# frozen_string_literal: true

#
# Based on AbstractController::Callbacks::ActionFilter
# https://github.com/rails/rails/blob/v7.2.0/actionpack/lib/abstract_controller/callbacks.rb#L39
module InertiaRails
class ActionFilter
def initialize(conditional_key, actions)
@conditional_key = conditional_key
@actions = Array(actions).map(&:to_s).to_set
@actions = Array(actions).to_set(&:to_s)
end

def match?(controller)
Expand Down
35 changes: 20 additions & 15 deletions lib/inertia_rails/controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require_relative "inertia_rails"
require_relative "helper"
require_relative "action_filter"
require_relative "meta_tag_builder"
# frozen_string_literal: true

require_relative 'inertia_rails'
require_relative 'helper'
require_relative 'action_filter'
require_relative 'meta_tag_builder'

module InertiaRails
module Controller
Expand All @@ -21,8 +23,8 @@ def inertia_share(hash = nil, **props, &block)
return push_to_inertia_share(**(hash || props), &block) if options.empty?

push_to_inertia_share do
next unless options[:if].all? { |filter| instance_exec(&filter) } if options[:if]
next unless options[:unless].none? { |filter| instance_exec(&filter) } if options[:unless]
next if options[:if] && !options[:if].all? { |filter| instance_exec(&filter) }
next if options[:unless]&.any? { |filter| instance_exec(&filter) }

next hash unless block

Expand Down Expand Up @@ -81,7 +83,9 @@ def extract_inertia_share_options(props)
return options if options.empty?

if props.except(:if, :unless, :only, :except).any?
raise ArgumentError, "You must not mix shared data and [:if, :unless, :only, :except] options, pass data as a hash or a block."
raise ArgumentError,
'You must not mix shared data and [:if, :unless, :only, :except] options, ' \
'pass data as a hash or a block.'
end

transform_inertia_share_option(options, :only, :if)
Expand Down Expand Up @@ -110,7 +114,7 @@ def filter_to_proc(filter)
when InertiaRails::ActionFilter
-> { filter.match?(self) }
else
raise ArgumentError, "You must pass a symbol or a proc as a filter."
raise ArgumentError, 'You must pass a symbol or a proc as a filter.'
end
end
end
Expand All @@ -136,6 +140,7 @@ def inertia_meta

def inertia_view_assigns
return {} unless @_inertia_instance_props

view_assigns.except(*@_inertia_skip_props)
end

Expand All @@ -152,22 +157,22 @@ def inertia_shared_data
else
if inertia_configuration.always_include_errors_hash.nil?
InertiaRails.deprecator.warn(
"To comply with the Inertia protocol, an empty errors hash `{errors: {}}` " \
"will be included to all responses by default starting with InertiaRails 4.0. " \
"To opt-in now, set `config.always_include_errors_hash = true`. " \
"To disable this warning, set it to `false`."
'To comply with the Inertia protocol, an empty errors hash `{errors: {}}` ' \
'will be included to all responses by default starting with InertiaRails 4.0. ' \
'To opt-in now, set `config.always_include_errors_hash = true`. ' \
'To disable this warning, set it to `false`.'
)
end
{}
end

self.class._inertia_shared_data.filter_map { |shared_data|
self.class._inertia_shared_data.filter_map do |shared_data|
if shared_data.respond_to?(:call)
instance_exec(&shared_data)
else
shared_data
end
}.reduce(initial_data, &:merge)
end.reduce(initial_data, &:merge)
end

def inertia_location(url)
Expand All @@ -183,7 +188,7 @@ def capture_inertia_session_options(options)
session[:inertia_errors] = inertia_errors.to_hash
else
InertiaRails.deprecator.warn(
"Object passed to `inertia: { errors: ... }` must respond to `to_hash`. Pass a hash-like object instead."
'Object passed to `inertia: { errors: ... }` must respond to `to_hash`. Pass a hash-like object instead.'
)
session[:inertia_errors] = inertia_errors
end
Expand Down
Loading