More than one ID in image rendering macros #1082
This commit is contained in:
parent
4749c6051a
commit
b34469eb28
@ -155,6 +155,8 @@ Link to the preview of 5 lines from a document with id 17: `{{dmsft(17, 5)}}`
|
||||
|
||||
Inline picture of the file with id 8; it must be an image file such as JPEG, PNG,...: `{{dmsf_image(8)}}`
|
||||
|
||||
Multiple inline pictures: `{{dmsf_image(8 9 10)}}`
|
||||
|
||||
Inline picture with custom size: `{{dmsf_image(8, size=300)}}`
|
||||
|
||||
Inline picture with custom size: `{{dmsf_image(8, size=50%)}}`
|
||||
@ -167,6 +169,8 @@ Inline picture with custom size: `{{dmsf_image(8, size=640x480)}}`
|
||||
|
||||
Thumbnail with height of 200px: `{{dmsftn(8)}}`
|
||||
|
||||
Multiple thumbnails with height of 200px: `{{dmsftn(8 9 10)}}`
|
||||
|
||||
Thumbnail with custom size: `{{dmsftn(8, size=300)}}`
|
||||
|
||||
Inline video of the file with id 8; it must be a video file such as MP4: `{{dmsf_video(9)}}`
|
||||
|
||||
@ -164,21 +164,26 @@ module RedmineDmsf
|
||||
size = options[:size]
|
||||
width = options[:width]
|
||||
height = options[:height]
|
||||
file = DmsfFile.visible.find args[0]
|
||||
unless User.current&.allowed_to?(:view_dmsf_files, file.project)
|
||||
raise l(:notice_not_authorized)
|
||||
end
|
||||
raise 'Not supported image format' unless file.image?
|
||||
url = view_dmsf_file_url(file)
|
||||
if size&.include?('%')
|
||||
image_tag url, alt: file.title, width: size, height: size
|
||||
elsif height
|
||||
image_tag url, alt: file.title, width: 'auto', height: height
|
||||
elsif width
|
||||
image_tag url, alt: file.title, width: width, height: 'auto'
|
||||
else
|
||||
image_tag url, alt: file.title, size: size
|
||||
ids = args[0].split
|
||||
html = +''
|
||||
ids.each do |id|
|
||||
file = DmsfFile.visible.find(id)
|
||||
unless User.current&.allowed_to?(:view_dmsf_files, file.project)
|
||||
raise l(:notice_not_authorized)
|
||||
end
|
||||
raise 'Not supported image format' unless file.image?
|
||||
url = view_dmsf_file_url(file)
|
||||
if size&.include?('%')
|
||||
html << image_tag(url, alt: file.title, width: size, height: size)
|
||||
elsif height
|
||||
html << image_tag(url, alt: file.title, width: 'auto', height: height)
|
||||
elsif width
|
||||
html << image_tag(url, alt: file.title, width: width, height: 'auto')
|
||||
else
|
||||
html << (image_tag url, alt: file.title, size: size)
|
||||
end
|
||||
end
|
||||
html.html_safe
|
||||
end
|
||||
|
||||
# dmsf_video - link to a video
|
||||
@ -225,23 +230,28 @@ module RedmineDmsf
|
||||
size = options[:size]
|
||||
width = options[:width]
|
||||
height = options[:height]
|
||||
file = DmsfFile.visible.find args[0]
|
||||
unless User.current&.allowed_to?(:view_dmsf_files, file.project)
|
||||
raise l(:notice_not_authorized)
|
||||
ids = args[0].split
|
||||
html = +''
|
||||
ids.each do |id|
|
||||
file = DmsfFile.visible.find(id)
|
||||
unless User.current&.allowed_to?(:view_dmsf_files, file.project)
|
||||
raise l(:notice_not_authorized)
|
||||
end
|
||||
raise 'Not supported image format' unless file.image?
|
||||
url = view_dmsf_file_url(file)
|
||||
if size
|
||||
img = image_tag(url, alt: file.title, size: size)
|
||||
elsif height
|
||||
img = image_tag(url, alt: file.title, width: 'auto', height: height)
|
||||
elsif width
|
||||
img = image_tag(url, alt: file.title, width: width, height: 'auto')
|
||||
else
|
||||
img = image_tag(url, alt: file.title, width: 'auto', height: 200)
|
||||
end
|
||||
html << link_to( img, url, target: '_blank', title: h(file.last_revision.try(:tooltip)),
|
||||
'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{url}")
|
||||
end
|
||||
raise 'Not supported image format' unless file.image?
|
||||
url = view_dmsf_file_url(file)
|
||||
if size
|
||||
img = image_tag(url, alt: file.title, size: size)
|
||||
elsif height
|
||||
img = image_tag(url, alt: file.title, width: 'auto', height: height)
|
||||
elsif width
|
||||
img = image_tag(url, alt: file.title, width: width, height: 'auto')
|
||||
else
|
||||
img = image_tag(url, alt: file.title, width: 'auto', height: 200)
|
||||
end
|
||||
link_to img, url, target: '_blank', title: h(file.last_revision.try(:tooltip)),
|
||||
'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{url}"
|
||||
html.html_safe
|
||||
end
|
||||
|
||||
# dmsfw - link to a document's approval workflow status
|
||||
|
||||
@ -224,6 +224,13 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest
|
||||
assert_equal "<p>#{link}</p>", text
|
||||
end
|
||||
|
||||
# {{dmsf_image(file_id file_id)}}
|
||||
def test_macro_dmsf_image_multiple
|
||||
text = textilizable("{{dmsf_image(#{@file7.id} #{@file7.id})}}")
|
||||
link = image_tag(view_dmsf_file_url(@file7), alt: @file7.title, size: nil)
|
||||
assert_equal "<p>#{link}#{link}</p>", text
|
||||
end
|
||||
|
||||
def test_macro_dmsf_image_size
|
||||
size = '50%'
|
||||
text = textilizable("{{dmsf_image(#{@file7.id}, size=#{size})}}")
|
||||
@ -327,7 +334,18 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest
|
||||
assert_equal "<p>#{link}</p>", text
|
||||
end
|
||||
|
||||
def test_macro_dmsftn
|
||||
# {{dmsftn(file_id file_id)}}
|
||||
def test_macro_dmsftn_multiple
|
||||
text = textilizable("{{dmsftn(#{@file7.id} #{@file7.id})}}")
|
||||
url = view_dmsf_file_url(@file7)
|
||||
img = image_tag(url, alt: @file7.title, width: 'auto', height: 200)
|
||||
link = link_to(img, url, target: '_blank', title: h(@file7.last_revision.try(:tooltip)),
|
||||
'data-downloadurl' => "#{@file7.last_revision.detect_content_type}:#{h(@file7.name)}:#{url}")
|
||||
assert_equal "<p>#{link}#{link}</p>", text
|
||||
end
|
||||
|
||||
# {{dmsftn(file_id size=300)}}
|
||||
def test_macro_dmsftn_size
|
||||
url = view_dmsf_file_url(@file7)
|
||||
size = '300'
|
||||
text = textilizable("{{dmsftn(#{@file7.id}, size=#{size})}}")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user