2014-05-01 06:33:52 +00:00
|
|
|
$:.push File.expand_path("../lib", __FILE__)
|
|
|
|
|
|
|
|
# Maintain your gem's version:
|
|
|
|
require "gallery/version"
|
2021-08-07 09:40:49 +00:00
|
|
|
require 'json'
|
|
|
|
bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install'
|
|
|
|
if bundle_update_flag
|
|
|
|
env_pwd = ENV['PWD']
|
2022-09-08 12:13:03 +00:00
|
|
|
begin
|
|
|
|
require ::File.expand_path('app/helpers/bundler_helper.rb', env_pwd)
|
|
|
|
extend BundlerHelper
|
|
|
|
rescue LoadError
|
2023-04-08 04:24:06 +00:00
|
|
|
def bundler_with_clean_env(&block)
|
2022-09-08 12:13:03 +00:00
|
|
|
if block_given?
|
|
|
|
if Bundler.respond_to?(:with_unbundled_env)
|
2023-04-08 04:24:06 +00:00
|
|
|
Bundler.with_unbundled_env(&block)
|
2022-09-08 12:13:03 +00:00
|
|
|
else
|
2023-04-08 04:24:06 +00:00
|
|
|
Bundler.with_clean_env(&block)
|
2022-09-08 12:13:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-08-07 09:40:49 +00:00
|
|
|
app_path = File.expand_path(__dir__)
|
|
|
|
template_path = env_pwd + '/app/templates'
|
|
|
|
all_template = Dir.glob(template_path+'/*/')
|
|
|
|
default_gallery_widget_info = JSON.parse(File.read("#{app_path}/modules/gallery/info.json"))["widgets"].sort_by{|h| h["filename"].to_i} rescue []
|
|
|
|
all_template.each do |folder|
|
|
|
|
if !folder.include?('mobile')
|
|
|
|
info_json_file = "#{folder}modules/gallery/info.json"
|
|
|
|
if File.exist?(info_json_file)
|
|
|
|
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 gallery widgets"
|
|
|
|
widget_info = info["widgets"].sort_by{|h| h["filename"].to_i} rescue []
|
|
|
|
update_flag = false
|
2021-11-27 15:08:08 +00:00
|
|
|
last_index = widget_info.collect{|v| v["filename"].to_s.scan(/\d+/).collect{|v1| v1.to_i}}.flatten.sort[-1] rescue nil
|
2021-08-07 09:40:49 +00:00
|
|
|
if !last_index.nil?
|
2021-09-06 05:54:59 +00:00
|
|
|
idx_regex = /^(\d+[\. \t]*)|[ \t]+$/
|
2021-08-07 09:40:49 +00:00
|
|
|
default_gallery_widget_info.each do |h|
|
2021-09-06 05:54:59 +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-08-07 09:40:49 +00:00
|
|
|
if (widget_info_index == -1 || widget_info_index.nil?)
|
|
|
|
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
|
2022-09-08 12:13:03 +00:00
|
|
|
bundler_with_clean_env{%x[cp -f #{app_path}/modules/gallery/_#{h["filename"]}.html.erb #{folder}modules/gallery/_#{copy_h["filename"]}.html.erb]}
|
2021-08-07 09:40:49 +00:00
|
|
|
elsif h["force_cover"] == "true"
|
2022-09-08 12:13:03 +00:00
|
|
|
bundler_with_clean_env{%x[cp -f #{app_path}/modules/gallery/_#{h["filename"]}.html.erb #{folder}modules/gallery/_#{widget_info[widget_info_index]["filename"]}.html.erb]}
|
2021-08-07 09:40:49 +00:00
|
|
|
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 gallery widgets"
|
2019-09-30 14:24:14 +00:00
|
|
|
end
|
2021-08-07 09:40:49 +00:00
|
|
|
end
|
2019-09-30 14:24:14 +00:00
|
|
|
end
|
2021-08-07 09:40:49 +00:00
|
|
|
end
|
2019-09-30 14:24:14 +00:00
|
|
|
end
|
2020-03-04 05:06:55 +00:00
|
|
|
#system ('rm -r '+app_path + '/modules/')
|
2014-05-01 06:33:52 +00:00
|
|
|
# Describe your gem and declare its dependencies:
|
|
|
|
Gem::Specification.new do |s|
|
|
|
|
s.name = "gallery"
|
|
|
|
s.version = Gallery::VERSION
|
|
|
|
s.authors = ["Ruling Digital Inc."]
|
|
|
|
s.email = ["orbit@rulingcom.com"]
|
|
|
|
s.homepage = "http://www.rulingcom.com"
|
|
|
|
s.summary = "Campus Gallery."
|
|
|
|
s.description = "Campus Galllery"
|
|
|
|
s.license = "MIT"
|
2023-02-18 13:28:40 +00:00
|
|
|
s.metadata = {
|
|
|
|
"_require" => "#{File.expand_path("../app/models/album_setting", __FILE__)}",
|
2023-04-17 07:41:13 +00:00
|
|
|
"global_hash" => "{resize_gravity: ([AlbumSetting.first.resize_gravity, 'Center'].select{|s| s.present?}.first rescue 'Center'), thumb_process_option: (AlbumSetting.first.thumb_process_option rescue 1)}"
|
2023-02-18 13:28:40 +00:00
|
|
|
}
|
2014-05-01 06:33:52 +00:00
|
|
|
|
|
|
|
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
|
|
|
|
s.test_files = Dir["test/**/*"]
|
|
|
|
end
|