event_news/event_news_mod.gemspec

174 lines
8.4 KiB
Ruby
Raw Permalink Normal View History

2023-04-08 04:21:39 +00:00
# encoding: UTF-8
$:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version:
require "event_news_mod/version"
2024-01-28 07:09:09 +00:00
require "json"
2023-04-08 04:21:39 +00:00
bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
if bundle_update_flag
require File.expand_path("../update_event_news", __FILE__)
env_pwd = ENV['PWD']
begin
require ::File.expand_path('app/helpers/bundler_helper.rb', env_pwd)
extend BundlerHelper
rescue LoadError
def bundler_with_clean_env(&block)
if block_given?
if Bundler.respond_to?(:with_unbundled_env)
Bundler.with_unbundled_env(&block)
else
Bundler.with_clean_env(&block)
end
end
end
end
app_path = File.expand_path(__dir__)
template_path = env_pwd + '/app/templates'
all_template = Dir.glob(template_path+'/*/')
2024-01-28 07:09:09 +00:00
default_info_contents = JSON.parse(File.read("#{app_path}/modules/event_news_mod/info.json")) rescue {}
default_event_news_index_info = default_info_contents["frontend"].sort_by{|h| h["filename"].to_f} rescue []
default_event_news_widget_info = default_info_contents["widgets"].sort_by{|h| h["filename"].to_f} rescue []
2024-07-22 05:24:22 +00:00
default_event_news_show_info = default_info_contents["show"] rescue nil
2023-04-08 04:21:39 +00:00
all_template.each do |folder|
if !folder.include?('mobile')
if Dir.exist?("#{folder}modules/event_news")
bundler_with_clean_env{system ("cp -rf #{folder}modules/event_news #{folder}modules/event_news_mod && rm -rf #{folder}modules/event_news")}
end
if Dir.exist?("#{folder}modules/event_news_mod/event_news")
bundler_with_clean_env{system ("cp -rf #{folder}modules/event_news_mod/event_news/* #{folder}modules/event_news_mod/. && rm -rf #{folder}modules/event_news_mod/event_news")}
end
info_json_file = "#{folder}modules/event_news_mod/info.json"
if File.exist?(info_json_file)
bundler_with_clean_env{system ('cp -f '+ app_path + '/modules/event_news_mod/show.html.erb ' + "#{folder}modules/event_news_mod/.")}
update_event_news_template(folder)
begin
file_text = File.read(info_json_file) rescue ""
encode_file_text = file_text.encode("UTF-8", "UTF-8", invalid: :replace, replace: "???")
next if (encode_file_text.include?("???") rescue true)
info = JSON.parse(encode_file_text) rescue {}
flag = (info.count != 0 rescue false)
if flag
2024-01-28 07:09:09 +00:00
puts "Checking event_news index"
index_info = info["frontend"].sort_by{|h| h["filename"].to_i} rescue []
last_index = index_info.collect{|v| v["filename"].to_s.scan(/\d+/).collect{|v1| v1.to_i}}.flatten.sort[-1] rescue nil
2024-07-22 05:24:22 +00:00
update_index_flag = false
2024-01-28 07:09:09 +00:00
if !last_index.nil?
idx_regex = /^(\d+[\. \t]*)|[ \t]+$/
default_event_news_index_info.each do |h|
name_without_index = h["name"]["zh_tw"].gsub(idx_regex,'')
index_info_index = (index_info.index{|hh| hh["name"]["zh_tw"].gsub(idx_regex,'') == name_without_index}||-1 rescue -1)
if index_info_index == -1
2024-07-22 05:24:22 +00:00
update_index_flag = true
2024-01-28 07:09:09 +00:00
copy_h = h.dup
h.delete("force_cover")
last_index = last_index + 1
copy_h["filename"] = copy_h["filename"].sub(/\d+/){|ff| last_index.to_s}
copy_h["name"].keys.each do |locale|
copy_h["name"][locale] = copy_h["name"][locale].sub(/\d+/){|ff| last_index.to_s}
end
index_info << copy_h
bundler_with_clean_env{%x[cp -f #{app_path}/modules/event_news_mod/#{h["filename"]}.html.erb #{folder}modules/event_news_mod/#{copy_h["filename"]}.html.erb]}
elsif h["force_cover"] == "true"
bundler_with_clean_env{%x[cp -f #{app_path}/modules/event_news_mod/#{h["filename"]}.html.erb #{folder}modules/event_news_mod/#{index_info[index_info_index]["filename"]}.html.erb]}
end
end
2024-07-22 05:24:22 +00:00
if update_index_flag
2024-01-28 07:09:09 +00:00
info["frontend"] = index_info
puts "Writing json #{info["frontend"].count} in #{info_json_file}"
end
end
2023-04-08 04:21:39 +00:00
puts "Checking event_news widgets"
widget_info = info["widgets"].sort_by{|h| h["filename"].to_i} rescue []
last_index = widget_info.collect{|v| v["filename"].to_s.scan(/\d+/).collect{|v1| v1.to_i}}.flatten.sort[-1] rescue nil
2024-07-22 05:24:22 +00:00
update_widget_flag = false
2023-04-08 04:21:39 +00:00
if !last_index.nil?
idx_regex = /^(\d+[\. \t]*)|[ \t]+$/
default_event_news_widget_info.each do |h|
name_without_index = h["name"]["zh_tw"].gsub(idx_regex,'')
widget_info_index = (widget_info.index{|hh| hh["name"]["zh_tw"].gsub(idx_regex,'') == name_without_index}||-1 rescue -1)
if widget_info_index == -1
2024-07-22 05:24:22 +00:00
update_widget_flag = true
2023-04-08 04:21:39 +00:00
copy_h = h.dup
h.delete("force_cover")
last_index = last_index + 1
copy_h["filename"] = copy_h["filename"].sub(/\d+/){|ff| last_index.to_s}
copy_h["name"].keys.each do |locale|
copy_h["name"][locale] = copy_h["name"][locale].sub(/\d+/){|ff| last_index.to_s}
end
widget_info << copy_h
bundler_with_clean_env{%x[cp -f #{app_path}/modules/event_news_mod/_#{h["filename"]}.html.erb #{folder}modules/event_news_mod/_#{copy_h["filename"]}.html.erb]}
elsif h["force_cover"] == "true"
bundler_with_clean_env{%x[cp -f #{app_path}/modules/event_news_mod/_#{h["filename"]}.html.erb #{folder}modules/event_news_mod/_#{widget_info[widget_info_index]["filename"]}.html.erb]}
end
end
2024-07-22 05:24:22 +00:00
if update_widget_flag
2023-04-08 04:21:39 +00:00
info["widgets"] = widget_info
puts "Writing json #{info["widgets"].count} in #{info_json_file}"
end
end
2024-07-22 05:24:22 +00:00
update_show_flag = false
if !default_event_news_show_info.nil?
update_show_flag = info["show"] != default_event_news_show_info
info["show"] = default_event_news_show_info
default_event_news_show_info.each do |info_detail|
filename = info_detail['filename']
bundler_with_clean_env{%x[cp -f #{app_path}/modules/event_news_mod/#{filename}.html.erb #{folder}modules/event_news_mod/#{filename}.html.erb]}
end
end
if update_index_flag || update_widget_flag || update_show_flag
begin
info_json = JSON.pretty_generate(info).gsub(":[",":[\n").gsub(":{",":{\n")
rescue
info_json = info.to_s.gsub("=>",": \n")
end
File.open(info_json_file,"w+"){|f| f.write(info_json)}
end
2023-04-08 04:21:39 +00:00
end
rescue => e
puts e
puts "There has some error when checking event_news widgets"
end
else
if !Dir.exist?(File.dirname(info_json_file)) && Dir.exist?(File.dirname(File.dirname(info_json_file)))
bundler_with_clean_env{system ('cp -r '+ app_path + '/modules/ ' + folder)}
end
end
end
end
# all_template.each do |folder|
# if !folder.include?('mobile')
# moudle_path = "#{folder}modules/universal_table/"
# begin
# if Dir.exist?(File.dirname(moudle_path))
# bundler_with_clean_env{system ('cp -r '+ app_path + '/modules/ ' + folder)}
# end
# rescue => e
# puts "There was some error when updating event_news widget."
# end
# end
# end
end
# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "event_news_mod"
s.version = EventNewsMod::VERSION
s.authors = ["RulingDigital"]
s.email = ["orbit@rulingcom.com"]
s.homepage = "http://www.rulingcom.com"
s.summary = "EventNews for Orbit"
s.description = "EventNews for Orbit"
s.license = "MIT"
2024-07-18 12:59:34 +00:00
s.metadata = {
"_require" => "#{File.expand_path("../app/models/event_news_setting", __FILE__)}",
"global_hash" => "{enable_manually_sort: (EventNewsSetting.first.enable_manually_sort rescue false), is_postdate_sort_first: (EventNewsSetting.first.is_postdate_sort_first rescue false)}"
2024-07-18 12:59:34 +00:00
}
2023-04-08 04:21:39 +00:00
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]
s.add_dependency "rufus-scheduler", "~> 3.6.0"
end