Websites/app/helpers/application_helper.rb

58 lines
1.4 KiB
Ruby
Raw Permalink Normal View History

2024-05-03 03:04:43 +00:00
# frozen_string_literal: true
module ApplicationHelper
include Pagy::Frontend
2024-05-03 03:04:43 +00:00
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?
%(<div class="error-messages ui-state-error ui-corner-all"><strong>Error</strong>: #{instance.__send__(:errors).full_messages.join(', ')}</div>).html_safe
else
""
end
end
2024-05-03 03:04:43 +00:00
end