Module: TinyMCE

Defined in:
lib/tiny_mce/spell_checker.rb,
lib/tiny_mce.rb,
lib/tiny_mce/base.rb,
lib/tiny_mce/helpers.rb,
lib/tiny_mce/railtie.rb,
lib/tiny_mce/exceptions.rb,
lib/tiny_mce/configuration.rb

Overview

The base module we include into ActionController::Base

Defined Under Namespace

Modules: Base, Helpers, SpellChecker Classes: Configuration, Plugin, Railtie, TinyMCEInvalidOption, TinyMCEInvalidOptionType

Class Method Summary collapse

Class Method Details

.generate_new_lang(env_lang) ⇒ Object

this method generate new language to tinyMCE



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/tiny_mce.rb', line 73

def self.generate_new_lang(env_lang)
  
  puts "---------------------------------------------------------------------------------------"
  puts "\t\t TinyMCE Language Basic Generator"
  puts "---------------------------------------------------------------------------------------"
  unless env_lang.empty?
  
    lib_tinymce = File.join(File.dirname(__FILE__), 'tiny_mce')
    file = File.join(lib_tinymce, "valid_tinymce_langs.yml")
    yml_langs = YAML::load(File.open(file))

    unless yml_langs.include?(env_lang)
      yml_langs << env_lang
      yml_langs.sort!
  
      #writing new language to valid_tinymce_langs.yml
      File.open(file, 'w') do |f|
        f << "#\n# For more information about available languages, see\n"
        f <<  "# http://tinymce.moxiecode.com/download_i18n.php\n"
        f << "# Should only include a list of completed translations (not incomplete ones which most are :-( )\n#\n\n"
        f << YAML.dump(yml_langs).to_s
      end
       #start to copy en files to new lang
        puts "Generated \"en\" lang copies, translate this files:"
        puts "---------------------------------------------------------------------------------------"
        puts " REMEMBER TO CHANGE ALL THIS FILES."
        puts "IF YOU WANT TO TRANSLATE AN ESPECIFIC PLUGIN GO TO plugin/langs AND ADD YOUR LANG\n\n"
      
    else
      puts "\n\n\t\tLanguage exists on configuration file.\n\n" 
    end
  
    assets_path = File.join(lib_tinymce, 'assets', 'tiny_mce') 
    unless File.exists?(File.join(assets_path, 'langs',"#{env_lang}.js"))
      puts "\t- tiny_mce/lib/tiny_mce/assets/tiny_mce/langs/#{env_lang}.js"
      FileUtils.cp( File.join(assets_path, "langs", "en.js"), File.join(assets_path, "langs","#{env_lang}.js")) 
    end
    unless File.exists?(File.join(assets_path,"themes","advanced","langs","#{env_lang}.js"))
      puts "\t- tiny_mce/lib/tiny_mce/assets/tiny_mce/themes/advanced/langs/#{env_lang}.js"
      FileUtils.cp(File.join(assets_path,"themes","advanced","langs","en.js"), File.join(assets_path,"themes","advanced","langs","#{env_lang}.js")) 
    end
    unless File.exists?(File.join(assets_path,"themes","advanced","langs","#{env_lang}_dlg.js"))
      puts "\t- tiny_mce/lib/tiny_mce/assets/tiny_mce/themes/advanced/langs/#{env_lang}_dlg.js"
      FileUtils.cp(File.join(assets_path,"themes","advanced","langs","en_dlg.js"), File.join(assets_path,"themes","advanced","langs","#{env_lang}_dlg.js"))
    end
    unless File.exists?(File.join(assets_path,"themes","simple","langs","#{env_lang}.js"))
      puts "\t- tiny_mce/lib/tiny_mce/assets/tiny_mce/themes/simple/langs/#{env_lang}_dlg.js"
      FileUtils.cp(File.join(assets_path,"themes","simple","langs","en.js"), File.join(assets_path,"themes","simple","langs","#{env_lang}.js")) 
    end
  
    puts "---------------------------------------------------------------------------------------"
  
  else
    puts "You must set the LANG environment. example: rake tiny_mce:new:lang LANG=pt-BR"
  end
end

.initializeObject



9
10
11
12
13
14
15
16
# File 'lib/tiny_mce.rb', line 9

def self.initialize
  return if @intialized
  raise "ActionController is not available yet." unless defined?(ActionController)
  ActionController::Base.send(:include, TinyMCE::Base)
  ActionController::Base.send(:helper, TinyMCE::Helpers)
  TinyMCE.install_or_update_tinymce
  @intialized = true
end

.install_or_update_tinymceObject



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
# File 'lib/tiny_mce.rb', line 18

def self.install_or_update_tinymce
  require 'fileutils'
  orig = File.join(File.dirname(__FILE__), 'tiny_mce', 'assets', 'tiny_mce')
  dest = File.join(Rails.root.to_s, '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.to_s, '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