Sha256: 4f1fd6e95c10f02c6f85c530d3e0fb79d00568a80ab27f5deac1bddf01e8064a

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require 'rails/generators'

module Ckeditor
  class BaseGenerator < Rails::Generators::Base
    class_option :version, :type => :string, :default => '3.6',
                 :desc => "Version of ckeditor which be install"

    def self.source_root
      @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
    end  
    
    # copy configuration
    def copy_initializer
      template "ckeditor.rb", "config/initializers/ckeditor.rb"
    end
    
    # copy ckeditor files
    def install_ckeditor
      puts "Start download #{filename}"
      file = Ckeditor::Utils.download(download_url)
      
      if File.exist?(file.path)
        Ckeditor::Utils.extract(file.path, Rails.root.join('public', 'javascripts'))
        directory "ckeditor", "public/javascripts/ckeditor"
        file.unlink
      else
        raise Rails::Generators::Error.new("Cannot download file #{download_url}")
      end
    end
    
    protected
    
      def download_url
        "http://download.cksource.com/CKEditor/CKEditor/CKEditor%20#{options[:version]}/ckeditor_#{options[:version]}.tar.gz"
      end
      
      def filename
        "ckeditor_#{options[:version]}.tar.gz"
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ckeditor-3.5.4 lib/generators/ckeditor/base/base_generator.rb