summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-06-09 18:40:59 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-06-09 18:40:59 +0000
commit80a7486f95a39ad3fc0946fad17fe51cff01cec6 (patch)
tree43e4ce8c5d338458359b5a8cf389972c93ac56f3 /app
parentaa0beecad0fa7cd8c62816b4dc7918f03b214b91 (diff)
downloadredmine-80a7486f95a39ad3fc0946fad17fe51cff01cec6.tar.gz
redmine-80a7486f95a39ad3fc0946fad17fe51cff01cec6.zip
File viewer for attached text files.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1520 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/attachments_controller.rb11
-rw-r--r--app/helpers/application_helper.rb8
-rw-r--r--app/helpers/repositories_helper.rb7
-rw-r--r--app/models/attachment.rb4
-rw-r--r--app/views/attachments/file.rhtml15
5 files changed, 34 insertions, 11 deletions
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index cfc15669f..9ea9ac48e 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -23,7 +23,10 @@ class AttachmentsController < ApplicationController
if @attachment.is_diff?
@diff = File.new(@attachment.diskfile, "rb").read
render :action => 'diff'
- else
+ elsif @attachment.is_text?
+ @content = File.new(@attachment.diskfile, "rb").read
+ render :action => 'file'
+ elsif
download
end
end
@@ -38,9 +41,9 @@ class AttachmentsController < ApplicationController
private
def find_project
@attachment = Attachment.find(params[:id])
- render_404 and return false unless File.readable?(@attachment.diskfile)
+ #render_404 and return false unless File.readable?(@attachment.diskfile)
@project = @attachment.project
- rescue
- render_404
+ #rescue
+ # render_404
end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 405c5bf44..16904c251 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -15,6 +15,9 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+require 'coderay'
+require 'coderay/helpers/file_type'
+
module ApplicationHelper
include Redmine::WikiFormatting::Macros::Definitions
@@ -116,6 +119,11 @@ module ApplicationHelper
l(:actionview_datehelper_select_month_names).split(',')[month-1]
end
+ def syntax_highlight(name, content)
+ type = CodeRay::FileType[name]
+ type ? CodeRay.scan(content, type).html : h(content)
+ end
+
def pagination_links_full(paginator, count=nil, options={})
page_param = options.delete(:page_param) || :page
url_param = params.dup
diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb
index 10f6e7396..e94ae2e7f 100644
--- a/app/helpers/repositories_helper.rb
+++ b/app/helpers/repositories_helper.rb
@@ -15,16 +15,9 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-require 'coderay'
-require 'coderay/helpers/file_type'
require 'iconv'
module RepositoriesHelper
- def syntax_highlight(name, content)
- type = CodeRay::FileType[name]
- type ? CodeRay.scan(content, type).html : h(content)
- end
-
def format_revision(txt)
txt.to_s[0,8]
end
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 95de4837a..7d6a74ebb 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -88,6 +88,10 @@ class Attachment < ActiveRecord::Base
self.filename =~ /\.(jpe?g|gif|png)$/i
end
+ def is_text?
+ Redmine::MimeType.is_type?('text', filename)
+ end
+
def is_diff?
self.filename =~ /\.(patch|diff)$/i
end
diff --git a/app/views/attachments/file.rhtml b/app/views/attachments/file.rhtml
new file mode 100644
index 000000000..7988d0aed
--- /dev/null
+++ b/app/views/attachments/file.rhtml
@@ -0,0 +1,15 @@
+<h2><%=h @attachment.filename %></h2>
+
+<div class="attachments">
+<p><%= h("#{@attachment.description} - ") unless @attachment.description.blank? %>
+ <span class="author"><%= @attachment.author %>, <%= format_time(@attachment.created_on) %></span></p>
+<p><%= link_to l(:button_download), {:controller => 'attachments', :action => 'download', :id => @attachment } -%>
+ <span class="size">(<%= number_to_human_size @attachment.filesize %>)</span></p>
+
+</div>
+&nbsp;
+<%= render :partial => 'common/file', :locals => {:content => @content, :filename => @attachment.filename} %>
+
+<% content_for :header_tags do -%>
+ <%= stylesheet_link_tag "scm" -%>
+<% end -%>