Fix bug that update orbit kernel will delete the fonts change in ckeditor.
This commit is contained in:
parent
f1df8a5329
commit
20ef6e26d3
|
@ -116,7 +116,7 @@ class Admin::PatchfilesController < OrbitAdminController
|
|||
@file_name = @file.original_filename
|
||||
@file_content = @file.read
|
||||
@file_content.force_encoding('UTF-8')
|
||||
Dir.chdir(@file_path)
|
||||
Dir.chdir(@file_path) do
|
||||
@filetowrite
|
||||
if !File.file?(@file_name)
|
||||
@filetowrite = File.new(@file_name,"w")
|
||||
|
@ -125,7 +125,7 @@ class Admin::PatchfilesController < OrbitAdminController
|
|||
end
|
||||
@filetowrite.write(@file_content)
|
||||
@filetowrite.close
|
||||
Dir.chdir(Rails.root.to_s)
|
||||
end
|
||||
else
|
||||
@file_name = @font_settings.font_file_name
|
||||
end
|
||||
|
@ -196,42 +196,18 @@ class Admin::PatchfilesController < OrbitAdminController
|
|||
def getfont
|
||||
@font_array = []
|
||||
@ckeditor_path = ENV['PWD'] + '/app/assets/javascripts/ckeditor'
|
||||
@filedata = File.read(@ckeditor_path+"/config.js.erb") rescue return
|
||||
@name_to_search ="config.font_names"
|
||||
@index_of_font = @filedata.index(@name_to_search)
|
||||
custom_fonts_file = "#{@ckeditor_path}/custom_fonts.txt"
|
||||
@font_str = ""
|
||||
@end_character
|
||||
@str_start
|
||||
@str_end
|
||||
if @index_of_font != nil
|
||||
@inex_start_to_search = @index_of_font + @name_to_search.length
|
||||
@str_start = @inex_start_to_search
|
||||
if (@filedata[@inex_start_to_search] != "\'" && @filedata[@inex_start_to_search] != "\"")
|
||||
for @str_start in @inex_start_to_search..@filedata.length
|
||||
break if (@filedata[@str_start] == "\'" || @filedata[@str_start] == "\"")
|
||||
end
|
||||
end
|
||||
@end_character = @filedata[@str_start]
|
||||
@str_end = @str_start+1
|
||||
if @str_start+1 < @filedata.length
|
||||
@str_end = @str_start+1
|
||||
for @str_end in @str_start+1..@filedata.length
|
||||
break if @filedata[@str_end] == @end_character || @str_end == @str_start
|
||||
if @filedata[@str_end] == "="
|
||||
@str_end = @str_start
|
||||
break
|
||||
end
|
||||
end
|
||||
if @str_end != @str_start
|
||||
@font_str = @filedata[@str_start+1...@str_end]
|
||||
if File.exist?(custom_fonts_file)
|
||||
@font_str = File.read(custom_fonts_file).strip rescue ""
|
||||
else
|
||||
@font_str = ""
|
||||
end
|
||||
@filedata = File.read(@ckeditor_path+"/config.js.erb") rescue return
|
||||
@font_str = @filedata.scan(/(config.font_names\s*=\s*(\"([^"]*)\"|\'([^']*)\'))/m).map{|a| (a[3] rescue nil)}.compact[-1]
|
||||
end
|
||||
@font_array = @font_str.split("\;")
|
||||
@font_array.map!{|i| i.strip}
|
||||
@font_array.delete("")
|
||||
end
|
||||
@font_array
|
||||
end
|
||||
def create_first_field
|
||||
@app_title = "patchfile"
|
||||
|
|
|
@ -20,7 +20,6 @@ class Patchfilefield
|
|||
before_create :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font
|
||||
before_update :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font
|
||||
before_save :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font
|
||||
after_update :set_config
|
||||
after_save :set_config
|
||||
#before_create :set_expire
|
||||
def delete_empty_font
|
||||
|
@ -94,10 +93,6 @@ class Patchfilefield
|
|||
self.new_add_font = ""
|
||||
end
|
||||
end
|
||||
# def set_expire
|
||||
# self.expirable_created_at = Time.now if self.is_preview
|
||||
# return true
|
||||
# end
|
||||
def set_un_used_font
|
||||
@un_use_font = []
|
||||
self.font_array.each do |font,istrue|
|
||||
|
@ -173,8 +168,6 @@ class Patchfilefield
|
|||
end
|
||||
@delete_font_array.push(self.delete_font) if self.delete_font != ""
|
||||
self.delete_font = ""
|
||||
puts "111111111111111111111111111111111111111111111111"
|
||||
puts @delete_font_array
|
||||
@add_font_array = []
|
||||
@use_font = self.used_font rescue []
|
||||
@use_font.each do |font_to_add|
|
||||
|
@ -184,59 +177,15 @@ class Patchfilefield
|
|||
end
|
||||
if @add_font_array != [] || @delete_font_array != []
|
||||
@ckeditor_path = ENV['PWD'] + '/app/assets/javascripts/ckeditor'
|
||||
Dir.chdir(@ckeditor_path)
|
||||
if !File.file?("config_back.js.erb")
|
||||
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)
|
||||
Dir.chdir(@ckeditor_path) do
|
||||
File.open("custom_fonts.txt","w+") do |f|
|
||||
f.write(self.used_font.join(";"))
|
||||
end
|
||||
puts "writing........."
|
||||
File.open("config.js.erb","a+") do |f|
|
||||
f.puts ""
|
||||
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).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
|
||||
end
|
||||
end
|
||||
puts self.used_font
|
||||
puts @filedata
|
||||
@filetowrite.write(@filedata)
|
||||
@filetowrite.close
|
||||
@filetocover = File.open("config.js.erb","w") rescue return
|
||||
@filetocover.write(@filedata)
|
||||
@filetocover.close
|
||||
File.delete("config_back.js.erb")
|
||||
end
|
||||
else
|
||||
@filedata1 = File.read("config.js.erb")
|
||||
@filedata2 = File.read("config_back.js.erb")
|
||||
if @filedata1.length < @filedata2.length
|
||||
@filetocover = File.open("config.js.erb","w")
|
||||
@filetocover.write(@filedata2)
|
||||
@filetocover.close
|
||||
end
|
||||
File.delete("config_back.js.erb")
|
||||
end
|
||||
Dir.chdir(Rails.root.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue