Module: Ckeditor::Utils

Defined in:
lib/ckeditor/utils.rb

Class Method Summary collapse

Class Method Details

.applay_options(options) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ckeditor/utils.rb', line 54

def applay_options(options)
  str = []
  
  options.each do |key, value|
    item = case value
      when String then
        value.split(//).first == '^' ? value.slice(1..-1) : "'#{value}'"
      when Hash then 
        "{ #{applay_options(value)} }"
      when Array then 
        arr = value.collect { |v| "'#{v}'" }
        "[ #{arr.join(',')} ]"
      else value
    end
    
    str << "#{key}: #{item}"
  end
  
  str.sort.join(',')
end

.escape_single_quotes(str) ⇒ Object



5
6
7
# File 'lib/ckeditor/utils.rb', line 5

def escape_single_quotes(str)
  str.gsub('\\','\0\0').gsub('</','<\/').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
end

.extract(filepath, output) ⇒ Object



16
17
18
19
# File 'lib/ckeditor/utils.rb', line 16

def extract(filepath, output)
  # TODO: need check system OS
  system("tar --exclude=*.php --exclude=*.asp -C '#{output}' -xzf '#{filepath}' ckeditor/")
end

.js_fileuploader(uploader_type, options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ckeditor/utils.rb', line 34

def js_fileuploader(uploader_type, options = {})
  options = { :multiple => true, :element => "fileupload" }.merge(options)
  
  case uploader_type.to_s.downcase
    when "image" then
      options[:action] = "^EDITOR.config.filebrowserImageUploadUrl"
      options[:allowedExtensions] = Ckeditor.image_file_types
    when "flash" then
      options[:action] = "^EDITOR.config.filebrowserFlashUploadUrl"
      options[:allowedExtensions] = ["swf"]
    else
      options[:action] = "^EDITOR.config.filebrowserUploadUrl"
      options[:allowedExtensions] = Ckeditor.attachment_file_types
  end
  
  js_options = applay_options(options)
  
  "$(document).ready(function(){ new qq.FileUploaderInput({ #{js_options} }); });"
end

.js_replace(dom_id, options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ckeditor/utils.rb', line 21

def js_replace(dom_id, options = {})
  js_options = applay_options(options)
  js = ["if (CKEDITOR.instances['#{dom_id}']) {CKEDITOR.remove(CKEDITOR.instances['#{dom_id}']);}"]
  
  if js_options.blank?
    js << "CKEDITOR.replace('#{dom_id}');"
  else
    js << "CKEDITOR.replace('#{dom_id}', { #{js_options} });"
  end
  
  js.join
end

.parameterize_filename(filename) ⇒ Object



9
10
11
12
13
14
# File 'lib/ckeditor/utils.rb', line 9

def parameterize_filename(filename)
  extension = File.extname(filename)
  basename = filename.gsub(/#{extension}$/, "")
  
  [basename.parameterize('_'), extension].join.downcase
end