added width attribute in order to resize by width with respect to aspect ratio

size attribute now sets the height with respect to aspect ratio
This commit is contained in:
Christian Franke 2016-02-21 01:10:40 +01:00
parent 24aff18ea2
commit 14738e4360

19
init.rb
View File

@ -171,20 +171,29 @@ Redmine::Plugin.register :redmine_dmsf do
"{{dmsf_image(file_id, size=300)}} -- with custom title and size\n" +
"{{dmsf_image(file_id, size=640x480)}}"
macro :dmsf_image do |obj, args|
args, options = extract_macro_options(args, :size, :title)
args, options = extract_macro_options(args, :size, :width, :title)
file_id = args.first
raise 'DMSF document ID required' unless file_id.present?
size = options[:size]
size = options[:size]
width = options[:width]
if file = DmsfFile.find_by_id(file_id)
unless User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
raise l(:notice_not_authorized)
end
raise 'Not supported image format' unless file.image?
url = url_for(:controller => :dmsf_files, :action => 'view', :id => file)
if size and size.include? "%"
image_tag(url, :alt => file.title, :width => size, :height => size)
if size
if size.include? "%"
image_tag(url, :alt => file.title, :width => size, :height => size)
elsif size.include? "x"
image_tag(url, :alt => file.title, :size => size)
else
image_tag(url, :alt => file.title, :width => 'auto', :height => size)
end
elsif width
image_tag(url, :alt => file.title, :width => width, :height => 'auto')
else
image_tag(url, :alt => file.title, :size => size)
image_tag(url, :alt => file.title, :width => 'auto', :height => size)
end
else
raise "Document ID #{file_id} not found"