forked from spen/seminar
Merge branch 'master' into 'master'
Fix bug. See merge request spen/seminar!30
This commit is contained in:
commit
98b2f10b1e
113
seminar.gemspec
113
seminar.gemspec
|
@ -8,67 +8,70 @@ begin
|
||||||
rescue => e
|
rescue => e
|
||||||
puts [e.to_s,e.backtrace]
|
puts [e.to_s,e.backtrace]
|
||||||
end
|
end
|
||||||
require "json"
|
bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
|
||||||
env_pwd = ENV['PWD']
|
if bundle_update_flag
|
||||||
app_path = File.expand_path(__dir__)
|
require "json"
|
||||||
template_path = env_pwd + '/app/templates'
|
env_pwd = ENV['PWD']
|
||||||
all_template = Dir.glob(template_path+'/*/')
|
app_path = File.expand_path(__dir__)
|
||||||
default_seminar_widget_info = JSON.parse(File.read("#{app_path}/modules/seminar/info.json"))["widgets"].sort_by{|h| h["filename"].to_i} rescue []
|
template_path = env_pwd + '/app/templates'
|
||||||
all_template.each do |folder|
|
all_template = Dir.glob(template_path+'/*/')
|
||||||
if !folder.include?('mobile')
|
default_seminar_widget_info = JSON.parse(File.read("#{app_path}/modules/seminar/info.json"))["widgets"].sort_by{|h| h["filename"].to_i} rescue []
|
||||||
info_json_file = "#{folder}modules/seminar/info.json"
|
all_template.each do |folder|
|
||||||
if File.exist?(info_json_file)
|
if !folder.include?('mobile')
|
||||||
#Bundler.with_clean_env{system ('cp -f '+ app_path + '/modules/seminar/show.html.erb ' + "#{folder}modules/seminar/.")}
|
info_json_file = "#{folder}modules/seminar/info.json"
|
||||||
begin
|
if File.exist?(info_json_file)
|
||||||
file_text = File.read(info_json_file) rescue ""
|
#Bundler.with_clean_env{system ('cp -f '+ app_path + '/modules/seminar/show.html.erb ' + "#{folder}modules/seminar/.")}
|
||||||
encode_file_text = file_text.encode("UTF-8", "UTF-8", invalid: :replace, replace: "???")
|
begin
|
||||||
next if (encode_file_text.include?("???") rescue true)
|
file_text = File.read(info_json_file) rescue ""
|
||||||
info = JSON.parse(encode_file_text) rescue {}
|
encode_file_text = file_text.encode("UTF-8", "UTF-8", invalid: :replace, replace: "???")
|
||||||
flag = (info.count != 0 rescue false)
|
next if (encode_file_text.include?("???") rescue true)
|
||||||
if flag
|
info = JSON.parse(encode_file_text) rescue {}
|
||||||
puts "Checking seminar widgets"
|
flag = (info.count != 0 rescue false)
|
||||||
widget_info = info["widgets"].sort_by{|h| h["filename"].to_i} rescue []
|
if flag
|
||||||
update_flag = false
|
puts "Checking seminar widgets"
|
||||||
last_index = widget_info[-1]["filename"].match(/\d+/)[0].to_i rescue nil
|
widget_info = info["widgets"].sort_by{|h| h["filename"].to_i} rescue []
|
||||||
if !last_index.nil?
|
update_flag = false
|
||||||
idx_regex = /^(\d+[\. \t]*)|[ \t]+$/
|
last_index = widget_info[-1]["filename"].match(/\d+/)[0].to_i rescue nil
|
||||||
default_seminar_widget_info.each do |h|
|
if !last_index.nil?
|
||||||
name_without_index = h["name"]["zh_tw"].gsub(idx_regex,'')
|
idx_regex = /^(\d+[\. \t]*)|[ \t]+$/
|
||||||
widget_info_index = (widget_info.index{|hh| hh["name"]["zh_tw"].gsub(idx_regex,'') == name_without_index}||-1 rescue -1)
|
default_seminar_widget_info.each do |h|
|
||||||
if widget_info_index == -1
|
name_without_index = h["name"]["zh_tw"].gsub(idx_regex,'')
|
||||||
update_flag = true
|
widget_info_index = (widget_info.index{|hh| hh["name"]["zh_tw"].gsub(idx_regex,'') == name_without_index}||-1 rescue -1)
|
||||||
copy_h = h.dup
|
if widget_info_index == -1
|
||||||
h.delete("force_cover")
|
update_flag = true
|
||||||
last_index = last_index + 1
|
copy_h = h.dup
|
||||||
copy_h["filename"] = copy_h["filename"].sub(/\d+/){|ff| last_index.to_s}
|
h.delete("force_cover")
|
||||||
copy_h["name"].keys.each do |locale|
|
last_index = last_index + 1
|
||||||
copy_h["name"][locale] = copy_h["name"][locale].sub(/\d+/){|ff| last_index.to_s}
|
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/seminar/_#{h["filename"]}.html.erb #{folder}modules/seminar/_#{copy_h["filename"]}.html.erb]}
|
||||||
|
elsif h["force_cover"] == "true"
|
||||||
|
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/seminar/_#{h["filename"]}.html.erb #{folder}modules/seminar/_#{widget_info[widget_info_index]["filename"]}.html.erb]}
|
||||||
end
|
end
|
||||||
widget_info << copy_h
|
|
||||||
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/seminar/_#{h["filename"]}.html.erb #{folder}modules/seminar/_#{copy_h["filename"]}.html.erb]}
|
|
||||||
elsif h["force_cover"] == "true"
|
|
||||||
Bundler.with_clean_env{%x[cp -f #{app_path}/modules/seminar/_#{h["filename"]}.html.erb #{folder}modules/seminar/_#{widget_info[widget_info_index]["filename"]}.html.erb]}
|
|
||||||
end
|
end
|
||||||
end
|
if update_flag
|
||||||
if update_flag
|
info["widgets"] = widget_info
|
||||||
info["widgets"] = widget_info
|
puts "Writing json #{info["widgets"].count} in #{info_json_file}"
|
||||||
puts "Writing json #{info["widgets"].count} in #{info_json_file}"
|
begin
|
||||||
begin
|
info_json = JSON.pretty_generate(info).gsub(":[",":[\n").gsub(":{",":{\n")
|
||||||
info_json = JSON.pretty_generate(info).gsub(":[",":[\n").gsub(":{",":{\n")
|
rescue
|
||||||
rescue
|
info_json = info.to_s.gsub("=>",": \n")
|
||||||
info_json = info.to_s.gsub("=>",": \n")
|
end
|
||||||
|
File.open(info_json_file,"w+"){|f| f.write(info_json)}
|
||||||
end
|
end
|
||||||
File.open(info_json_file,"w+"){|f| f.write(info_json)}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
rescue => e
|
||||||
|
puts e
|
||||||
|
puts "There has some error when checking seminar 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
|
||||||
rescue => e
|
|
||||||
puts e
|
|
||||||
puts "There has some error when checking seminar 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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue