mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
Merge pull request #1155 from ZogStriP/remove-auto-link-images-wider-than-setting
removed auto_link_images_wider_than setting
This commit is contained in:
commit
337f393af5
@ -106,7 +106,6 @@ class SiteSetting < ActiveRecord::Base
|
|||||||
setting(:max_flags_per_day, 20)
|
setting(:max_flags_per_day, 20)
|
||||||
setting(:max_edits_per_day, 30)
|
setting(:max_edits_per_day, 30)
|
||||||
setting(:max_favorites_per_day, 20)
|
setting(:max_favorites_per_day, 20)
|
||||||
setting(:auto_link_images_wider_than, 50)
|
|
||||||
|
|
||||||
setting(:email_time_window_mins, 10)
|
setting(:email_time_window_mins, 10)
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class Upload < ActiveRecord::Base
|
|||||||
def create_thumbnail!
|
def create_thumbnail!
|
||||||
return unless SiteSetting.create_thumbnails?
|
return unless SiteSetting.create_thumbnails?
|
||||||
return if SiteSetting.enable_s3_uploads?
|
return if SiteSetting.enable_s3_uploads?
|
||||||
return unless width > SiteSetting.auto_link_images_wider_than
|
return if width < SiteSetting.max_image_width
|
||||||
return if has_thumbnail?
|
return if has_thumbnail?
|
||||||
thumbnail = OptimizedImage.create_for(self, width, height)
|
thumbnail = OptimizedImage.create_for(self, width, height)
|
||||||
optimized_images << thumbnail if thumbnail
|
optimized_images << thumbnail if thumbnail
|
||||||
|
@ -624,7 +624,6 @@ cs:
|
|||||||
max_mentions_per_post: "Maximální počet zmínek přes @name, které mohou být použity v jednom příspěvku"
|
max_mentions_per_post: "Maximální počet zmínek přes @name, které mohou být použity v jednom příspěvku"
|
||||||
|
|
||||||
create_thumbnails: "Vytvářet náhledy pro obrázky v lightboxu"
|
create_thumbnails: "Vytvářet náhledy pro obrázky v lightboxu"
|
||||||
auto_link_images_wider_than: "Obrázky širší než tato hodnota v pixelech budou odkazovány do lightboxu"
|
|
||||||
|
|
||||||
email_time_window_mins: "Kolik minut se čeká než se uživateli zašle email, aby měl možnost obsah vidět sám od sebe"
|
email_time_window_mins: "Kolik minut se čeká než se uživateli zašle email, aby měl možnost obsah vidět sám od sebe"
|
||||||
flush_timings_secs: "Jak často se vynulují časovací data na serveru, v sekundách"
|
flush_timings_secs: "Jak často se vynulují časovací data na serveru, v sekundách"
|
||||||
|
@ -411,8 +411,6 @@ da:
|
|||||||
basic_requires_read_posts: "How many posts a new user must read before promotion to basic (1) trust level"
|
basic_requires_read_posts: "How many posts a new user must read before promotion to basic (1) trust level"
|
||||||
basic_requires_time_spent_mins: "How many minutes a new user must read posts before promotion to basic (1) trust level"
|
basic_requires_time_spent_mins: "How many minutes a new user must read posts before promotion to basic (1) trust level"
|
||||||
|
|
||||||
auto_link_images_wider_than: "Images wider than this, in pixels, will get auto link and lightbox treatment"
|
|
||||||
|
|
||||||
email_time_window_mins: "How many minutes we wait before sending a user mail, to give them a chance to see it first"
|
email_time_window_mins: "How many minutes we wait before sending a user mail, to give them a chance to see it first"
|
||||||
flush_timings_secs: "How frequently we flush timing data to the server, in seconds"
|
flush_timings_secs: "How frequently we flush timing data to the server, in seconds"
|
||||||
max_word_length: "The maximum allowed word length, in characters, in a topic title"
|
max_word_length: "The maximum allowed word length, in characters, in a topic title"
|
||||||
|
@ -580,8 +580,6 @@ de:
|
|||||||
newuser_max_mentions_per_post: "Maximale Zahl der @Namens-Erwähnungen, die neue Benutzer in Beiträgen nutzen dürfen."
|
newuser_max_mentions_per_post: "Maximale Zahl der @Namens-Erwähnungen, die neue Benutzer in Beiträgen nutzen dürfen."
|
||||||
max_mentions_per_post: "Maximale Zahl der @Namens-Erwähnungen, die man in einem Beitrag nutzen kann."
|
max_mentions_per_post: "Maximale Zahl der @Namens-Erwähnungen, die man in einem Beitrag nutzen kann."
|
||||||
|
|
||||||
auto_link_images_wider_than: "Pixelbreite, ab der Bilder automatisch verlinkt und verkleinert in einer Lightbox dargestellt werden."
|
|
||||||
|
|
||||||
email_time_window_mins: "Minuten Wartezeit, bevor eine Mail an Nutzer verschickt wird, um ihnen die Chance zu geben, eine Neuigkeit zuerst zu sehen."
|
email_time_window_mins: "Minuten Wartezeit, bevor eine Mail an Nutzer verschickt wird, um ihnen die Chance zu geben, eine Neuigkeit zuerst zu sehen."
|
||||||
flush_timings_secs: "Sekunden, nach denen Zeiteinstellungen auf den Server übertragen werden."
|
flush_timings_secs: "Sekunden, nach denen Zeiteinstellungen auf den Server übertragen werden."
|
||||||
max_word_length: "Maximale Wortlänge in Zeichen in Thementiteln."
|
max_word_length: "Maximale Wortlänge in Zeichen in Thementiteln."
|
||||||
|
@ -602,7 +602,6 @@ en:
|
|||||||
max_mentions_per_post: "Maximum number of @name notifications you can use in a post"
|
max_mentions_per_post: "Maximum number of @name notifications you can use in a post"
|
||||||
|
|
||||||
create_thumbnails: "Create thumbnails for lightboxed images"
|
create_thumbnails: "Create thumbnails for lightboxed images"
|
||||||
auto_link_images_wider_than: "Images wider than this, in pixels, will get auto link and lightbox treatment"
|
|
||||||
|
|
||||||
email_time_window_mins: "How many minutes we wait before sending a user mail, to give them a chance to see it first"
|
email_time_window_mins: "How many minutes we wait before sending a user mail, to give them a chance to see it first"
|
||||||
flush_timings_secs: "How frequently we flush timing data to the server, in seconds"
|
flush_timings_secs: "How frequently we flush timing data to the server, in seconds"
|
||||||
|
@ -399,8 +399,6 @@ es:
|
|||||||
basic_requires_read_posts: "Cuantos post debe un usuario leer antes de ser promocionado al nivel básico (1) de confianza"
|
basic_requires_read_posts: "Cuantos post debe un usuario leer antes de ser promocionado al nivel básico (1) de confianza"
|
||||||
basic_requires_time_spent_mins: "Cuantos minutos un usuario debe leer posts antes de ser promocionado al nivel básico (1) de confianza"
|
basic_requires_time_spent_mins: "Cuantos minutos un usuario debe leer posts antes de ser promocionado al nivel básico (1) de confianza"
|
||||||
|
|
||||||
auto_link_images_wider_than: "Imágenes más amplias que esto, en píxeles, tendrán un tratamiento de lightbox y auto link"
|
|
||||||
|
|
||||||
email_time_window_mins: "Cuantos minutos esperamos antes de enviar un mail a un usuario, para darles la oportunidad de verlo antes"
|
email_time_window_mins: "Cuantos minutos esperamos antes de enviar un mail a un usuario, para darles la oportunidad de verlo antes"
|
||||||
flush_timings_secs: "How frequently we flush timing data to the server, in seconds"
|
flush_timings_secs: "How frequently we flush timing data to the server, in seconds"
|
||||||
max_word_length: "La máxima longitud de palabra permitida, en caracteres en el título de un topic"
|
max_word_length: "La máxima longitud de palabra permitida, en caracteres en el título de un topic"
|
||||||
|
@ -570,8 +570,6 @@ fr:
|
|||||||
regular_requires_likes_given: "Combien de j'aime un utilisateur doit donner pour être promu au niveau régulier (2)"
|
regular_requires_likes_given: "Combien de j'aime un utilisateur doit donner pour être promu au niveau régulier (2)"
|
||||||
regular_requires_topic_reply_count: "Combien de réponses un utilisateur doit donner pour être promu au niveau régulier (2)"
|
regular_requires_topic_reply_count: "Combien de réponses un utilisateur doit donner pour être promu au niveau régulier (2)"
|
||||||
|
|
||||||
auto_link_images_wider_than: "Les images en lien automatiques doivent êtres plus larges que préciser"
|
|
||||||
|
|
||||||
email_time_window_mins: "Combien de minutes attendre avant d'envoyer un mail à l'utilisateur, pour lui donner une chance de voir lui-même avant l'envoi."
|
email_time_window_mins: "Combien de minutes attendre avant d'envoyer un mail à l'utilisateur, pour lui donner une chance de voir lui-même avant l'envoi."
|
||||||
flush_timings_secs: "A quelle fréquence requêter les données de timing au serveur, en secondes."
|
flush_timings_secs: "A quelle fréquence requêter les données de timing au serveur, en secondes."
|
||||||
max_word_length: "Le nombre maximum de mots dans un titre de discussion"
|
max_word_length: "Le nombre maximum de mots dans un titre de discussion"
|
||||||
|
@ -411,8 +411,6 @@ id:
|
|||||||
basic_requires_read_posts: "How many posts a new user must read before promotion to basic (1) trust level"
|
basic_requires_read_posts: "How many posts a new user must read before promotion to basic (1) trust level"
|
||||||
basic_requires_time_spent_mins: "How many minutes a new user must read posts before promotion to basic (1) trust level"
|
basic_requires_time_spent_mins: "How many minutes a new user must read posts before promotion to basic (1) trust level"
|
||||||
|
|
||||||
auto_link_images_wider_than: "Images wider than this, in pixels, will get auto link and lightbox treatment"
|
|
||||||
|
|
||||||
email_time_window_mins: "How many minutes we wait before sending a user mail, to give them a chance to see it first"
|
email_time_window_mins: "How many minutes we wait before sending a user mail, to give them a chance to see it first"
|
||||||
flush_timings_secs: "How frequently we flush timing data to the server, in seconds"
|
flush_timings_secs: "How frequently we flush timing data to the server, in seconds"
|
||||||
max_word_length: "The maximum allowed word length, in characters, in a topic title"
|
max_word_length: "The maximum allowed word length, in characters, in a topic title"
|
||||||
|
@ -548,8 +548,6 @@ it:
|
|||||||
newuser_max_mentions_per_post: "Numero massimo di menzioni @name che un nuovo utente può fare in un post"
|
newuser_max_mentions_per_post: "Numero massimo di menzioni @name che un nuovo utente può fare in un post"
|
||||||
max_mentions_per_post: "Numero massimo di menzioni @name che un utente può fare in un post"
|
max_mentions_per_post: "Numero massimo di menzioni @name che un utente può fare in un post"
|
||||||
|
|
||||||
auto_link_images_wider_than: "Immagini più larghe di questo valore (in pixel) verranno visualizzate tramite lightbox"
|
|
||||||
|
|
||||||
email_time_window_mins: "Quanti minuti prima che una email venga mandata all'utente, per dare la possibilità di controllarla"
|
email_time_window_mins: "Quanti minuti prima che una email venga mandata all'utente, per dare la possibilità di controllarla"
|
||||||
flush_timings_secs: "Frequenza di aggiornamento dati temporali (su server), in secondi"
|
flush_timings_secs: "Frequenza di aggiornamento dati temporali (su server), in secondi"
|
||||||
max_word_length: "Numero massimo di caratteri che compongono una parola del titolo di un topic"
|
max_word_length: "Numero massimo di caratteri che compongono una parola del titolo di un topic"
|
||||||
|
@ -574,8 +574,6 @@ nl:
|
|||||||
newuser_max_mentions_per_post: "Maximum aantal @naam notificaties dat een nieuw lid in een bericht kan gebruiken"
|
newuser_max_mentions_per_post: "Maximum aantal @naam notificaties dat een nieuw lid in een bericht kan gebruiken"
|
||||||
max_mentions_per_post: "Maximum aantal @naam notificaties dat je in een bericht kan gebruiken"
|
max_mentions_per_post: "Maximum aantal @naam notificaties dat je in een bericht kan gebruiken"
|
||||||
|
|
||||||
auto_link_images_wider_than: "Afbeeldingen breder dan dit, in pixels, krijgen automatisch een link naar een lightbox"
|
|
||||||
|
|
||||||
email_time_window_mins: "Hoeveel minuten we wachten met het sturen van een e-mail naar een persoon, om ze een kans te geven het eerst op de site te kunnen lezen."
|
email_time_window_mins: "Hoeveel minuten we wachten met het sturen van een e-mail naar een persoon, om ze een kans te geven het eerst op de site te kunnen lezen."
|
||||||
flush_timings_secs: "Hoe vaak we timing-data naar de server sturen, in seconden."
|
flush_timings_secs: "Hoe vaak we timing-data naar de server sturen, in seconden."
|
||||||
max_word_length: "De maximumlengte van een woord in een topictitel"
|
max_word_length: "De maximumlengte van een woord in een topictitel"
|
||||||
|
@ -657,8 +657,6 @@ pseudo:
|
|||||||
ůšéř čáɳ ůšé íɳ á ƿóšť ]]'
|
ůšéř čáɳ ůšé íɳ á ƿóšť ]]'
|
||||||
max_mentions_per_post: '[[ Ϻáхíɱůɱ ɳůɱƀéř óƒ @ɳáɱé ɳóťíƒíčáťíóɳš ýóů čáɳ ůšé íɳ
|
max_mentions_per_post: '[[ Ϻáхíɱůɱ ɳůɱƀéř óƒ @ɳáɱé ɳóťíƒíčáťíóɳš ýóů čáɳ ůšé íɳ
|
||||||
á ƿóšť ]]'
|
á ƿóšť ]]'
|
||||||
auto_link_images_wider_than: '[[ Íɱáǧéš ŵíďéř ťĥáɳ ťĥíš, íɳ ƿíхéłš, ŵíłł ǧéť áůťó
|
|
||||||
łíɳǩ áɳď łíǧĥťƀóх ťřéáťɱéɳť ]]'
|
|
||||||
email_time_window_mins: '[[ Ĥóŵ ɱáɳý ɱíɳůťéš ŵé ŵáíť ƀéƒóřé šéɳďíɳǧ á ůšéř ɱáíł,
|
email_time_window_mins: '[[ Ĥóŵ ɱáɳý ɱíɳůťéš ŵé ŵáíť ƀéƒóřé šéɳďíɳǧ á ůšéř ɱáíł,
|
||||||
ťó ǧíνé ťĥéɱ á čĥáɳčé ťó šéé íť ƒířšť ]]'
|
ťó ǧíνé ťĥéɱ á čĥáɳčé ťó šéé íť ƒířšť ]]'
|
||||||
flush_timings_secs: '[[ Ĥóŵ ƒřéƣůéɳťłý ŵé ƒłůšĥ ťíɱíɳǧ ďáťá ťó ťĥé šéřνéř, íɳ
|
flush_timings_secs: '[[ Ĥóŵ ƒřéƣůéɳťłý ŵé ƒłůšĥ ťíɱíɳǧ ďáťá ťó ťĥé šéřνéř, íɳ
|
||||||
|
@ -339,8 +339,6 @@ pt:
|
|||||||
basic_requires_read_posts: "How many posts a user needs to have read to be promoted to basic level"
|
basic_requires_read_posts: "How many posts a user needs to have read to be promoted to basic level"
|
||||||
basic_requires_time_spent_mins: "How many mins a user needs to have spent reading posts to be promoted to basic level"
|
basic_requires_time_spent_mins: "How many mins a user needs to have spent reading posts to be promoted to basic level"
|
||||||
|
|
||||||
auto_link_images_wider_than: "How wide does an image need to be, to be considered for auto link and lightbox treatment"
|
|
||||||
|
|
||||||
email_time_window_mins: "How many minutes we wait before sending a user mail, to give them a chance to see it first."
|
email_time_window_mins: "How many minutes we wait before sending a user mail, to give them a chance to see it first."
|
||||||
flush_timings_secs: "How frequently we flush timing data to the server, in seconds."
|
flush_timings_secs: "How frequently we flush timing data to the server, in seconds."
|
||||||
|
|
||||||
|
@ -625,7 +625,6 @@ ru:
|
|||||||
newuser_max_mentions_per_post: Максимальное число упоминаний по @name , которое новый пользователь может использовать в сообщении
|
newuser_max_mentions_per_post: Максимальное число упоминаний по @name , которое новый пользователь может использовать в сообщении
|
||||||
max_mentions_per_post: Максимальное число упоминаний по @name , которое новый пользователь может использовать в сообщении
|
max_mentions_per_post: Максимальное число упоминаний по @name , которое новый пользователь может использовать в сообщении
|
||||||
create_thumbnails: Создать миниатюры для изображений
|
create_thumbnails: Создать миниатюры для изображений
|
||||||
auto_link_images_wider_than: Изображение, шириной более чем указанное значение в пикселях, получит автоматическую ссылку и обработку lightbox
|
|
||||||
email_time_window_mins: Сколько минут нужно подождать перед отсылкой письма пользователя, чтобы дать ему шанс сперва его увидеть
|
email_time_window_mins: Сколько минут нужно подождать перед отсылкой письма пользователя, чтобы дать ему шанс сперва его увидеть
|
||||||
flush_timings_secs: Как часто мы отправляем временные данные на сервер, в секундах
|
flush_timings_secs: Как часто мы отправляем временные данные на сервер, в секундах
|
||||||
max_word_length: Максимальная длина слов в названии темы, в символах
|
max_word_length: Максимальная длина слов в названии темы, в символах
|
||||||
|
@ -468,8 +468,6 @@ sv:
|
|||||||
newuser_max_mentions_per_post: "Maximum number of @name notifications a new user can use in a post"
|
newuser_max_mentions_per_post: "Maximum number of @name notifications a new user can use in a post"
|
||||||
max_mentions_per_post: "Maximum number of @name notifications you can use in a post"
|
max_mentions_per_post: "Maximum number of @name notifications you can use in a post"
|
||||||
|
|
||||||
auto_link_images_wider_than: "Images wider than this, in pixels, will get auto link and lightbox treatment"
|
|
||||||
|
|
||||||
email_time_window_mins: "How many minutes we wait before sending a user mail, to give them a chance to see it first"
|
email_time_window_mins: "How many minutes we wait before sending a user mail, to give them a chance to see it first"
|
||||||
flush_timings_secs: "How frequently we flush timing data to the server, in seconds"
|
flush_timings_secs: "How frequently we flush timing data to the server, in seconds"
|
||||||
max_word_length: "The maximum allowed word length, in characters, in a topic title"
|
max_word_length: "The maximum allowed word length, in characters, in a topic title"
|
||||||
|
@ -563,8 +563,6 @@ zh_CN:
|
|||||||
newuser_max_mentions_per_post: "一个访问者可以在一个帖子里使用 @name 提及的最大数量"
|
newuser_max_mentions_per_post: "一个访问者可以在一个帖子里使用 @name 提及的最大数量"
|
||||||
max_mentions_per_post: "你可以在一个帖子里使用 @name 提及的最大数量"
|
max_mentions_per_post: "你可以在一个帖子里使用 @name 提及的最大数量"
|
||||||
|
|
||||||
auto_link_images_wider_than: "图片宽度超过此设定像素值的,将被自动附加一个链接并且使用灯箱(lightbox)来展示"
|
|
||||||
|
|
||||||
email_time_window_mins: "等待多少分钟才给用户发送通知电子邮件,好让他们有机会自己来浏览"
|
email_time_window_mins: "等待多少分钟才给用户发送通知电子邮件,好让他们有机会自己来浏览"
|
||||||
flush_timings_secs: "刷新时间数据的频率,以秒为单位"
|
flush_timings_secs: "刷新时间数据的频率,以秒为单位"
|
||||||
max_word_length: "在主题的标题中,允许的词语长度的最大字符数"
|
max_word_length: "在主题的标题中,允许的词语长度的最大字符数"
|
||||||
|
@ -546,8 +546,6 @@ zh_TW:
|
|||||||
newuser_max_mentions_per_post: "一個訪問者可以在一個帖子裏使用 @name 提及的最大數量"
|
newuser_max_mentions_per_post: "一個訪問者可以在一個帖子裏使用 @name 提及的最大數量"
|
||||||
max_mentions_per_post: "你可以在一個帖子裏使用 @name 提及的最大數量"
|
max_mentions_per_post: "你可以在一個帖子裏使用 @name 提及的最大數量"
|
||||||
|
|
||||||
auto_link_images_wider_than: "圖片寬度超過此設定像素值的,將被自動附加一個鏈接並且使用燈箱(lightbox)來展示"
|
|
||||||
|
|
||||||
email_time_window_mins: "等待多少分鍾才給用戶發送通知電子郵件,好讓他們有機會自己來浏覽"
|
email_time_window_mins: "等待多少分鍾才給用戶發送通知電子郵件,好讓他們有機會自己來浏覽"
|
||||||
flush_timings_secs: "刷新時間數據的頻率,以秒爲單位"
|
flush_timings_secs: "刷新時間數據的頻率,以秒爲單位"
|
||||||
max_word_length: "在主題的標題中,允許的詞語長度的最大字符數"
|
max_word_length: "在主題的標題中,允許的詞語長度的最大字符數"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Post processing that we can do after a post has already been cooked. For
|
# Post processing that we can do after a post has already been cooked.
|
||||||
# example, inserting the onebox content, or image sizes.
|
# For example, inserting the onebox content, or image sizes.
|
||||||
|
|
||||||
require_dependency 'oneboxer'
|
require_dependency 'oneboxer'
|
||||||
|
|
||||||
@ -16,14 +16,13 @@ class CookedPostProcessor
|
|||||||
end
|
end
|
||||||
|
|
||||||
def post_process
|
def post_process
|
||||||
return unless @doc.present?
|
|
||||||
post_process_images
|
post_process_images
|
||||||
post_process_oneboxes
|
post_process_oneboxes
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_process_images
|
def post_process_images
|
||||||
images = @doc.css("img") - @doc.css(".onebox-result img")
|
images = @doc.css("img") - @doc.css(".onebox-result img") - @doc.css(".quote img")
|
||||||
return unless images.present?
|
return if images.blank?
|
||||||
|
|
||||||
images.each do |img|
|
images.each do |img|
|
||||||
# keep track of the original src
|
# keep track of the original src
|
||||||
@ -109,13 +108,13 @@ class CookedPostProcessor
|
|||||||
|
|
||||||
def convert_to_link!(img, upload=nil)
|
def convert_to_link!(img, upload=nil)
|
||||||
src = img["src"]
|
src = img["src"]
|
||||||
|
return unless src.present?
|
||||||
|
|
||||||
width, height = img["width"].to_i, img["height"].to_i
|
width, height = img["width"].to_i, img["height"].to_i
|
||||||
|
|
||||||
return unless src.present? && width > SiteSetting.auto_link_images_wider_than
|
|
||||||
|
|
||||||
original_width, original_height = get_size(src)
|
original_width, original_height = get_size(src)
|
||||||
|
|
||||||
return unless original_width.to_i > width && original_height.to_i > height
|
return unless original_width.to_i > width && original_height.to_i > height
|
||||||
|
return if original_width < SiteSetting.max_image_width
|
||||||
|
|
||||||
parent = img.parent
|
parent = img.parent
|
||||||
while parent
|
while parent
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
require 'cooked_post_processor'
|
require 'cooked_post_processor'
|
||||||
|
|
||||||
describe CookedPostProcessor do
|
describe CookedPostProcessor do
|
||||||
@ -42,7 +41,6 @@ describe CookedPostProcessor do
|
|||||||
@topic = Fabricate(:topic)
|
@topic = Fabricate(:topic)
|
||||||
@post = Fabricate.build(:post_with_image_url, topic: @topic, user: @topic.user)
|
@post = Fabricate.build(:post_with_image_url, topic: @topic, user: @topic.user)
|
||||||
@cpp = CookedPostProcessor.new(@post, image_sizes: {'http://www.forumwarz.com/images/header/logo.png' => {'width' => 111, 'height' => 222}})
|
@cpp = CookedPostProcessor.new(@post, image_sizes: {'http://www.forumwarz.com/images/header/logo.png' => {'width' => 111, 'height' => 222}})
|
||||||
@cpp.expects(:get_size).returns([111,222])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't call image_dimensions because it knows the size" do
|
it "doesn't call image_dimensions because it knows the size" do
|
||||||
@ -134,6 +132,7 @@ describe CookedPostProcessor do
|
|||||||
let(:processor) { CookedPostProcessor.new(post) }
|
let(:processor) { CookedPostProcessor.new(post) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
SiteSetting.stubs(:max_image_width).returns(10)
|
||||||
FastImage.stubs(:size).returns([1000, 1000])
|
FastImage.stubs(:size).returns([1000, 1000])
|
||||||
processor.post_process_images
|
processor.post_process_images
|
||||||
end
|
end
|
||||||
@ -155,13 +154,8 @@ describe CookedPostProcessor do
|
|||||||
SiteSetting.stubs(:crawl_images?).returns(true)
|
SiteSetting.stubs(:crawl_images?).returns(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
let :post_with_img do
|
let(:post_with_img) { Fabricate.build(:post, cooked: '<p><img src="http://hello.com/image.png"></p>') }
|
||||||
Fabricate.build(:post, cooked: '<p><img src="http://hello.com/image.png"></p>')
|
let(:cpp_for_post) { CookedPostProcessor.new(post_with_img) }
|
||||||
end
|
|
||||||
|
|
||||||
let :cpp_for_post do
|
|
||||||
CookedPostProcessor.new(post_with_img)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'convert img tags to links if they are sized down' do
|
it 'convert img tags to links if they are sized down' do
|
||||||
cpp_for_post.expects(:get_size).returns([2000,2000]).twice
|
cpp_for_post.expects(:get_size).returns([2000,2000]).twice
|
||||||
@ -177,31 +171,32 @@ describe CookedPostProcessor do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'image_dimensions' do
|
context "image_dimensions" do
|
||||||
|
|
||||||
it "returns unless called with a http or https url" do
|
it "returns unless called with a http or https url" do
|
||||||
cpp.image_dimensions('/tmp/image.jpg').should be_blank
|
cpp.image_dimensions("/tmp/image.jpg").should be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with valid url' do
|
context "with valid url" do
|
||||||
before do
|
|
||||||
@url = 'http://www.forumwarz.com/images/header/logo.png'
|
|
||||||
end
|
|
||||||
|
|
||||||
it "doesn't call fastimage if image crawling is disabled" do
|
let(:url) { "http://www.forumwarz.com/images/header/logo.png" }
|
||||||
|
|
||||||
|
it "doesn't call FastImage if image crawling is disabled" do
|
||||||
SiteSetting.expects(:crawl_images?).returns(false)
|
SiteSetting.expects(:crawl_images?).returns(false)
|
||||||
FastImage.expects(:size).never
|
FastImage.expects(:size).never
|
||||||
cpp.image_dimensions(@url)
|
cpp.image_dimensions(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "calls fastimage if image crawling is enabled" do
|
it "calls FastImage if image crawling is enabled" do
|
||||||
SiteSetting.expects(:crawl_images?).returns(true)
|
SiteSetting.expects(:crawl_images?).returns(true)
|
||||||
FastImage.expects(:size).with(@url)
|
FastImage.expects(:size).with(url)
|
||||||
cpp.image_dimensions(@url)
|
cpp.image_dimensions(url)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'is_valid_image_uri?' do
|
end
|
||||||
|
|
||||||
|
context "is_valid_image_uri?" do
|
||||||
|
|
||||||
it "needs the scheme to be either http or https" do
|
it "needs the scheme to be either http or https" do
|
||||||
cpp.is_valid_image_uri?("http://domain.com").should == true
|
cpp.is_valid_image_uri?("http://domain.com").should == true
|
||||||
@ -212,25 +207,25 @@ describe CookedPostProcessor do
|
|||||||
cpp.is_valid_image_uri?("/tmp/image.png").should == false
|
cpp.is_valid_image_uri?("/tmp/image.png").should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't throw exception with a bad URI" do
|
it "doesn't throw an exception with a bad URI" do
|
||||||
cpp.is_valid_image_uri?("http://do<main.com").should == nil
|
cpp.is_valid_image_uri?("http://do<main.com").should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'get_filename' do
|
context "get_filename" do
|
||||||
|
|
||||||
it "returns the filename of the src when there is no upload" 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"
|
cpp.get_filename(nil, "http://domain.com/image.png").should == "image.png"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the original filename of the upload when there is an upload" do
|
it "returns the original filename of the upload when there is an upload" do
|
||||||
upload = Fabricate.build(:upload, { original_filename: "upload.jpg" })
|
upload = build(:upload, { original_filename: "upload.jpg" })
|
||||||
cpp.get_filename(upload, "http://domain.com/image.png").should == "upload.jpg"
|
cpp.get_filename(upload, "http://domain.com/image.png").should == "upload.jpg"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns a generic name for pasted images" do
|
it "returns a generic name for pasted images" do
|
||||||
upload = Fabricate.build(:upload, { original_filename: "blob.png" })
|
upload = build(:upload, { original_filename: "blob.png" })
|
||||||
cpp.get_filename(upload, "http://domain.com/image.png").should == I18n.t('upload.pasted_image_filename')
|
cpp.get_filename(upload, "http://domain.com/image.png").should == I18n.t('upload.pasted_image_filename')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user