From 14738e43605d7b3e55dc12b3aa72ad868c50c16b Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Sun, 21 Feb 2016 01:10:40 +0100 Subject: [PATCH] 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 --- init.rb | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/init.rb b/init.rb index 88ce4e8c..29b434c5 100644 --- a/init.rb +++ b/init.rb @@ -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"