ckeditor_tasks.rake
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:3k
源码类别:

Ajax

开发平台:

Others

  1. # desc "Explaining what the task does"
  2. # task :ckeditor do
  3. #   # Task goes here
  4. # end
  5. namespace :ckeditor do
  6.   def setup
  7.     require "config/environment"
  8.     require 'fileutils'
  9.     directory = File.join(RAILS_ROOT, '/vendor/plugins/easy-ckeditor/')
  10.     require "#{directory}lib/ckeditor"
  11.     require "#{directory}lib/ckeditor_version"
  12.     require "#{directory}lib/ckeditor_file_utils"
  13.   end
  14.   desc 'Install the CKEditor components'
  15.   task :install do
  16.     setup
  17.     puts "** Installing CKEditor Plugin version #{CkeditorVersion.current}..."
  18.     CkeditorFileUtils.destroy_and_install
  19.     puts "** Successfully installed CKEditor Plugin version #{CkeditorVersion.current}"
  20.   end
  21.   desc 'Uninstall the CKEditor components'
  22.   task :uninstall do
  23.     setup
  24.     puts "** Uninstalling CKEditor Plugin version #{CkeditorVersion.current}..."
  25.     CkeditorFileUtils.destroy
  26.     puts "** Uninstalling Easy CKEditor Plugin Files..."
  27.     CkeditorFileUtils.rm_plugin
  28.     puts "** Successfully Uninstalled CKEditor Plugin version #{CkeditorVersion.current}"
  29.   end
  30.   def fetch(path)
  31.     response = Net::HTTP.get_response(URI.parse(path))
  32.     case response
  33.     when Net::HTTPSuccess     then
  34.       response
  35.     when Net::HTTPRedirection then
  36.       puts "** Redirected to #{response['location']}"
  37.       fetch(response['location'])
  38.     else
  39.       response.error!
  40.     end
  41.   end
  42.   desc "Update the CKEditor code to the latest nightly build"
  43.   task :download do
  44.     require 'net/http'
  45.     require 'zip/zipfilesystem'
  46.     setup
  47.     version = ENV['VERSION'] || "Nightly"
  48.     installed_version = "3.0"
  49.     puts "** Current CKEditor version: #{installed_version}..."
  50.     puts "** Downloading #{version} (please be patient)..."
  51.     rails_tmp_path = File.join(RAILS_ROOT, "/tmp/")
  52.     tmp_zip_path = File.join(rails_tmp_path, "ckeditor_#{version}.zip")
  53.     # Creating tmp dir if it doesn't exist
  54.     Dir.mkdir(rails_tmp_path) unless File.exists? rails_tmp_path
  55.     # Download nightly build (http://download.cksource.com/CKEditor/CKEditor/Nightly%20Build/ckeditor_nightly.zip)
  56.     # Releases (http://download.cksource.com/CKEditor/CKEditor/CKEditor%203.0/ckeditor_3.0.zip)
  57.     nightly = version=='Nightly' ? true : false
  58.     domain = "http://download.cksource.com"
  59.     path = nightly ? "/CKEditor/CKEditor/Nightly%20Build/ckeditor_nightly.zip" : "/CKEditor/CKEditor/CKEditor%203.0/ckeditor_#{version}.zip"
  60.     puts "** Download from #{domain}#{path}"
  61.     #Net::HTTP.start(domain) { |http|
  62.       response = fetch("#{domain}#{path}")
  63.       open(tmp_zip_path, "wb") { |file|
  64.         file.write(response.body)
  65.       }
  66.     #}
  67.     puts "** Download successful"
  68.     puts "** Extracting CKeditor"
  69.     Zip::ZipFile.open(tmp_zip_path) do |zipfile|
  70.       zipfile.each do |entry|
  71.         filename = File.join(rails_tmp_path, entry.name)
  72.         FileUtils.rm_f(filename)
  73.         FileUtils.mkdir_p(File.dirname(filename))
  74.         entry.extract(filename)
  75.       end
  76.     end
  77.     puts "** Backing up existing CKEditor install to /public/javascripts/ckeditor_bck"
  78.     CkeditorFileUtils.backup_existing
  79.     puts "** Shifting files to /public/javascripts/ckeditor"
  80.     FileUtils.cp_r File.join(RAILS_ROOT, "/tmp/ckeditor/"), File.join(RAILS_ROOT, "/public/javascripts/")
  81.     puts "** Clean up"
  82.     FileUtils.remove_file(tmp_zip_path, true)
  83.     FileUtils.remove_entry(File.join(rails_tmp_path, "ckeditor/"), true)
  84.     puts "** Successfully updated to CKEditor version: #{version}..."
  85.   end
  86. end