From c47f65def8c7702e74aff943c7f190ff59ee01cf Mon Sep 17 00:00:00 2001 From: BOHUNG Date: Sun, 29 Sep 2019 14:58:58 +0800 Subject: [PATCH] fix some bug and delete unuse code --- .../admin/patchfiles_controller.rb | 2 +- app/models/fontfile.rb | 14 ++--- app/models/patchfilefield.rb | 63 ++++++++++--------- 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/app/controllers/admin/patchfiles_controller.rb b/app/controllers/admin/patchfiles_controller.rb index baa25a3..235da5e 100644 --- a/app/controllers/admin/patchfiles_controller.rb +++ b/app/controllers/admin/patchfiles_controller.rb @@ -111,7 +111,7 @@ class Admin::PatchfilesController < OrbitAdminController end redirect_to admin_patchfiles_editckeditor_path and return else - params["patchfilefield"]["new_add_font"] = params["patchfilefield"]["new_add_font"].gsub('\"','').gsub("\'",'').gsub(";",'') + params["patchfilefield"]["new_add_font"] = params["patchfilefield"]["new_add_font"].gsub('\"','').gsub("\'",'').gsub(";",'').gsub('\\','') @field.new_add_font = params["patchfilefield"]["new_add_font"] rescue (redirect_to admin_patchfiles_showckeditor_path and return) @key_arr = @field.font_array.keys params["patchfilefield"]["font_array"] = {} if params["patchfilefield"]["font_array"].nil? == true diff --git a/app/models/fontfile.rb b/app/models/fontfile.rb index a68725e..4190853 100644 --- a/app/models/fontfile.rb +++ b/app/models/fontfile.rb @@ -10,7 +10,6 @@ class Fontfile field :title ,type:String ,default:"" field :is_delete_font_file, type:String,default: 'false' field :old_title ,type:String ,default:"" - #field :font_file ,type:String ,default:"" field :font_link ,type:String ,default:"" field :old_font_link ,type:String ,default:"" mount_uploader :font_file, AssetUploader @@ -20,14 +19,7 @@ class Fontfile field :old_font_dir, type:String ,default:"" scope :can_display, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc],[:postdate, :desc])} scope :is_approved, ->{where(:approved => true)} - #has_many :filefields, :autosave => true, :dependent => :destroy -# accepts_nested_attributes_for :filefields, :allow_destroy => true - # before_create - #before_update :set_old_link#,:set_old_title - #before_save :set_old_title - #before_create :set_expire after_update :change_font_name,:set_css_link,:change_font_settings - #after_save :change_font_name def change_font_settings if self.old_font_file_name == self.font_file_name && self.is_delete_font_file =='true' self.font_file_name = "" @@ -63,7 +55,8 @@ class Fontfile @filetowrite.write(@file_content) @filetowrite.close end - elsif self.old_font_link != ""&& self.old_font_link != self.font_link + end + if self.old_font_link != ""&& self.old_font_link != self.font_link @font_link_str = "" if @file_content.include? @font_link_str @file_content = @file_content.gsub(@font_link_str,'') @@ -127,7 +120,8 @@ class Fontfile f.puts @font_link_str } end - elsif self.font_link != "" + end + if self.font_link != "" @font_link_str = "" @str_to_search = self.font_link.to_s if @file_content.include? @str_to_search diff --git a/app/models/patchfilefield.rb b/app/models/patchfilefield.rb index 9b2180d..79c8429 100644 --- a/app/models/patchfilefield.rb +++ b/app/models/patchfilefield.rb @@ -186,39 +186,46 @@ class Patchfilefield @ckeditor_path = ENV['PWD'] + '/app/assets/javascripts/ckeditor' Dir.chdir(@ckeditor_path) if !File.file?("config_back.js.erb") - @filetowrite = File.new("config_back.js.erb","w") - if @add_font_array != [] - @add_font_array.each do |new_add_font| - @filedata = @filedata.insert(@str_end,"\;"+new_add_font) + if @str_end != nil + @filetowrite = File.new("config_back.js.erb","w") + if @add_font_array != [] + @add_font_array.each do |new_add_font| + @filedata = @filedata.insert(@str_end,"\;"+new_add_font) + end end - end - @delete_font_array.each do |font_to_delete| - if @filedata.index(font_to_delete) != nil - @str_above_end = @filedata.index(font_to_delete) - 1 - @str_above_start - for @str_above_start in (0..@str_above_end).to_a.reverse - if @filedata[@str_above_start] =="\'" || @filedata[@str_above_start] =="\"" - break + @delete_font_array.each do |font_to_delete| + if @filedata.index(font_to_delete) != nil + @str_above_end = @filedata.index(font_to_delete).to_i - 1 + @str_above_start + for @str_above_start in (0..@str_above_end).to_a.reverse + if @filedata[@str_above_start] =="\'" || @filedata[@str_above_start] =="\"" + break + end + break if @filedata[@str_above_start] == "\;" + end + @str_above_start = @str_above_end - 1 if @str_above_start == nil + @str_to_delete = (( @filedata[@str_above_start..@str_above_end].include? "\;") ? @filedata[@str_above_start..@str_above_end] : "")+font_to_delete + @name_to_search ="config.font_names" + @index_of_font = @filedata.index(@name_to_search) + @datachange = @filedata[@index_of_font...@str_end] + @new_datachange = @datachange.sub(@str_to_delete,'') + @filedata =@filedata.sub(@datachange,@new_datachange) + for @i in @str_start+1...@str_end + next if @filedata[@i] == " " + break if @filedata[@i] != "\;" + @filedata.slice!(@i) end - break if @filedata[@str_above_start] == "\;" - end - @str_to_delete = (( @filedata[@str_above_start..@str_above_end].include? "\;") ? @filedata[@str_above_start..@str_above_end] : "")+font_to_delete - @filedata =@filedata.sub(@str_to_delete,"") - for @i in @str_start+1...@str_end - next if @filedata[@i] == " " - break if @filedata[@i] != "\;" - @filedata.slice!(@i) end end + puts self.used_font + puts @filedata + @filetowrite.write(@filedata) + @filetowrite.close + @filetocover = File.open("config.js.erb","w") + @filetocover.write(@filedata) + @filetocover.close + File.delete("config_back.js.erb") end - puts self.used_font - puts @filedata - @filetowrite.write(@filedata) - @filetowrite.close - @filetocover = File.open("config.js.erb","w") - @filetocover.write(@filedata) - @filetocover.close - File.delete("config_back.js.erb") else @filedata1 = File.read("config.js.erb") @filedata2 = File.read("config_back.js.erb")