More explicit initializer for rails 7 compatibility
This commit is contained in:
+15
-2
@@ -13,15 +13,28 @@ require 'tinymce-rails'
|
||||
module Cmtool
|
||||
class Engine < ::Rails::Engine
|
||||
isolate_namespace Cmtool
|
||||
initializer "cmtool.build_menu" do
|
||||
initializer 'cmtool.build_menu', after: 'load_config_initializers' do |app|
|
||||
require 'email_validator'
|
||||
require 'bourbon'
|
||||
#require 'bourbon'
|
||||
require 'slim-rails'
|
||||
require 'paperclip'
|
||||
require 'devise'
|
||||
require 'devise_simply_stored'
|
||||
require 'jquery-rails'
|
||||
require 'tinymce-rails'
|
||||
|
||||
require 'page' # app/models/page.rb
|
||||
require 'user' # app/models/user.rb
|
||||
require 'cmtool/yml_file'
|
||||
require 'cmtool/keyword'
|
||||
require 'cmtool/news'
|
||||
require 'cmtool/faq'
|
||||
require 'cmtool/quote'
|
||||
require 'cmtool/contact_form'
|
||||
require 'cmtool/newsletter_subscription'
|
||||
require 'cmtool/image'
|
||||
require 'cmtool/directory'
|
||||
|
||||
Cmtool::Menu.register do
|
||||
group label: :site do
|
||||
title t('cmtool.menu.site.title')
|
||||
|
||||
@@ -1,67 +1,68 @@
|
||||
module Cmtool
|
||||
module Includes
|
||||
module PagesController
|
||||
extend ActiveSupport::Concern
|
||||
def home
|
||||
page_name = "home"
|
||||
@page = find_page(page_name)
|
||||
@sub_pages = @page.children.select{|child| child.in_menu.present? }
|
||||
render template: "pages/#{page_name}", layout: @page.layout.presence || ::Page.layouts.first.to_s, formats: [:html]
|
||||
module Includes
|
||||
module PagesController
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def home
|
||||
page_name = 'home'
|
||||
@page = find_page(page_name)
|
||||
@sub_pages = @page.children.select{|child| child.in_menu.present? }
|
||||
render template: "pages/#{page_name}", layout: @page.layout.presence || ::Page.layouts.first.to_s, formats: [:html]
|
||||
end
|
||||
|
||||
# General catcher for pages
|
||||
def show
|
||||
@page = ::Page.find_by_name_and_locale(params[:name], I18n.locale.to_s)
|
||||
not_found and return unless @page
|
||||
|
||||
@sub_pages = [@page] + @page.children.select{|child| child.in_menu.present? }
|
||||
template = "pages/#{@page.name}"
|
||||
if template_exists?(template)
|
||||
render template: template, formats: [:html], layout: @page.layout.presence || ::Page.layouts.first
|
||||
return
|
||||
else
|
||||
render formats: [:html], layout: @page.layout.presence || ::Page.layouts.first
|
||||
end
|
||||
end
|
||||
|
||||
# General catcher for pages
|
||||
def show
|
||||
@page = ::Page.find_by_name_and_locale(params[:name], I18n.locale.to_s)
|
||||
not_found and return unless @page
|
||||
|
||||
@sub_pages = [@page] + @page.children.select{|child| child.in_menu.present? }
|
||||
template = "pages/#{@page.name}"
|
||||
if template_exists?(template)
|
||||
render template: template, formats: [:html], layout: @page.layout.presence || ::Page.layouts.first
|
||||
return
|
||||
else
|
||||
render formats: [:html], layout: @page.layout.presence || ::Page.layouts.first
|
||||
end
|
||||
def not_found
|
||||
@page = ::Page.find_by_name_and_locale('404', I18n.locale.to_s) || ::Page.new(name: '404', body: "404 Page Not Found")
|
||||
@sub_pages = []
|
||||
page_name_extension = params[:name].to_s[/(?<=\.)\w{2,4}$/]
|
||||
format = %w[html css js json].find{|f| f == request.format.symbol.to_s or f == page_name_extension }.try(:to_sym) || :html
|
||||
case format
|
||||
when :json
|
||||
render json: {}, status: 404
|
||||
when :html
|
||||
render template: 'pages/404', formats: [:html], layout: @page.layout.presence || ::Page.layouts.first.to_s, status: 404
|
||||
else
|
||||
render nothing: true, status: 404
|
||||
end
|
||||
end
|
||||
|
||||
def not_found
|
||||
@page = ::Page.find_by_name_and_locale('404', I18n.locale.to_s) || ::Page.new(name: '404', body: "404 Page Not Found")
|
||||
@sub_pages = []
|
||||
page_name_extension = params[:name].to_s[/(?<=\.)\w{2,4}$/]
|
||||
format = %w[html css js json].find{|f| f == request.format.symbol.to_s or f == page_name_extension }.try(:to_sym) || :html
|
||||
case format
|
||||
when :json
|
||||
render json: {}, status: 404
|
||||
when :html
|
||||
render template: 'pages/404', formats: [:html], layout: @page.layout.presence || ::Page.layouts.first.to_s, status: 404
|
||||
else
|
||||
render nothing: true, status: 404
|
||||
end
|
||||
end
|
||||
|
||||
def sitemap
|
||||
respond_to do |format|
|
||||
format.xml do
|
||||
pages_xml = ::Page.for_sitemap.map do |page|
|
||||
uri = page_url(page.name, locale: page.locale)
|
||||
"<url><loc>#{uri}</loc><lastmod>#{page.updated_at.strftime('%Y-%m-%d')}</lastmod></url>"
|
||||
end.join("\n")
|
||||
result = <<-XML
|
||||
def sitemap
|
||||
respond_to do |format|
|
||||
format.xml do
|
||||
pages_xml = ::Page.for_sitemap.map do |page|
|
||||
uri = page_url(page.name, locale: page.locale)
|
||||
"<url><loc>#{uri}</loc><lastmod>#{page.updated_at.strftime('%Y-%m-%d')}</lastmod></url>"
|
||||
end.join("\n")
|
||||
result = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
#{pages_xml}
|
||||
</urlset>
|
||||
XML
|
||||
render xml: result
|
||||
end
|
||||
XML
|
||||
render xml: result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
def find_page(name)
|
||||
::Page.find_by_name_and_locale(name, I18n.locale.to_s) || ::Page.new(name: name, locale: I18n.locale.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
def find_page(name)
|
||||
::Page.find_by_name_and_locale(name, I18n.locale.to_s) || ::Page.new(name: name, locale: I18n.locale.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user