Prepare to support ruby 3.3.

This commit is contained in:
邱博亞 2024-02-24 20:56:13 +08:00
parent a55848b554
commit 6c89f33caa
2 changed files with 201 additions and 199 deletions

View File

@ -334,9 +334,9 @@ module EventNewsHelper
if @target_action == "index" if @target_action == "index"
filename = File.basename(overridehtml.nil? ? params[:layout_type] : overridehtml) filename = File.basename(overridehtml.nil? ? params[:layout_type] : overridehtml)
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', 'event_news_mod', "#{filename}.html.erb") f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', 'event_news_mod', "#{filename}.html.erb")
if !File.exists?f if !File.exist?(f)
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', 'event_news_mod', "index.html.erb") f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', 'event_news_mod', "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
@ -376,7 +376,7 @@ module EventNewsHelper
else else
filename = overridehtml.nil? ? @target_action : overridehtml filename = overridehtml.nil? ? @target_action : overridehtml
f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', 'event_news_mod', "#{filename}.html.erb") f = File.join(Rails.root, 'app', 'templates', "#{@key}", 'modules', 'event_news_mod', "#{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
@ -478,7 +478,7 @@ module EventNewsHelper
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

@ -1,7 +1,8 @@
require "yaml"
module EventNewsMod module EventNewsMod
class Engine < ::Rails::Engine class Engine < ::Rails::Engine
initializer "event_news_mod" do initializer "event_news_mod" do
Rails.application.config.to_prepare do
require "yaml"
begin begin
translate_data = Dir["#{EventNewsMod::Engine.root}/config/locales/*.yml"] .map{|yaml_file| YAML.load(File.read(yaml_file))} translate_data = Dir["#{EventNewsMod::Engine.root}/config/locales/*.yml"] .map{|yaml_file| YAML.load(File.read(yaml_file))}
data = {} data = {}
@ -194,3 +195,4 @@ module EventNewsMod
end end
end end
end end
end