Class: TinyMCE::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/tiny_mce.rb

Overview

Plugin Support

Class Method Summary collapse

Class Method Details

.installObject



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/tiny_mce.rb', line 137

def self.install
  return unless File.directory?(self.assets_path)
  require 'fileutils'

  # public/javascripts/tiny_mce/plugins/imageselector/editor_plugin.js 
  assests_plugins_path = File.join(self.assets_path, 'plugins')

  # check if plugin subdirectory is the same as already under tiny_mce/plugins
  plugin_source_path = Dir[File.join(self.assets_path, 'plugins', '*')][0]
  plugin_directory_name = File.basename(plugin_source_path)
  destination_source_path = File.join(Rails.root.to_s,
                                      'public',
                                      'javascripts',
                                      'tiny_mce',
                                      'plugins',
                                      plugin_directory_name)

  # diff will return differences if there are any or empty string if not
  if !File.exist?(destination_source_path) || `diff -r #{plugin_source_path} #{destination_source_path}`.present?
    puts "Installing #{self.name} plugin assets from #{self.assets_path}"
    FileUtils.cp_r "#{self.assets_path}/.", File.join(Rails.root.to_s, 'public', 'javascripts', 'tiny_mce')
  end
end