Upload Desktop themes

This commit is contained in:
RulingDigital 2013-12-26 14:13:34 +08:00
parent b51030ac14
commit a1a15775e9
10 changed files with 28 additions and 1 deletions

View File

@ -15,7 +15,7 @@ class DesktopController< ApplicationController
@desktop.save! @desktop.save!
end end
@currentusername = current_user.name @currentusername = current_user.name
@currentname = current_user.first_name + current_user.last_name @currentname = current_user.first_name + current_user.last_name rescue ""
@title = "Desktop - " + @currentusername @title = "Desktop - " + @currentusername
@section = @desktop.sections.first @section = @desktop.sections.first
end end

Binary file not shown.

BIN
lib/desktop_themes/Mars.zip Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -21,10 +21,37 @@ namespace :desktop do
# flash[:error] = "Upload file should be in zip format" # flash[:error] = "Upload file should be in zip format"
#end #end
temp_file.close temp_file.close
Dir.glob("#{Rails.root}/lib/desktop_themes/*.zip").each do |theme_zip|
upload_desktop_theme(theme_zip,File.basename(theme_zip, ".zip"))
end
end end
Rake::Task["tiles:destroy_build_tiles"].execute Rake::Task["tiles:destroy_build_tiles"].execute
end end
def upload_desktop_theme(file, zip_name)
Zip::ZipFile.open(file) { |zip_file|
dt = DesktopTheme.new.from_json(zip_file.read("#{zip_name}/settings.json"))
Dir.mktmpdir('f_path') { |dir|
images_entries = []
zip_file.entries.each do |entry|
case (path = entry.to_s)
when /\A(#{zip_name})\/(theme\.css)\z/ #for default css
dt.build_css_default(:file => get_temp_file(zip_file, dir, entry))
when /\A(#{zip_name})\/(background)\/.*((\.jpg)|(\.png)|(\.gif))\z/ #for img
images_entries << entry
end
end
images_entries.each do |image|
dt.images.build(:file => get_temp_file(zip_file,dir,image))
end
}
dt.save
}
end
def unzip_widget(file, zip_name) def unzip_widget(file, zip_name)
Zip::ZipFile.open(file) { |zip_file| Zip::ZipFile.open(file) { |zip_file|
dw = DesktopWidget.new.from_json(zip_file.read("#{zip_name}/settings.json")) dw = DesktopWidget.new.from_json(zip_file.read("#{zip_name}/settings.json"))