forked from kete/tiny_mce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tiny_mce.rb
73 lines (68 loc) · 2.33 KB
/
tiny_mce.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Require all the necessary files to run TinyMCE
require 'tiny_mce/base'
require 'tiny_mce/exceptions'
require 'tiny_mce/configuration'
require 'tiny_mce/spell_checker'
require 'tiny_mce/helpers'
module TinyMCE
def self.install_or_update_tinymce
require 'fileutils'
orig = File.join(File.dirname(__FILE__), 'tiny_mce', 'assets', 'tiny_mce')
dest = File.join(Rails.root, 'public', 'javascripts', 'tiny_mce')
tiny_mce_js = File.join(dest, 'tiny_mce.js')
unless File.exists?(tiny_mce_js) && FileUtils.identical?(File.join(orig, 'tiny_mce.js'), tiny_mce_js)
if File.exists?(tiny_mce_js)
# upgrade
begin
puts "Removing directory #{dest}..."
FileUtils.rm_rf dest
puts "Creating directory #{dest}..."
FileUtils.mkdir_p dest
puts "Copying TinyMCE to #{dest}..."
FileUtils.cp_r "#{orig}/.", dest
puts "Successfully updated TinyMCE."
rescue
puts 'ERROR: Problem updating TinyMCE. Please manually copy '
puts orig
puts 'to'
puts dest
end
else
# install
begin
puts "Creating directory #{dest}..."
FileUtils.mkdir_p dest
puts "Copying TinyMCE to #{dest}..."
FileUtils.cp_r "#{orig}/.", dest
puts "Successfully installed TinyMCE."
rescue
puts "ERROR: Problem installing TinyMCE. Please manually copy "
puts orig
puts "to"
puts dest
end
end
end
tiny_mce_yaml_filepath = File.join(Rails.root, 'config', 'tiny_mce.yml')
unless File.exists?(tiny_mce_yaml_filepath)
File.open(tiny_mce_yaml_filepath, 'w') do |f|
f.puts '# Here you can specify default options for TinyMCE across all controllers'
f.puts '#'
f.puts '# theme: advanced'
f.puts '# plugins:'
f.puts '# - table'
f.puts '# - fullscreen'
end
puts "Written configuration example to #{tiny_mce_yaml_filepath}"
end
end
module Base
include TinyMCE::SpellChecker
end
end
# Include the TinyMCE methods and TinyMCE Helpers into ActionController::Base
if defined?(Rails) && defined?(ActionController)
ActionController::Base.send(:include, TinyMCE::Base)
ActionController::Base.send(:helper, TinyMCE::Helpers)
TinyMCE.install_or_update_tinymce
end