2011-07-12 08:02:41 +00:00
|
|
|
class Stylesheet < DesignFile
|
2012-10-24 10:40:38 +00:00
|
|
|
belongs_to :design
|
2012-11-01 12:42:40 +00:00
|
|
|
belongs_to :desktop_widget
|
2011-09-13 03:57:20 +00:00
|
|
|
mount_uploader :file_orig, AssetUploader
|
|
|
|
|
|
|
|
def parse_urls
|
|
|
|
orig_content = content = self.file.read.force_encoding("UTF-8")
|
2012-01-26 04:05:25 +00:00
|
|
|
# self.remove_file!
|
|
|
|
# self.remove_file_orig!
|
2011-09-13 03:57:20 +00:00
|
|
|
names = []
|
|
|
|
images = self.design.images
|
|
|
|
content.scan(/(?<=url)(.*?)(?=\))/){
|
|
|
|
css_name = $1.gsub(' ','').gsub('(','')
|
|
|
|
name = File.basename(css_name).gsub(/[\\\"]/, '')
|
2012-10-24 10:40:38 +00:00
|
|
|
image = images.detect{ |i| i.file_identifier.eql?(name) } rescue nil
|
|
|
|
image.update_attribute(:in_css, true) if image
|
|
|
|
file_name = image.file_url rescue nil
|
2011-09-13 03:57:20 +00:00
|
|
|
names << [css_name, file_name]
|
|
|
|
}
|
|
|
|
names.each do |name|
|
|
|
|
content.gsub!(name[0], name[1]) if name[1]
|
|
|
|
end
|
|
|
|
Dir.mktmpdir('f_path') { |dir|
|
2012-01-24 03:36:24 +00:00
|
|
|
orig_file_name = self.file_identifier
|
2011-09-13 03:57:20 +00:00
|
|
|
|
|
|
|
temp_file = File.new(dir + '/' + orig_file_name, 'w+')
|
|
|
|
temp_file.write orig_content.force_encoding("UTF-8")
|
|
|
|
self.file_orig = temp_file
|
|
|
|
|
|
|
|
temp_file = File.new(dir + '/' + orig_file_name, 'w+')
|
|
|
|
temp_file.write content.force_encoding("UTF-8")
|
|
|
|
self.file = temp_file
|
2012-04-06 09:31:22 +00:00
|
|
|
self.save
|
2012-01-26 04:05:25 +00:00
|
|
|
}
|
2011-09-13 03:57:20 +00:00
|
|
|
end
|
2012-11-01 12:42:40 +00:00
|
|
|
def parse_widgets_urls
|
|
|
|
orig_content = content = self.file.read.force_encoding("UTF-8")
|
|
|
|
# self.remove_file!
|
|
|
|
# self.remove_file_orig!
|
|
|
|
names = []
|
|
|
|
images = self.desktop_widget.images
|
|
|
|
content.scan(/(?<=url)(.*?)(?=\))/){
|
|
|
|
css_name = $1.gsub(' ','').gsub('(','')
|
|
|
|
name = File.basename(css_name).gsub(/[\\\"]/, '')
|
|
|
|
image = images.detect{ |i| i.file_identifier.eql?(name) } rescue nil
|
|
|
|
image.update_attribute(:in_css, true) if image
|
|
|
|
file_name = image.file_url rescue nil
|
|
|
|
names << [css_name, file_name]
|
|
|
|
}
|
|
|
|
names.each do |name|
|
|
|
|
content.gsub!(name[0], name[1]) if name[1]
|
|
|
|
end
|
|
|
|
Dir.mktmpdir('f_path') { |dir|
|
|
|
|
orig_file_name = self.file_identifier
|
|
|
|
|
|
|
|
temp_file = File.new(dir + '/' + orig_file_name, 'w+')
|
|
|
|
temp_file.write orig_content.force_encoding("UTF-8")
|
|
|
|
self.file_orig = temp_file
|
|
|
|
|
|
|
|
temp_file = File.new(dir + '/' + orig_file_name, 'w+')
|
|
|
|
temp_file.write content.force_encoding("UTF-8")
|
|
|
|
self.file = temp_file
|
|
|
|
self.save
|
|
|
|
}
|
|
|
|
end
|
2011-09-13 03:57:20 +00:00
|
|
|
|
2011-07-12 08:02:41 +00:00
|
|
|
end
|