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