Module: Ckeditor::Utils
- Defined in:
- lib/ckeditor/utils.rb
Defined Under Namespace
Classes: JavascriptCode
Class Method Summary collapse
- .escape_single_quotes(str) ⇒ Object
- .filethumb(filename) ⇒ Object
- .js_fileuploader(uploader_type, options = {}) ⇒ Object
- .js_replace(dom_id, options = {}) ⇒ Object
- .parameterize_filename(filename) ⇒ Object
- .select_assets(path, relative_path) ⇒ Object
Class Method Details
.escape_single_quotes(str) ⇒ Object
17 18 19 |
# File 'lib/ckeditor/utils.rb', line 17 def escape_single_quotes(str) str.gsub('\\','\0\0').gsub('</','<\/').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" } end |
.filethumb(filename) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ckeditor/utils.rb', line 59 def filethumb(filename) extname = filename.blank? ? "unknown" : File.extname(filename).gsub(/^\./, '') image = "#{extname}.gif" source = Ckeditor.root_path.join("app/assets/javascripts/ckeditor/filebrowser/images/thumbs") unless File.exists?(File.join(source, image)) image = "unknown.gif" end File.join(Ckeditor.relative_path, "filebrowser/images/thumbs", image) end |
.js_fileuploader(uploader_type, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ckeditor/utils.rb', line 39 def js_fileuploader(uploader_type, = {}) = { :multiple => true, :element => "fileupload" }.merge() case uploader_type.to_s.downcase when "image" then [:action] = JavascriptCode.new("EDITOR.config.filebrowserImageUploadUrl") [:allowedExtensions] = Ckeditor.image_file_types when "flash" then [:action] = JavascriptCode.new("EDITOR.config.filebrowserFlashUploadUrl") [:allowedExtensions] = ["swf"] else [:action] = JavascriptCode.new("EDITOR.config.filebrowserUploadUrl") [:allowedExtensions] = Ckeditor. end = ActiveSupport::JSON.encode() "(function() { new qq.FileUploaderInput(#{}); }).call(this);".html_safe end |
.js_replace(dom_id, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/ckeditor/utils.rb', line 30 def js_replace(dom_id, = {}) = ActiveSupport::JSON.encode() js = ["if (CKEDITOR.instances['#{dom_id}']) {CKEDITOR.remove(CKEDITOR.instances['#{dom_id}']);}"] js << "CKEDITOR.replace('#{dom_id}', #{});" "(function() { #{js.join} }).call(this);".html_safe end |
.parameterize_filename(filename) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/ckeditor/utils.rb', line 21 def parameterize_filename(filename) return filename unless Ckeditor.parameterize_filenames extension = File.extname(filename) basename = filename.gsub(/#{extension}$/, "") [basename.parameterize('_'), extension].join.downcase end |
.select_assets(path, relative_path) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/ckeditor/utils.rb', line 71 def select_assets(path, relative_path) folder = File.join(path, '**') relative_folder = Ckeditor.root_path.join(relative_path) Dir[Ckeditor.root_path.join(folder, '*.{js,css}')].inject([]) do |list, file| list << Pathname.new(file).relative_path_from(relative_folder).to_s list end end |