Module: Ckeditor::Utils
- Defined in:
- lib/ckeditor/utils.rb
Class Method Summary collapse
- .escape_single_quotes(str) ⇒ Object
- .filethumb(filename) ⇒ Object
- .js_fileuploader(uploader_type, options = {}) ⇒ Object
- .js_replace(dom_id, options = nil) ⇒ Object
- .parameterize_filename(filename) ⇒ Object
- .select_assets(path, relative_path) ⇒ Object
Class Method Details
.escape_single_quotes(str) ⇒ Object
7 8 9 |
# File 'lib/ckeditor/utils.rb', line 7 def escape_single_quotes(str) str.gsub('\\','\0\0').gsub('</','<\/').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" } end |
.filethumb(filename) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ckeditor/utils.rb', line 54 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
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 = ActiveSupport::JSON.encode().gsub /"EDITOR.config.filebrowser(.*)UploadUrl"/, 'EDITOR.config.filebrowser\1UploadUrl' "(function() { new qq.FileUploaderInput(#{}); }).call(this);".html_safe end |
.js_replace(dom_id, options = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ckeditor/utils.rb', line 20 def js_replace(dom_id, = nil) js = ["if (typeof CKEDITOR != 'undefined') {"] if && !.keys.empty? = ActiveSupport::JSON.encode() js << "CKEDITOR.replace('#{dom_id}', #{});" else js << "CKEDITOR.replace('#{dom_id}');" end js << "}" js.join(" ").html_safe end |
.parameterize_filename(filename) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/ckeditor/utils.rb', line 11 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
66 67 68 69 70 71 72 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 |
# File 'lib/ckeditor/utils.rb', line 66 def select_assets(path, relative_path) relative_folder = Ckeditor.root_path.join relative_path folder = relative_folder.join path extensions = '*.{js,css,png,gif,jpg,scss}' # Files at root files = Dir[folder.join(extensions)] # Plugins if Ckeditor.assets_plugins.nil? files += Dir[folder.join('plugins', '**', extensions)] else Ckeditor.assets_plugins.each do |plugin| files += Dir[folder.join('plugins', plugin, '**', extensions)] end end # Other folders Dir[folder.join('*/')].each do |subfolder| path = Pathname.new(subfolder) unless path.basename.to_s == 'plugins' files += Dir[path.join('**', extensions)] end end paths = files.map { |file| Pathname.new(file) } # Filter languages if Ckeditor.assets_languages.present? paths.select! do |path| path.dirname.basename.to_s != 'lang' || Ckeditor.assets_languages.include?(path.basename.to_s.split('.')[0]) end end paths.map { |path| path.relative_path_from(relative_folder).to_s.gsub('.scss', '') }.select { |path| path != 'ckeditor/ckeditor.js' } end |