Module: Ckeditor::Utils
- Defined in:
- lib/ckeditor/utils.rb
Class Method Summary collapse
- .applay_options(options) ⇒ Object
- .escape_single_quotes(str) ⇒ Object
- .extract(filepath, output) ⇒ Object
- .js_fileuploader(uploader_type, options = {}) ⇒ Object
- .js_replace(dom_id, options = {}) ⇒ Object
- .parameterize_filename(filename) ⇒ Object
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 () str = [] .each do |key, value| item = case value when String then value.split(//).first == '^' ? value.slice(1..-1) : "'#{value}'" when Hash then "{ #{(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, = {}) = { :multiple => true, :element => "fileupload" }.merge() case uploader_type.to_s.downcase when "image" then [:action] = "^EDITOR.config.filebrowserImageUploadUrl" [:allowedExtensions] = Ckeditor.image_file_types when "flash" then [:action] = "^EDITOR.config.filebrowserFlashUploadUrl" [:allowedExtensions] = ["swf"] else [:action] = "^EDITOR.config.filebrowserUploadUrl" [:allowedExtensions] = Ckeditor. end = () "$(document).ready(function(){ new qq.FileUploaderInput({ #{} }); });" 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, = {}) = () js = ["if (CKEDITOR.instances['#{dom_id}']) {CKEDITOR.remove(CKEDITOR.instances['#{dom_id}']);}"] if .blank? js << "CKEDITOR.replace('#{dom_id}');" else js << "CKEDITOR.replace('#{dom_id}', { #{} });" 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 |