# -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) # Maintain your gem's version: require "file_manager/version" bundle_update_flag = ARGV[0]=='update' || ARGV[0]=='install' if bundle_update_flag require "json" 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 if block_given? if Bundler.respond_to?(:with_unbundled_env) Bundler.with_unbundled_env(&Proc.new) else Bundler.with_clean_env(&Proc.new) end end end end app_path = File.expand_path(__dir__) if Dir.exist?("#{app_path}/modules") template_path = env_pwd + '/app/templates' all_template = Dir.glob(template_path+'/*/') default_file_manager_widget_info = JSON.parse(File.read("#{app_path}/modules/file-manager/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/file-manager/info.json" if File.exist?(info_json_file) #bundler_with_clean_env{system ('cp -f '+ app_path + '/modules/file-manager/show.html.erb ' + "#{folder}modules/file-manager/.")} 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 file-manager 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? idx_regex = /^(\d+[\. \t]*)|[ \t]+$/ default_file_manager_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 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/file-manager/_#{h["filename"]}.html.erb #{folder}modules/file-manager/_#{copy_h["filename"]}.html.erb]} elsif h["force_cover"] == "true" bundler_with_clean_env{%x[cp -f #{app_path}/modules/file-manager/_#{h["filename"]}.html.erb #{folder}modules/file-manager/_#{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 file-manager 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 Gem::Specification.new do |s| s.name = "file-manager" s.version = FileManager::VERSION s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.require_paths = ["lib"] s.authors = ["Bohung Chiu"] s.date = "2024-05-12" s.description = "file-manager plugin." s.email = ["bohung@rulingcom.com"] s.files = ["{app,config,lib}/**/*", "MIT-LICENSE", "README.rdoc", "Rakefile"] s.homepage = "https://orbitek.co" s.licenses = ["MIT"] s.summary = "file-manager plugin." s.test_files = ["test/test_helper.rb", "test/controllers/index_test.rb"] # s.add_dependency "charlock_holmes" # s.add_dependency "custom_gallery" end