2020-07-22 02:23:36 +00:00
|
|
|
# encoding: UTF-8
|
|
|
|
$:.push File.expand_path("../lib", __FILE__)
|
|
|
|
|
|
|
|
# Maintain your gem's version:
|
|
|
|
require "event_news_mod/version"
|
2021-05-19 14:17:26 +00:00
|
|
|
bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
|
|
|
|
if bundle_update_flag
|
2021-08-24 15:09:19 +00:00
|
|
|
require File.expand_path("../update_event_news", __FILE__)
|
2021-05-19 14:17:26 +00:00
|
|
|
env_pwd = ENV['PWD']
|
|
|
|
app_path = File.expand_path(__dir__)
|
|
|
|
template_path = env_pwd + '/app/templates'
|
|
|
|
all_template = Dir.glob(template_path+'/*/')
|
|
|
|
default_event_news_widget_info = JSON.parse(File.read("#{app_path}/modules/event_news/info.json"))["widgets"].sort_by{|h| h["filename"].to_i} rescue []
|
|
|
|
all_template.each do |folder|
|
|
|
|
if !folder.include?('mobile')
|
2021-06-09 07:05:42 +00:00
|
|
|
info_json_file = "#{folder}modules/event_news/info.json"
|
|
|
|
if File.exist?(info_json_file)
|
2021-08-23 11:44:45 +00:00
|
|
|
Bundler.with_clean_env{system ('cp -f '+ app_path + '/modules/event_news/show.html.erb ' + "#{folder}modules/event_news/.")}
|
2021-08-24 15:09:19 +00:00
|
|
|
update_event_news_template(folder)
|
2021-06-09 07:05:42 +00:00
|
|
|
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
|
|
|
|
puts "Checking event_news widgets"
|
|
|
|
widget_info = info["widgets"].sort_by{|h| h["filename"].to_i} rescue []
|
|
|
|
update_flag = false
|
|
|
|
last_index = widget_info[-1]["filename"].match(/\d+/)[0].to_i rescue nil
|
|
|
|
if !last_index.nil?
|
2021-09-05 10:56:57 +00:00
|
|
|
idx_regex = /^(\d+[\. \t]*)|[ \t]+$/
|
2021-06-09 07:05:42 +00:00
|
|
|
default_event_news_widget_info.each do |h|
|
2021-09-05 10:56:57 +00:00
|
|
|
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)
|
2021-06-09 07:05:42 +00:00
|
|
|
if widget_info_index == -1
|
|
|
|
update_flag = true
|
|
|
|
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/_#{h["filename"]}.html.erb #{folder}modules/event_news/_#{copy_h["filename"]}.html.erb]}
|
|
|
|
elsif h["force_cover"] == "true"
|
|
|
|
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/event_news/_#{h["filename"]}.html.erb #{folder}modules/event_news/_#{widget_info[widget_info_index]["filename"]}.html.erb]}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if update_flag
|
|
|
|
info["widgets"] = widget_info
|
|
|
|
puts "Writing json #{info["widgets"].count} in #{info_json_file}"
|
|
|
|
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
|
|
|
|
end
|
|
|
|
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
|
2021-05-19 14:17:26 +00:00
|
|
|
end
|
|
|
|
end
|
2021-06-09 07:05:42 +00:00
|
|
|
|
|
|
|
# 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
|
2021-05-19 14:17:26 +00:00
|
|
|
end
|
2020-07-22 02:23:36 +00:00
|
|
|
# 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"
|
|
|
|
|
|
|
|
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
|