mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
DEV: Make attachment markdown reusable
This commit is contained in:
@ -1,12 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_dependency 'url_helper'
|
||||
require_dependency 'file_helper'
|
||||
require_dependency 'discourse_markdown'
|
||||
|
||||
module ImportScripts
|
||||
class Uploader
|
||||
include ActionView::Helpers::NumberHelper
|
||||
|
||||
# Creates an upload.
|
||||
# Expects path to be the full path and filename of the source file.
|
||||
# @return [Upload]
|
||||
@ -42,22 +40,15 @@ module ImportScripts
|
||||
end
|
||||
|
||||
def html_for_upload(upload, display_filename)
|
||||
if FileHelper.is_supported_image?(upload.url)
|
||||
embedded_image_html(upload)
|
||||
else
|
||||
attachment_html(upload, display_filename)
|
||||
end
|
||||
DiscourseMarkdown.upload_markdown(upload, display_name: display_filename)
|
||||
end
|
||||
|
||||
def embedded_image_html(upload)
|
||||
image_width = [upload.width, SiteSetting.max_image_width].compact.min
|
||||
image_height = [upload.height, SiteSetting.max_image_height].compact.min
|
||||
upload_name = upload.short_url || upload.url
|
||||
%Q~~
|
||||
DiscourseMarkdown.image_markdown(upload)
|
||||
end
|
||||
|
||||
def attachment_html(upload, display_filename)
|
||||
"[#{display_filename}|attachment](#{upload.short}) (#{number_to_human_size(upload.filesize)})"
|
||||
DiscourseMarkdown.attachment_markdown(upload, display_name: display_filename)
|
||||
end
|
||||
|
||||
private
|
||||
|
Reference in New Issue
Block a user