# frozen_string_literal: true module ApplicationHelper include Pagy::Frontend def page_title return content_for(:page_title) if content_for?(:page_title) return site_title if defined?(site_title) "Unknown" end def domain return content_for(:domain) if content_for?(:domain) return site_domain if defined?(site_domain) "unknown" end def color return content_for(:color) if content_for?(:color) return site_color if defined?(site_color) "#2C2F33" end def with_params(**) params.except(:controller, :action, :index).merge(**).permit! end def without_search(*args) p = params.except(:controller, :action, :index, :search) return p.permit! if args.empty? p.merge(search: params.fetch(:search, {}).except(*args)).permit! end def if_active(css, path:) return css if request.path == path "" end def time_tag(content, time) datetime = time.strftime("%Y-%m-%dT%H:%M%:z") tag.time(content || datetime, datetime: datetime, title: time.to_fs) end def compact_time(time) time_tag(time.strftime("%Y-%m-%d %H:%M:%S"), time) end def error_messages_for(instance_name) instance = instance_variable_get("@#{instance_name}") if instance&.errors&.any? %(
Error: #{instance.__send__(:errors).full_messages.join(', ')}
).html_safe else "" end end end