Prepare to support ruby 3.3.

This commit is contained in:
邱博亞 2024-02-24 21:05:55 +08:00
parent 6d14f05e15
commit b3a4dc479b
2 changed files with 148 additions and 146 deletions

View File

@ -320,9 +320,9 @@ module CustomAnnouncementsHelper
if @target_action == "index" if @target_action == "index"
filename = overridehtml.nil? ? params[:layout_type] : overridehtml filename = overridehtml.nil? ? params[:layout_type] : overridehtml
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', 'custom_announcement', "#{filename}.html.erb") f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', 'custom_announcement', "#{filename}.html.erb")
if !File.exists?f if !File.exist?(f)
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', 'custom_announcement', "index.html.erb") f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', 'custom_announcement', "index.html.erb")
if !File.exists?f if !File.exist?(f)
return "<div class='well'>Maybe the administrator has changed the theme, please select the index page design again from the page settings.</div>".html_safe return "<div class='well'>Maybe the administrator has changed the theme, please select the index page design again from the page settings.</div>".html_safe
end end
end end
@ -362,7 +362,7 @@ module CustomAnnouncementsHelper
else else
filename = overridehtml.nil? ? @target_action : overridehtml filename = overridehtml.nil? ? @target_action : overridehtml
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', 'custom_announcement', "#{filename}.html.erb") f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', 'custom_announcement', "#{filename}.html.erb")
if File.exists?f if File.exist?(f)
file = File.open(f) file = File.open(f)
doc = Nokogiri::HTML(file, nil, "UTF-8") doc = Nokogiri::HTML(file, nil, "UTF-8")
file.close file.close
@ -464,7 +464,7 @@ module CustomAnnouncementsHelper
layout_types = [] layout_types = []
@key = Site.first.template @key = Site.first.template
f = File.join("#{Rails.root}/app/templates/#{@key}/modules/#{module_app}/info.json") f = File.join("#{Rails.root}/app/templates/#{@key}/modules/#{module_app}/info.json")
if File.exists?f if File.exist?(f)
info = File.read(f) info = File.read(f)
hash = JSON.parse(info) rescue {} hash = JSON.parse(info) rescue {}
frontends = hash["frontend"] || [] frontends = hash["frontend"] || []

View File

@ -2,6 +2,7 @@ require "yaml"
module CustomAnnouncement module CustomAnnouncement
class Engine < ::Rails::Engine class Engine < ::Rails::Engine
initializer "custom_announcement" do initializer "custom_announcement" do
Rails.application.config.to_prepare do
begin begin
translate_data = Dir["#{CustomAnnouncement::Engine.root}/config/locales/*.yml"] .map{|yaml_file| YAML.load(File.read(yaml_file))} translate_data = Dir["#{CustomAnnouncement::Engine.root}/config/locales/*.yml"] .map{|yaml_file| YAML.load(File.read(yaml_file))}
data = {} data = {}
@ -152,3 +153,4 @@ module CustomAnnouncement
end end
end end
end end
end