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,196 +1,198 @@
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
begin require "yaml"
translate_data = Dir["#{EventNewsMod::Engine.root}/config/locales/*.yml"] .map{|yaml_file| YAML.load(File.read(yaml_file))} begin
data = {} translate_data = Dir["#{EventNewsMod::Engine.root}/config/locales/*.yml"] .map{|yaml_file| YAML.load(File.read(yaml_file))}
key1 = {} data = {}
key2 = {} key1 = {}
key3 = {} key2 = {}
key4 = {} key3 = {}
key5 = {} key4 = {}
key1_attr = [] key5 = {}
key2_attr = [] key1_attr = []
key3_attr = [] key2_attr = []
key4_attr = [] key3_attr = []
data_item = {} key4_attr = []
key_item1 = {} data_item = {}
key_item2 = {} key_item1 = {}
key_item3 = {} key_item2 = {}
value_item1 = {} key_item3 = {}
value_item2 = {} value_item1 = {}
value_item3 = {} value_item2 = {}
value2_item1 = {} value_item3 = {}
value2_item2 = {} value2_item1 = {}
key1_options = ['small_size','medium_size','orignal_size'] value2_item2 = {}
key2_options = ['not_enable_tabs','enable_tabs_with_categories_include_all','enable_tabs_with_categories'] key1_options = ['small_size','medium_size','orignal_size']
key3_options = ['default','upper_left','lower_left','upper_right','lower_right'] key2_options = ['not_enable_tabs','enable_tabs_with_categories_include_all','enable_tabs_with_categories']
key4_options = ['the_same_as_data_count','display_all_in_other_tabs'] key3_options = ['default','upper_left','lower_left','upper_right','lower_right']
#After fix I18n.load_path, translation can work there key4_options = ['the_same_as_data_count','display_all_in_other_tabs']
key5_attr = ['no_','yes_'].map{|v| I18n.available_locales.map{|k| I18n.with_locale(k){[k,I18n.t(v)]}}.to_h} #After fix I18n.load_path, translation can work there
key1_options.each_with_index do |k,i| key5_attr = ['no_','yes_'].map{|v| I18n.available_locales.map{|k| I18n.with_locale(k){[k,I18n.t(v)]}}.to_h}
key1_attr[i] = {} key1_options.each_with_index do |k,i|
end key1_attr[i] = {}
key2_options.each_with_index do |k,i| end
key2_attr[i] = {} key2_options.each_with_index do |k,i|
end key2_attr[i] = {}
key3_options.each_with_index do |k,i| end
key3_attr[i] = {} key3_options.each_with_index do |k,i|
end key3_attr[i] = {}
key4_options.each_with_index do |k,i| end
key4_attr[i] = {} key4_options.each_with_index do |k,i|
end key4_attr[i] = {}
translate_data.each do |t_data| end
v = t_data.values translate_data.each do |t_data|
k = t_data.keys[0] v = t_data.values
key1[k] = v[0]['event_news']['picture_showing_size'] k = t_data.keys[0]
key2[k] = v[0]['event_news']['tabs_options'] key1[k] = v[0]['event_news']['picture_showing_size']
key3[k] = v[0]['event_news']['read_more_position_options'] key2[k] = v[0]['event_news']['tabs_options']
key4[k] = v[0]['event_news']['all_tabs_setting'] key3[k] = v[0]['event_news']['read_more_position_options']
key5[k] = v[0]['event_news']['show_today_data_first'] key4[k] = v[0]['event_news']['all_tabs_setting']
key1_options.each_with_index do |kk,i| key5[k] = v[0]['event_news']['show_today_data_first']
key1_attr[i][k] = v[0]['event_news'][kk] key1_options.each_with_index do |kk,i|
end key1_attr[i][k] = v[0]['event_news'][kk]
key2_options.each_with_index do |kk,i| end
key2_attr[i][k] = v[0]['event_news'][kk] key2_options.each_with_index do |kk,i|
end key2_attr[i][k] = v[0]['event_news'][kk]
key3_options.each_with_index do |kk,i| end
key3_attr[i][k] = v[0]['event_news'][kk] key3_options.each_with_index do |kk,i|
end key3_attr[i][k] = v[0]['event_news'][kk]
key4_options.each_with_index do |kk,i| end
key4_attr[i][k] = v[0]['event_news'][kk] key4_options.each_with_index do |kk,i|
end key4_attr[i][k] = v[0]['event_news'][kk]
key_item1[k] = v[0]['event_news']['showing_back_and_next'] end
key_item2[k] = v[0]['event_news']['enable_search'] key_item1[k] = v[0]['event_news']['showing_back_and_next']
key_item3[k] = v[0]['event_news']['ad_banner_location'] key_item2[k] = v[0]['event_news']['enable_search']
value_item1[k] = v[0]['event_news']['not_show'] key_item3[k] = v[0]['event_news']['ad_banner_location']
value_item2[k] = v[0]['event_news']['show_bottom'] value_item1[k] = v[0]['event_news']['not_show']
value_item3[k] = v[0]['event_news']['show_top'] value_item2[k] = v[0]['event_news']['show_bottom']
value2_item1[k] = v[0]['event_news']['no'] value_item3[k] = v[0]['event_news']['show_top']
value2_item2[k] = v[0]['event_news']['yes'] value2_item1[k] = v[0]['event_news']['no']
end value2_item2[k] = v[0]['event_news']['yes']
data[key1] = key1_attr end
data[key2] = key2_attr data[key1] = key1_attr
data[key3] = key3_attr data[key2] = key2_attr
data[key4] = key4_attr data[key3] = key3_attr
data[key5] = key5_attr data[key4] = key4_attr
data_item[key_item1] = [value_item1,value_item2,value_item3] data[key5] = key5_attr
data_item[key_item2] = [value2_item1,value2_item2] data_item[key_item1] = [value_item1,value_item2,value_item3]
data_item[key_item3] = [value_item2,value_item3] data_item[key_item2] = [value2_item1,value2_item2]
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console') data_item[key_item3] = [value_item2,value_item3]
require File.expand_path('../../../app/models/event_news_cache', __FILE__) if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
if defined?(EventNewsCache) require File.expand_path('../../../app/models/event_news_cache', __FILE__)
EventNewsCache.destroy_all if defined?(EventNewsCache)
end EventNewsCache.destroy_all
require File.expand_path('../../../app/models/event_news_custom_title', __FILE__) end
if defined? EventNewsCustomTitle require File.expand_path('../../../app/models/event_news_custom_title', __FILE__)
EventNewsCustomTitle.get_map if defined? EventNewsCustomTitle
end EventNewsCustomTitle.get_map
end end
rescue => e end
puts ['error in event_news',e,e.backtrace] rescue => e
end puts ['error in event_news',e,e.backtrace]
OrbitApp.registration "event_news_mod", :type => "ModuleApp" do end
db = ::Mongoid::Sessions.default OrbitApp.registration "event_news_mod", :type => "ModuleApp" do
collection = db[:module_apps] db = ::Mongoid::Sessions.default
update_results = collection.update_many({key: 'event_news'},'$set'=>{key: 'event_news_mod', title: 'event_news_mod'}) collection = db[:module_apps]
if update_results.n != 0 update_results = collection.update_many({key: 'event_news'},'$set'=>{key: 'event_news_mod', title: 'event_news_mod'})
puts "Updating event_news to event_news_mod!" if update_results.n != 0
collection = db[:pages] puts "Updating event_news to event_news_mod!"
collection.update_many({:module=> 'event_news'},'$set'=>{:module=> 'event_news_mod'}) collection = db[:pages]
collection = db[:sub_parts] collection.update_many({:module=> 'event_news'},'$set'=>{:module=> 'event_news_mod'})
collection.update_many({:module=> 'event_news'},'$set'=>{:module=> 'event_news_mod'}) collection = db[:sub_parts]
template_path = Rails.root.to_s + '/app/templates' collection.update_many({:module=> 'event_news'},'$set'=>{:module=> 'event_news_mod'})
all_template = Dir.glob(template_path+'/*/') template_path = Rails.root.to_s + '/app/templates'
all_template.each do |folder| all_template = Dir.glob(template_path+'/*/')
Bundler.with_clean_env{system ("mkdir -p #{folder}modules/event_news_mod; cp -rf #{folder}modules/event_news/* #{folder}modules/event_news_mod/. && rm -rf #{folder}modules/event_news_mod/event_news")} all_template.each do |folder|
end Bundler.with_clean_env{system ("mkdir -p #{folder}modules/event_news_mod; cp -rf #{folder}modules/event_news/* #{folder}modules/event_news_mod/. && rm -rf #{folder}modules/event_news_mod/event_news")}
end end
module_label "event_news.event_news" end
base_url File.expand_path File.dirname(__FILE__) module_label "event_news.event_news"
widget_methods ["widget","random_event_news_widget", "tag_cloud"] base_url File.expand_path File.dirname(__FILE__)
widget_settings [{"data_count"=>30}] widget_methods ["widget","random_event_news_widget", "tag_cloud"]
taggable "EventNews" widget_settings [{"data_count"=>30}]
categorizable taggable "EventNews"
authorizable categorizable
frontend_enabled authorizable
feeds_url "/xhr/event_news/feeds" frontend_enabled
data_count 1..30 feeds_url "/xhr/event_news/feeds"
begin data_count 1..30
show_options data begin
show_option_items data_item show_options data
rescue => e show_option_items data_item
puts ['there_was_no_show_option_method',e] rescue => e
end puts ['there_was_no_show_option_method',e]
if File.basename($0) != 'rake' end
begin if File.basename($0) != 'rake'
avoid_page_cache EventNewsCache begin
avoid_page_cache EventNewsFeedCache avoid_page_cache EventNewsCache
avoid_page_cache EventNewsFeed avoid_page_cache EventNewsFeedCache
rescue => e avoid_page_cache EventNewsFeed
puts ["avoid_page_cache", e.to_s] rescue => e
end puts ["avoid_page_cache", e.to_s]
end end
side_bar do end
head_label_i18n 'event_news.event_news', icon_class: "icons-megaphone" side_bar do
available_for "users" head_label_i18n 'event_news.event_news', icon_class: "icons-megaphone"
active_for_controllers (['admin/event_news']) available_for "users"
head_link_path "admin_event_news_index_path" active_for_controllers (['admin/event_news'])
head_link_path "admin_event_news_index_path"
context_link 'event_news.all_articles',
:link_path=>"admin_event_news_index_path" , context_link 'event_news.all_articles',
:priority=>1, :link_path=>"admin_event_news_index_path" ,
:active_for_action=>{'admin/event_news'=>'index'}, :priority=>1,
:available_for => 'users' :active_for_action=>{'admin/event_news'=>'index'},
context_link 'new_', :available_for => 'users'
:link_path=>"new_admin_event_news_path" , context_link 'new_',
:priority=>2, :link_path=>"new_admin_event_news_path" ,
:active_for_action=>{'admin/event_news'=>'new'}, :priority=>2,
:available_for => 'sub_managers' :active_for_action=>{'admin/event_news'=>'new'},
context_link 'categories', :available_for => 'sub_managers'
:link_path=>"admin_module_app_categories_path" , context_link 'categories',
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'event_news_mod').id}", :link_path=>"admin_module_app_categories_path" ,
:priority=>3, :link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'event_news_mod').id}",
:active_for_action=>{'admin/event_news'=>'categories'}, :priority=>3,
:active_for_category => 'EventNewsModule', :active_for_action=>{'admin/event_news'=>'categories'},
:available_for => 'managers' :active_for_category => 'EventNewsModule',
context_link 'tags', :available_for => 'managers'
:link_path=>"admin_module_app_tags_path" , context_link 'tags',
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'event_news_mod').id}", :link_path=>"admin_module_app_tags_path" ,
:priority=>4, :link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'event_news_mod').id}",
:active_for_action=>{'admin/event_news'=>'tags'}, :priority=>4,
:active_for_tag => 'EventNewsModule', :active_for_action=>{'admin/event_news'=>'tags'},
:available_for => 'managers' :active_for_tag => 'EventNewsModule',
context_link 'event_news.custom_fields_title', :available_for => 'managers'
:link_path=>"custom_fields_title_admin_event_news_index_path" , context_link 'event_news.custom_fields_title',
:priority=>5, :link_path=>"custom_fields_title_admin_event_news_index_path" ,
:active_for_action=>{'admin/event_news'=>'custom_fields_title'}, :priority=>5,
:available_for => 'managers' :active_for_action=>{'admin/event_news'=>'custom_fields_title'},
:available_for => 'managers'
context_link 'event_news.feed_list',
:link_path=>"admin_event_news_feed_path" , context_link 'event_news.feed_list',
:priority=>6, :link_path=>"admin_event_news_feed_path" ,
:active_for_action=>{'admin/event_news'=>'feed'}, :priority=>6,
:available_for => 'managers' :active_for_action=>{'admin/event_news'=>'feed'},
context_link 'event_news.import', :available_for => 'managers'
:link_path=>"admin_event_news_import_path" , context_link 'event_news.import',
:priority=>7, :link_path=>"admin_event_news_import_path" ,
:active_for_action=>{'admin/event_news'=>'import'}, :priority=>7,
:available_for => 'managers' :active_for_action=>{'admin/event_news'=>'import'},
context_link 'event_news.settings', :available_for => 'managers'
:link_path=>"admin_event_news_settings_path" , context_link 'event_news.settings',
:priority=>8, :link_path=>"admin_event_news_settings_path" ,
:active_for_action=>{'admin/event_news'=>'settings'}, :priority=>8,
:available_for => 'managers' :active_for_action=>{'admin/event_news'=>'settings'},
end :available_for => 'managers'
end
end
# temp = YAML.load_file(File.join(Rails.root,"config","mongoid.yml")) end
# dbsettings = temp["production"]["sessions"]["default"] # temp = YAML.load_file(File.join(Rails.root,"config","mongoid.yml"))
# s = Moped::Session.new(dbsettings["hosts"]) # dbsettings = temp["production"]["sessions"]["default"]
# s.use dbsettings["database"] # s = Moped::Session.new(dbsettings["hosts"])
# s[:bulletins].indexes.create({expirable_created_at: 1},{ expireAfterSeconds: 180 }) # s.use dbsettings["database"]
end # s[:bulletins].indexes.create({expirable_created_at: 1},{ expireAfterSeconds: 180 })
end end
end
end
end end