Prepare to support ruby 3.3.

This commit is contained in:
邱博亞 2024-02-24 21:25:10 +08:00
parent 9abbb5d09b
commit 565a7fb8e4
1 changed files with 83 additions and 81 deletions

View File

@ -1,94 +1,96 @@
module CustomGallery
class Engine < ::Rails::Engine
initializer "custom_gallery" do
begin
translate_data = Dir["#{CustomGallery::Engine.root}/config/locales/*.yml"] .map{|yaml_file| YAML.load(File.read(yaml_file))}
data = {}
key1 = {}
value1 = {}
value2 = {}
value3 = {}
translate_data.each do |t_data|
v = t_data.values
k = t_data.keys[0]
key1[k] = v[0]['custom_gallery']['inner_page_layout']
value1[k] = v[0]['custom_gallery']['grid_style']
value2[k] = v[0]['custom_gallery']['card_style']
value3[k] = v[0]['custom_gallery']['slideshow_style']
Rails.application.config.to_prepare do
begin
translate_data = Dir["#{CustomGallery::Engine.root}/config/locales/*.yml"] .map{|yaml_file| YAML.load(File.read(yaml_file))}
data = {}
key1 = {}
value1 = {}
value2 = {}
value3 = {}
translate_data.each do |t_data|
v = t_data.values
k = t_data.keys[0]
key1[k] = v[0]['custom_gallery']['inner_page_layout']
value1[k] = v[0]['custom_gallery']['grid_style']
value2[k] = v[0]['custom_gallery']['card_style']
value3[k] = v[0]['custom_gallery']['slideshow_style']
end
data[key1] = [value1,value2,value3]
rescue => e
puts ['error in custom_gallery',e]
end
data[key1] = [value1,value2,value3]
rescue => e
puts ['error in custom_gallery',e]
end
require File.expand_path('../../../app/models/custom_album_setting', __FILE__)
if defined?(CustomAlbumSetting)
if CustomAlbumSetting.first.nil?
CustomAlbumSetting.create()
elsif CustomAlbumSetting.count > 1
CustomAlbumSetting.all.to_a[1..-1].each do |custom_album_setting|
custom_album_setting.destroy
require File.join(CustomGallery::Engine.root, 'app/models/custom_album_setting')
if defined?(CustomAlbumSetting)
if CustomAlbumSetting.first.nil?
CustomAlbumSetting.create()
elsif CustomAlbumSetting.count > 1
CustomAlbumSetting.all.to_a[1..-1].each do |custom_album_setting|
custom_album_setting.destroy
end
end
end
end
OrbitApp.registration "CustomGallery", :type => "ModuleApp" do
module_label "custom_gallery.custom_gallery"
base_url File.expand_path File.dirname(__FILE__)
widget_methods ["widget","custom_album_widget"]
# widget_settings []
widget_settings [{"data_count"=>30,"enable_custom_widget_data"=>true}]
models_to_cache [:custom_album,:custom_album_image]
taggable "CustomAlbum"
categorizable
authorizable
frontend_enabled
data_count 1..30
begin
show_option_items data
rescue => e
puts ['there_was_no_show_option_method',e]
end
side_bar do
set_sidebar_order(100) rescue nil
head_label_i18n 'custom_gallery.custom_gallery', icon_class: "fa fa-file-image-o"
available_for "users"
active_for_controllers (['admin/custom_galleries','admin/images'])
head_link_path "admin_custom_galleries_path"
OrbitApp.registration "CustomGallery", :type => "ModuleApp" do
module_label "custom_gallery.custom_gallery"
base_url File.expand_path File.dirname(__FILE__)
widget_methods ["widget","custom_album_widget"]
# widget_settings []
widget_settings [{"data_count"=>30,"enable_custom_widget_data"=>true}]
models_to_cache [:custom_album,:custom_album_image]
taggable "CustomAlbum"
categorizable
authorizable
frontend_enabled
data_count 1..30
begin
show_option_items data
rescue => e
puts ['there_was_no_show_option_method',e]
end
side_bar do
set_sidebar_order(100) rescue nil
head_label_i18n 'custom_gallery.custom_gallery', icon_class: "fa fa-file-image-o"
available_for "users"
active_for_controllers (['admin/custom_galleries','admin/images'])
head_link_path "admin_custom_galleries_path"
context_link 'custom_gallery.all',
:link_path=>"admin_custom_galleries_path" ,
:priority=>1,
:active_for_action=>{'admin/custom_galleries'=>"index"},
:available_for => 'users'
context_link 'custom_gallery.all',
:link_path=>"admin_custom_galleries_path" ,
:priority=>1,
:active_for_action=>{'admin/custom_galleries'=>"index"},
:available_for => 'users'
# context_link 'custom_gallery.new',
# :link_path=>"new_admin_custom_gallery_path" ,
# :priority=>2,
# :active_for_action=>{'admin/custom_galleries'=>"new"},
# :available_for => 'sub_managers'
# context_link 'custom_gallery.new',
# :link_path=>"new_admin_custom_gallery_path" ,
# :priority=>2,
# :active_for_action=>{'admin/custom_galleries'=>"new"},
# :available_for => 'sub_managers'
context_link 'categories',
:link_path=>"admin_module_app_categories_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'custom_gallery').id}",
:priority=>3,
:active_for_action=>{'admin/custom_galleries'=>'categories'},
:active_for_category => 'CustomGallery',
:available_for => 'managers'
context_link 'tags',
:link_path=>"admin_module_app_tags_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'custom_gallery').id}",
:priority=>4,
:active_for_action=>{'admin/custom_galleries'=>'tags'},
:active_for_tag => 'CustomGallery',
:available_for => 'managers'
context_link 'setting',
:link_path=>"admin_custom_galleries_setting_path" ,
:priority=>5,
:active_for_action=>{'admin/custom_galleries'=>'setting'},
:available_for => 'managers'
end
context_link 'categories',
:link_path=>"admin_module_app_categories_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'custom_gallery').id}",
:priority=>3,
:active_for_action=>{'admin/custom_galleries'=>'categories'},
:active_for_category => 'CustomGallery',
:available_for => 'managers'
context_link 'tags',
:link_path=>"admin_module_app_tags_path" ,
:link_arg=>"{:module_app_id=>ModuleApp.find_by(:key=>'custom_gallery').id}",
:priority=>4,
:active_for_action=>{'admin/custom_galleries'=>'tags'},
:active_for_tag => 'CustomGallery',
:available_for => 'managers'
context_link 'setting',
:link_path=>"admin_custom_galleries_setting_path" ,
:priority=>5,
:active_for_action=>{'admin/custom_galleries'=>'setting'},
:available_for => 'managers'
end
end
end
end
end