# frozen_string_literal: true require "rails/engine" require "tailwind_merge" module Ariadne # The Ariadne gem is a collection of ViewComponents that can be used to build # accessible, responsive, and consistent UIs for Yetto. module ViewComponents mattr_accessor :tailwind_merger # :nodoc: class Engine < ::Rails::Engine isolate_namespace Ariadne::ViewComponents config.autoload_paths = ["#{root}/lib"] config.eager_load_paths = ["#{root}/app/components", "#{root}/app/forms", "#{root}/app/helpers", "#{root}/app/lib"] config.ariadne_view_components = ActiveSupport::OrderedOptions.new config.ariadne_view_components.raise_on_invalid_options = true config.ariadne_view_components.silence_deprecations = false config.ariadne_view_components.silence_warnings = false config.ariadne_view_components.validate_class_names = true config.ariadne_view_components.raise_on_invalid_aria = true initializer "ariadne_view_components.assets" do |app| app.config.assets.precompile += ["ariadne_view_components"] if app.config.respond_to?(:assets) end initializer "ariadne_view_components.eager_load_actions" do ActiveSupport.on_load(:after_initialize) do if Rails.application.config.eager_load Ariadne::Forms::Base.compile! Ariadne::Forms::Base.descendants.each(&:compile!) Ariadne::Form::BaseComponent.descendants.each(&:compile!) end end end initializer "ariadne.forms.helpers" do ActiveSupport.on_load(:action_controller_base) do begin require "ariadne/form_helper" rescue LoadError # rubocop:disable Lint/SuppressedException end helper Ariadne::FormHelper # make ariadne_form_with available to view components also ::ViewComponent::Base.prepend(Ariadne::FormHelper) end end initializer "ariadne_view_components.zeitwerk_ignore" do Rails.autoloaders.each do |autoloader| autoloader.ignore(Engine.root.join("lib", "ariadne", "view_components", "linters.rb")) autoloader.ignore(Engine.root.join("lib", "ariadne", "view_components", "linters", "**", "*.rb")) autoloader.ignore(Engine.root.join("lib", "ariadne", "view_components", "statuses.rb")) end end initializer "i18n.load_path" do config.i18n.load_path.concat(Dir[Engine.root.join.join("app", "components", "**", "*.yml")]) end config.after_initialize do |_app| Ariadne::ViewComponents.tailwind_merger = TailwindMerge::Merger.new(config: { prefix: "ariadne-" }) end end end end