From 72745d257d582792f5621589e0a0297b40e5b7b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 26 Jun 2013 21:53:31 +0200 Subject: [PATCH] provide a way to give a default filename to pasted images in the lightbox overlay --- config/locales/server.cs.yml | 1 + config/locales/server.da.yml | 3 +++ config/locales/server.de.yml | 1 + config/locales/server.en.yml | 1 + config/locales/server.es.yml | 3 +++ config/locales/server.fr.yml | 3 ++- config/locales/server.id.yml | 3 +++ config/locales/server.it.yml | 1 + config/locales/server.nl.yml | 1 + config/locales/server.pseudo.yml | 1 + config/locales/server.pt.yml | 3 +++ config/locales/server.ru.yml | 1 + config/locales/server.sv.yml | 3 +++ config/locales/server.zh_CN.yml | 1 + config/locales/server.zh_TW.yml | 1 + lib/cooked_post_processor.rb | 10 +++++++--- spec/components/cooked_post_processor_spec.rb | 18 ++++++++++++++++++ 17 files changed, 51 insertions(+), 4 deletions(-) diff --git a/config/locales/server.cs.yml b/config/locales/server.cs.yml index 00cd37708..41af43aed 100644 --- a/config/locales/server.cs.yml +++ b/config/locales/server.cs.yml @@ -1045,6 +1045,7 @@ cs: deleted: 'smazáno' upload: + pasted_image_filename: "" image: fetch_failure: "Bohužel, nastala chybí při získávání obrázku." unknown_image_type: "Bohužel, soubor, který se snažíte nahrát, zřejmě není obrázek." diff --git a/config/locales/server.da.yml b/config/locales/server.da.yml index 7aad03850..b41a1d11c 100644 --- a/config/locales/server.da.yml +++ b/config/locales/server.da.yml @@ -783,3 +783,6 @@ da: see_more: "Se mere" search_title: "Søg efter dette emne" search_google: "Søg Google" + + upload: + pasted_image_filename: "" diff --git a/config/locales/server.de.yml b/config/locales/server.de.yml index 04af0aa94..a2e8f5302 100644 --- a/config/locales/server.de.yml +++ b/config/locales/server.de.yml @@ -1005,6 +1005,7 @@ de: deleted: 'gelöscht' upload: + pasted_image_filename: "" image: fetch_failure: "Entschuldige, beim Laden des Bildes ist ein Fehler aufgetreten." unknown_image_type: "Entschuldige, aber die Datei die Du hochladen möchtest schein kein Bild zu sein." diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index bc8cf1158..4c47aff6b 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1039,6 +1039,7 @@ en: deleted: 'deleted' upload: + pasted_image_filename: "Pasted image" image: fetch_failure: "Sorry, there has been an error while fetching the image." unknown_image_type: "Sorry, but the file you tried to upload doesn't appear to be an image." diff --git a/config/locales/server.es.yml b/config/locales/server.es.yml index 7f7587496..7ec111605 100644 --- a/config/locales/server.es.yml +++ b/config/locales/server.es.yml @@ -763,3 +763,6 @@ es: see_more: "Ver Más" search_title: "Buscar por este tema" search_google: "Buscar en Google" + + upload: + pasted_image_filename: "" diff --git a/config/locales/server.fr.yml b/config/locales/server.fr.yml index 46cf4d5f0..af98204b6 100644 --- a/config/locales/server.fr.yml +++ b/config/locales/server.fr.yml @@ -551,7 +551,7 @@ fr: enable_s3_uploads: "S'il faut ou non uploader sur s3" s3_upload_bucket: "Le bucket dans lequel uploader sur s3" s3_secret_access_key: "La clé secrète Amazon S3 qui va être utilisée pour uploader des images" - s3_region: "Le nom de la région Amazon S3 qui va être utilisée pour uploader des images" + s3_region: "Le nom de la région Amazon S3 qui va être utilisée pour uploader des images" default_invitee_trust_level: "Le niveau de confiance par défaut des utilisateurs invités" default_trust_level: "Le niveau de confiance par défaut des utilisateurs" @@ -944,6 +944,7 @@ fr: deleted: 'supprimmé' upload: + pasted_image_filename: "Image collée" image: fetch_failure: "Désolé, une erreur s'est produite lorsque nous avons essayé de récupérer l'image." unknown_image_type: "Désolé, mais le fichier que vous essayez d'envoyer ne semble pas être une image." diff --git a/config/locales/server.id.yml b/config/locales/server.id.yml index 081c15a9f..4dfefe491 100644 --- a/config/locales/server.id.yml +++ b/config/locales/server.id.yml @@ -780,3 +780,6 @@ id: see_more: "See More" search_title: "Search for this topic" search_google: "Search Google" + + upload: + pasted_image_filename: "" diff --git a/config/locales/server.it.yml b/config/locales/server.it.yml index 55d95ecef..a7849ebc7 100644 --- a/config/locales/server.it.yml +++ b/config/locales/server.it.yml @@ -918,6 +918,7 @@ it: deleted: 'cancellato' upload: + pasted_image_filename: "" image: fetch_failure: "Spiacente, si è verificato un errore nel recupero dell'immagine." unknown_image_type: "Spiacente, ma il file che hai provato a caricare non sembra un'immagine." diff --git a/config/locales/server.nl.yml b/config/locales/server.nl.yml index d448649d5..9ac314774 100644 --- a/config/locales/server.nl.yml +++ b/config/locales/server.nl.yml @@ -970,6 +970,7 @@ nl: deleted: 'verwijderd' upload: + pasted_image_filename: "" image: fetch_failure: "Er ging iets mis bij het opvragen van de afbeelding." unknown_image_type: "Het bestand dat je wil uploaden is geen afbeelding." diff --git a/config/locales/server.pseudo.yml b/config/locales/server.pseudo.yml index 34e9740c7..1f86e438c 100644 --- a/config/locales/server.pseudo.yml +++ b/config/locales/server.pseudo.yml @@ -1075,6 +1075,7 @@ pseudo: áɳď ƿéřɱíťťéď áššíǧɳš. ]]' deleted: '[[ ďéłéťéď ]]' upload: + pasted_image_filename: "" image: fetch_failure: '[[ Šóřřý, ťĥéřé ĥáš ƀééɳ áɳ éřřóř ŵĥíłé ƒéťčĥíɳǧ ťĥé íɱáǧé. ]]' diff --git a/config/locales/server.pt.yml b/config/locales/server.pt.yml index 4554645da..3c59830ca 100644 --- a/config/locales/server.pt.yml +++ b/config/locales/server.pt.yml @@ -682,3 +682,6 @@ pt: discourse_hub: access_token_problem: "Conta a um admin: Por-favor atualiza as configurações do site para incluir o discourse_org_access_key correto." + + upload: + pasted_image_filename: "" diff --git a/config/locales/server.ru.yml b/config/locales/server.ru.yml index 73404f058..9eeceb36f 100644 --- a/config/locales/server.ru.yml +++ b/config/locales/server.ru.yml @@ -1023,6 +1023,7 @@ ru: miscellaneous: 'This Agreement constitutes the entire agreement between %{company_short_name} and you concerning the subject matter hereof, and they may only be modified by a written amendment signed by an authorized executive of %{company_short_name}, or by the posting by %{company_short_name} of a revised version. Except to the extent applicable law, if any, provides otherwise, this Agreement, any access to or use of the Website will be governed by the laws of the state of California, U.S.A., excluding its conflict of law provisions, and the proper venue for any disputes arising out of or relating to any of the same will be the state and federal courts located in San Francisco County, California. Except for claims for injunctive or equitable relief or claims regarding intellectual property rights (which may be brought in any competent court without the posting of a bond), any dispute arising under this Agreement shall be finally settled in accordance with the Comprehensive Arbitration Rules of the Judicial Arbitration and Mediation Service, Inc. (“JAMS”) by three arbitrators appointed in accordance with such Rules. The arbitration shall take place in San Francisco, California, in the English language and the arbitral decision may be enforced in any court. The prevailing party in any action or proceeding to enforce this Agreement shall be entitled to costs and attorneys’ fees. If any part of this Agreement is held invalid or unenforceable, that part will be construed to reflect the parties’ original intent, and the remaining portions will remain in full force and effect. A waiver by either party of any term or condition of this Agreement or any breach thereof, in any one instance, will not waive such term or condition or any subsequent breach thereof. You may assign your rights under this Agreement to any party that consents to, and agrees to be bound by, its terms and conditions; %{company_short_name} may assign its rights under this Agreement without condition. This Agreement will be binding upon and will inure to the benefit of the parties, their successors and permitted assigns.' deleted: удалено upload: + pasted_image_filename: "" image: fetch_failure: Извините, во время извлечения изображения произошла ошибка. unknown_image_type: Файл, который вы загружаете, не является изображением. diff --git a/config/locales/server.sv.yml b/config/locales/server.sv.yml index 20f664588..7f19fccc1 100644 --- a/config/locales/server.sv.yml +++ b/config/locales/server.sv.yml @@ -838,3 +838,6 @@ sv: see_more: "See More" search_title: "Search for this topic" search_google: "Search Google" + + upload: + pasted_image_filename: "" diff --git a/config/locales/server.zh_CN.yml b/config/locales/server.zh_CN.yml index 440900c38..48bb9253a 100644 --- a/config/locales/server.zh_CN.yml +++ b/config/locales/server.zh_CN.yml @@ -932,6 +932,7 @@ zh_CN: deleted: '已删除' upload: + pasted_image_filename: "" image: fetch_failure: "抱歉,获取图片時发生错误。" unknown_image_type: "抱歉,你上传的文件似乎不是一张图片。" diff --git a/config/locales/server.zh_TW.yml b/config/locales/server.zh_TW.yml index ad7b54a0f..5524d4680 100644 --- a/config/locales/server.zh_TW.yml +++ b/config/locales/server.zh_TW.yml @@ -918,6 +918,7 @@ zh_TW: deleted: '已刪除' upload: + pasted_image_filename: "" image: fetch_failure: "抱歉,獲取圖片時發生錯誤。" unknown_image_type: "抱歉,你上傳的文件似乎不是一張圖片。" diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 714b456c6..7b6cb5edd 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -141,19 +141,23 @@ class CookedPostProcessor meta["class"] = "meta" img.add_next_sibling meta - filename = upload ? upload.original_filename : File.basename(src) + filename = get_filename(upload, src) informations = "#{original_width}x#{original_height}" informations << " | #{number_to_human_size(upload.filesize)}" if upload meta.add_child create_span_node("filename", filename) meta.add_child create_span_node("informations", informations) meta.add_child create_span_node("expand") - # TODO: download - # TODO: views-count @dirty = true end + def get_filename(upload, src) + return File.basename(src) unless upload + return upload.original_filename unless upload.original_filename == "blob" + return I18n.t('upload.pasted_image_filename') + end + def create_span_node(klass, content=nil) span = Nokogiri::XML::Node.new "span", @doc span.content = content if content diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index c54fe8601..018f7af99 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -218,4 +218,22 @@ describe CookedPostProcessor do end + context 'get_filename' do + + it "returns the filename of the src when there is no upload" do + cpp.get_filename(nil, "http://domain.com/image.png").should == "image.png" + end + + it "returns the original filename of the upload when there is an upload" do + upload = Fabricate.build(:upload, { original_filename: "upload.jpg" }) + cpp.get_filename(upload, "http://domain.com/image.png").should == "upload.jpg" + end + + it "returns a generic name for pasted images" do + upload = Fabricate.build(:upload, { original_filename: "blob" }) + cpp.get_filename(upload, "http://domain.com/image.png").should == I18n.t('upload.pasted_image_filename') + end + + end + end