Merge pull request #510 from chris-ibcsf/devel-1.5.7

macro for simple thumbnails / width/height scaling
This commit is contained in:
Karel Picman 2016-02-23 16:09:50 +01:00
commit 92fc69a5cd
2 changed files with 73 additions and 3 deletions

View File

@ -119,9 +119,25 @@ Search will now automatically search DMSF content when a Redmine search is perfo
####An inline picture with custom size
`{{dmsf_image(8, size=300)}}`
####An inline picture with custom size
`{{dmsf_image(8, size=50%)}}`
####An inline picture with custom height
`{{dmsf_image(8, height=300)}}`
####An inline picture with custom width
`{{dmsf_image(8, width=300)}}`
####An inline picture with custom size
`{{dmsf_image(8, size=640x480)}}`
####A thumbnail with height of 200px
`{{dmsftn(8)}}`
####A thumbnail with custom size
`{{dmsftn(8, size=300)}}`
The DMSF file/revision id can be found in link for file/revision download from within Redmine.
###Linking DMSF folders from Wiki entries:

60
init.rb
View File

@ -171,23 +171,77 @@ Redmine::Plugin.register :redmine_dmsf do
desc "Wiki DMSF image:\n\n" +
"{{dmsf_image(file_id)}}\n" +
"{{dmsf_image(file_id, size=300)}} -- with custom title and size\n" +
"{{dmsf_image(file_id, height=300)}} -- with custom title and height (auto width)\n" +
"{{dmsf_image(file_id, width=300)}} -- with custom title and width (auto height)\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, :height, :title)
file_id = args.first
raise 'DMSF document ID required' unless file_id.present?
size = options[:size]
size = options[:size]
width = options[:width]
height = options[:height]
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)
image_tag(url, :alt => file.title, :size => size)
if size && 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)
end
else
raise "Document ID #{file_id} not found"
end
end
desc "Wiki DMSF thumbnail:\n\n" +
"{{dmsftn(file_id)}}\n" +
"{{dmsftn(file_id, size=300)}} -- with custom title and size\n" +
"{{dmsftn(file_id, height=300)}} -- with custom title and height (auto width)\n" +
"{{dmsftn(file_id, width=300)}} -- with custom title and width (auto height)\n" +
"{{dmsftn(file_id, size=640x480)}}"
macro :dmsftn do |obj, args|
args, options = extract_macro_options(args, :size, :width, :height, :title)
file_id = args.first
raise 'DMSF document ID required' unless file_id.present?
size = options[:size]
width = options[:width]
height = options[:height]
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)
file_view_url = url_for(:controller => :dmsf_files, :action => 'view', :id => file, :download => args[2])
if size && size.include?("%")
img = image_tag(url, :alt => file.title, :width => size, :height => size)
elsif size && size.include?("x")
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,
file_view_url, :target => '_blank',
:title => l(:title_title_version_version_download, :title => h(file.title), :version => file.version),
'data-downloadurl' => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{file_view_url}")
else
raise "Document ID #{file_id} not found"
end
end
end
# Rubyzip configuration