Display contents of text file in Wiki page #468

This commit is contained in:
Karel Picman 2015-11-11 13:52:04 +01:00
parent d42eb93415
commit 0dbd84114f
5 changed files with 196 additions and 51 deletions

View File

@ -1,6 +1,17 @@
Changelog for Redmine DMSF
==========================
1.5.6 *2015-??-??*
------------------
* Bug: #469 - dmsfd doesn't reuse Wiki syntax in Wiki page
* New: #468 - Display contents of text file in Wiki page
* Bug: #465 - Install using debian 8 (jessie)
* Bug: #459 - WebDav Windows
* Bug: #458 - Cannot upload big files
Maintenance release II.
1.5.5 *2015-10-19*
------------------

View File

@ -1,7 +1,7 @@
Redmine DMSF Plugin
===================
The current version of Redmine DMSF is **1.5.5** [![Build Status](https://api.travis-ci.org/danmunn/redmine_dmsf.png)](https://travis-ci.org/danmunn/redmine_dmsf)
The current version of Redmine DMSF is **1.5.6 devel** [![Build Status](https://api.travis-ci.org/danmunn/redmine_dmsf.png)](https://travis-ci.org/danmunn/redmine_dmsf)
Redmine DMSF is Document Management System Features plugin for Redmine issue tracking system; It is aimed to replace current Redmine's Documents module.
@ -107,6 +107,9 @@ Search will now automatically search DMSF content when a Redmine search is perfo
####Link to the description of a file with id 17
`{{dmsfd(17)}}`
####Link to the preview of the first 5 lines from a file with id 17
`{{dmsft(17, 5)}}`
####An inline picture of the file with id 8; it must be an image file such as JPEG, PNG,...
`{{dmsf_image(8)}}`

View File

@ -406,5 +406,27 @@ class DmsfFile < ActiveRecord::Base
def image?
self.last_revision && !!(self.last_revision.disk_filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png)$/i)
end
def preview(limit)
result = 'No preview available'
if (self.last_revision.disk_filename =~ /\.(txt|ini|diff|c|cpp|php|csv|rb|h|erb|html|css)$/i)
begin
f = File.new(self.last_revision.disk_file)
f.each_line do |line|
case f.lineno
when 1
result = line
when limit.to_i + 1
break
else
result << line
end
end
rescue Exception => e
result = e.message
end
end
result
end
end

File diff suppressed because it is too large Load Diff

15
init.rb
View File

@ -28,7 +28,7 @@ Redmine::Plugin.register :redmine_dmsf do
name 'DMSF'
author 'Vit Jonas / Daniel Munn / Karel Picman'
description 'Document Management System Features'
version '1.5.5'
version '1.5.6 devel'
url 'http://www.redmine.org/plugins/dmsf'
author_url 'https://github.com/danmunn/redmine_dmsf/graphs/contributors'
@ -148,6 +148,19 @@ Redmine::Plugin.register :redmine_dmsf do
raise l(:notice_not_authorized)
end
end
desc "Wiki link to DMSF document's content preview:\n\n" +
"{{dmsft(file_id)}}\n\n" +
"_file_id_ can be found in the link for file/revision download."
macro :dmsft do |obj, args|
raise ArgumentError if args.length < 2 # Requires file id and lines number
file = DmsfFile.visible.find args[0].strip
if User.current && User.current.allowed_to?(:view_dmsf_files, file.project)
return file.preview(args[1].strip).gsub("\n", '<br/>').html_safe
else
raise l(:notice_not_authorized)
end
end
desc "Wiki DMSF image:\n\n" +
"{{dmsf_image(file_id)}}\n" +