##// END OF EJS Templates
File viewer for attached text files....
Jean-Philippe Lang -
r1506:80a7486f95a3
parent child
Show More
@@ -0,0 +1,15
1 <h2><%=h @attachment.filename %></h2>
2
3 <div class="attachments">
4 <p><%= h("#{@attachment.description} - ") unless @attachment.description.blank? %>
5 <span class="author"><%= @attachment.author %>, <%= format_time(@attachment.created_on) %></span></p>
6 <p><%= link_to l(:button_download), {:controller => 'attachments', :action => 'download', :id => @attachment } -%>
7 <span class="size">(<%= number_to_human_size @attachment.filesize %>)</span></p>
8
9 </div>
10 &nbsp;
11 <%= render :partial => 'common/file', :locals => {:content => @content, :filename => @attachment.filename} %>
12
13 <% content_for :header_tags do -%>
14 <%= stylesheet_link_tag "scm" -%>
15 <% end -%>
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,13
1 Index: trunk/app/controllers/issues_controller.rb
2 ===================================================================
3 --- trunk/app/controllers/issues_controller.rb (r�vision 1483)
4 +++ trunk/app/controllers/issues_controller.rb (r�vision 1484)
5 @@ -149,7 +149,7 @@
6 attach_files(@issue, params[:attachments])
7 flash[:notice] = l(:notice_successful_create)
8 Mailer.deliver_issue_add(@issue) if Setting.notified_events.include?('issue_added')
9 - redirect_to :controller => 'issues', :action => 'show', :id => @issue, :project_id => @project
10 + redirect_to :controller => 'issues', :action => 'show', :id => @issue
11 return
12 end
13 end
@@ -0,0 +1,10
1 # The Greeter class
2 class Greeter
3 def initialize(name)
4 @name = name.capitalize
5 end
6
7 def salute
8 puts "Hello #{@name}!"
9 end
10 end
@@ -0,0 +1,59
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'attachments_controller'
20
21 # Re-raise errors caught by the controller.
22 class AttachmentsController; def rescue_action(e) raise e end; end
23
24
25 class AttachmentsControllerTest < Test::Unit::TestCase
26 fixtures :users, :projects, :issues, :attachments
27
28 def setup
29 @controller = AttachmentsController.new
30 @request = ActionController::TestRequest.new
31 @response = ActionController::TestResponse.new
32 Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
33 User.current = nil
34 end
35
36 def test_show_diff
37 get :show, :id => 5
38 assert_response :success
39 assert_template 'diff'
40 end
41
42 def test_show_text_file
43 get :show, :id => 4
44 assert_response :success
45 assert_template 'file'
46 end
47
48 def test_show_other
49 get :show, :id => 6
50 assert_response :success
51 assert_equal 'application/octet-stream', @response.content_type
52 end
53
54 def test_download_text_file
55 get :download, :id => 4
56 assert_response :success
57 assert_equal 'application/x-ruby', @response.content_type
58 end
59 end
@@ -23,7 +23,10 class AttachmentsController < ApplicationController
23 if @attachment.is_diff?
23 if @attachment.is_diff?
24 @diff = File.new(@attachment.diskfile, "rb").read
24 @diff = File.new(@attachment.diskfile, "rb").read
25 render :action => 'diff'
25 render :action => 'diff'
26 else
26 elsif @attachment.is_text?
27 @content = File.new(@attachment.diskfile, "rb").read
28 render :action => 'file'
29 elsif
27 download
30 download
28 end
31 end
29 end
32 end
@@ -38,9 +41,9 class AttachmentsController < ApplicationController
38 private
41 private
39 def find_project
42 def find_project
40 @attachment = Attachment.find(params[:id])
43 @attachment = Attachment.find(params[:id])
41 render_404 and return false unless File.readable?(@attachment.diskfile)
44 #render_404 and return false unless File.readable?(@attachment.diskfile)
42 @project = @attachment.project
45 @project = @attachment.project
43 rescue
46 #rescue
44 render_404
47 # render_404
45 end
48 end
46 end
49 end
@@ -15,6 +15,9
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require 'coderay'
19 require 'coderay/helpers/file_type'
20
18 module ApplicationHelper
21 module ApplicationHelper
19 include Redmine::WikiFormatting::Macros::Definitions
22 include Redmine::WikiFormatting::Macros::Definitions
20
23
@@ -116,6 +119,11 module ApplicationHelper
116 l(:actionview_datehelper_select_month_names).split(',')[month-1]
119 l(:actionview_datehelper_select_month_names).split(',')[month-1]
117 end
120 end
118
121
122 def syntax_highlight(name, content)
123 type = CodeRay::FileType[name]
124 type ? CodeRay.scan(content, type).html : h(content)
125 end
126
119 def pagination_links_full(paginator, count=nil, options={})
127 def pagination_links_full(paginator, count=nil, options={})
120 page_param = options.delete(:page_param) || :page
128 page_param = options.delete(:page_param) || :page
121 url_param = params.dup
129 url_param = params.dup
@@ -15,16 +15,9
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require 'coderay'
19 require 'coderay/helpers/file_type'
20 require 'iconv'
18 require 'iconv'
21
19
22 module RepositoriesHelper
20 module RepositoriesHelper
23 def syntax_highlight(name, content)
24 type = CodeRay::FileType[name]
25 type ? CodeRay.scan(content, type).html : h(content)
26 end
27
28 def format_revision(txt)
21 def format_revision(txt)
29 txt.to_s[0,8]
22 txt.to_s[0,8]
30 end
23 end
@@ -88,6 +88,10 class Attachment < ActiveRecord::Base
88 self.filename =~ /\.(jpe?g|gif|png)$/i
88 self.filename =~ /\.(jpe?g|gif|png)$/i
89 end
89 end
90
90
91 def is_text?
92 Redmine::MimeType.is_type?('text', filename)
93 end
94
91 def is_diff?
95 def is_diff?
92 self.filename =~ /\.(patch|diff)$/i
96 self.filename =~ /\.(patch|diff)$/i
93 end
97 end
@@ -36,4 +36,40 attachments_003:
36 filename: logo.gif
36 filename: logo.gif
37 description: This is a logo
37 description: This is a logo
38 author_id: 2
38 author_id: 2
39 No newline at end of file
39 attachments_004:
40 created_on: 2006-07-19 21:07:27 +02:00
41 container_type: Issue
42 container_id: 3
43 downloads: 0
44 disk_filename: 060719210727_source.rb
45 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
46 id: 4
47 filesize: 153
48 filename: source.rb
49 author_id: 2
50 description: This is a Ruby source file
51 content_type: application/x-ruby
52 attachments_005:
53 created_on: 2006-07-19 21:07:27 +02:00
54 container_type: Issue
55 container_id: 3
56 downloads: 0
57 disk_filename: 060719210727_changeset.diff
58 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
59 id: 5
60 filesize: 687
61 filename: changeset.diff
62 author_id: 2
63 content_type: text/x-diff
64 attachments_006:
65 created_on: 2006-07-19 21:07:27 +02:00
66 container_type: Issue
67 container_id: 3
68 downloads: 0
69 disk_filename: 060719210727_archive.zip
70 digest: b91e08d0cf966d5c6ff411bd8c4cc3a2
71 id: 6
72 filesize: 157
73 filename: archive.zip
74 author_id: 2
75 content_type: application/octet-stream
@@ -40,6 +40,8 class DocumentsControllerTest < Test::Unit::TestCase
40
40
41 def test_new_with_one_attachment
41 def test_new_with_one_attachment
42 @request.session[:user_id] = 2
42 @request.session[:user_id] = 2
43 set_tmp_attachments_directory
44
43 post :new, :project_id => 'ecookbook',
45 post :new, :project_id => 'ecookbook',
44 :document => { :title => 'DocumentsControllerTest#test_post_new',
46 :document => { :title => 'DocumentsControllerTest#test_post_new',
45 :description => 'This is a new document',
47 :description => 'This is a new document',
@@ -361,6 +361,8 class IssuesControllerTest < Test::Unit::TestCase
361 end
361 end
362
362
363 def test_post_edit_with_attachment_only
363 def test_post_edit_with_attachment_only
364 set_tmp_attachments_directory
365
364 # anonymous user
366 # anonymous user
365 post :edit,
367 post :edit,
366 :id => 1,
368 :id => 1,
@@ -1,3 +1,20
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
1 require "#{File.dirname(__FILE__)}/../test_helper"
18 require "#{File.dirname(__FILE__)}/../test_helper"
2
19
3 class IssuesTest < ActionController::IntegrationTest
20 class IssuesTest < ActionController::IntegrationTest
@@ -47,6 +64,7 class IssuesTest < ActionController::IntegrationTest
47 # add then remove 2 attachments to an issue
64 # add then remove 2 attachments to an issue
48 def test_issue_attachements
65 def test_issue_attachements
49 log_user('jsmith', 'jsmith')
66 log_user('jsmith', 'jsmith')
67 set_tmp_attachments_directory
50
68
51 post 'issues/edit/1',
69 post 'issues/edit/1',
52 :notes => 'Some notes',
70 :notes => 'Some notes',
@@ -57,6 +57,12 class Test::Unit::TestCase
57 def test_uploaded_file(name, mime)
57 def test_uploaded_file(name, mime)
58 ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + "/files/#{name}", mime)
58 ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + "/files/#{name}", mime)
59 end
59 end
60
61 # Use a temporary directory for attachment related tests
62 def set_tmp_attachments_directory
63 Dir.mkdir "#{RAILS_ROOT}/tmp/test/attachments" unless File.directory?("#{RAILS_ROOT}/tmp/test/attachments")
64 Attachment.storage_path = "#{RAILS_ROOT}/tmp/test/attachments"
65 end
60 end
66 end
61
67
62
68
General Comments 0
You need to be logged in to leave comments. Login now