# frozen_string_literal: true require "rails/engine" require "yattho/classify/utilities" module Yattho module ViewComponents # :nodoc: class Engine < ::Rails::Engine isolate_namespace Yattho::ViewComponents config.autoload_paths = %W[ #{root}/lib ] config.eager_load_paths = %W[ #{root}/app/components #{root}/app/forms #{root}/app/helpers #{root}/app/lib ] config.yattho_view_components = ActiveSupport::OrderedOptions.new config.yattho_view_components.raise_on_invalid_options = false config.yattho_view_components.silence_deprecations = false config.yattho_view_components.validate_class_names = !Rails.env.production? config.yattho_view_components.raise_on_invalid_aria = false initializer "yattho_view_components.assets" do |app| app.config.assets.precompile += %w[yattho_view_components] if app.config.respond_to?(:assets) end initializer "yattho.eager_load_actions" do ActiveSupport.on_load(:after_initialize) do if Rails.application.config.eager_load Yattho::Forms::Base.compile! Yattho::Forms::Base.descendants.each(&:compile!) Yattho::Forms::BaseComponent.descendants.each(&:compile!) Yattho::Octicon::Cache.preload! end end end initializer "yattho.forms.helpers" do ActiveSupport.on_load :action_controller do require "yattho/form_helper" helper Yattho::FormHelper # make yattho_form_with available to view components also ViewComponent::Base.prepend(Yattho::FormHelper) end end initializer "yattho_view_components.zeitwerk_ignore" do Rails.autoloaders.each do |autoloader| autoloader.ignore(Engine.root.join("lib", "yattho", "view_components", "linters.rb")) autoloader.ignore(Engine.root.join("lib", "yattho", "view_components", "linters", "**", "*.rb")) autoloader.ignore(Engine.root.join("lib", "yattho", "view_components", "statuses.rb")) autoloader.ignore(Engine.root.join("lib", "yattho", "view_components", "audited.rb")) end end config.after_initialize do |app| ::Yattho::Classify::Utilities.validate_class_names = app.config.yattho_view_components.delete(:validate_class_names) end end end end