Websites/app/helpers/application_helper.rb
Donovan Daniels b1c702e3cd
Add image management ui
poorly tested but it worked well enough, I'm sure I'll be patching bugs over the next few weeks
Also remove turbo because it sucks
Also changed the way we handle hosts in dev
2024-05-06 03:25:17 -05:00

58 lines
1.4 KiB
Ruby

# 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?
%(<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
end