Sha256: 2d3e44d3c531d9c5d680d2a7ee94264a49cd67238804baf44e0b6e8fed160fd3

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'rails/generators/resource_helpers'
require_relative 'controller_template_base'

module InertiaRails
  module Generators
    class ScaffoldTemplateBase < ControllerTemplateBase
      include Rails::Generators::ResourceHelpers

      remove_argument :actions

      argument :attributes, type: :array, default: [], banner: 'field:type field:type'

      def copy_view_files
        available_views.each do |view|
          template "#{options.frontend_framework}/#{view}.#{template_extension}",
                   File.join(base_path, "#{view}.#{extension}")
        end

        template "#{options.frontend_framework}/#{partial_name}.#{template_extension}",
                 File.join(base_path, "#{inertia_component_name}.#{extension}")

        template "#{options.frontend_framework}/types.ts", File.join(base_path, 'types.ts') if typescript?
      end

      private

      def template_extension
        return extension unless typescript?
        return 'tsx' if options.frontend_framework == 'react'

        "ts.#{extension}"
      end

      def available_views
        %w[Index Edit Show New Form]
      end

      def partial_name
        'One'
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
inertia_rails-3.5.0 lib/inertia_rails/generators/scaffold_template_base.rb