##// END OF EJS Templates
Text files can now be viewed online when browsing the repository....
Jean-Philippe Lang -
r518:8614c00c8a3e
parent child
Show More
@@ -0,0 +1,23
1 <h2><%= render :partial => 'navigation', :locals => { :path => @path, :kind => 'file', :revision => @rev } %></h2>
2
3 <table class="list">
4 <thead>
5 <tr>
6 <th colspan="2" class="list-filename"><%= @path %></th>
7 </tr>
8 </thead>
9 <tbody>
10 <% line_num = 1 %>
11 <% @content.each_line do |line| %>
12 <tr>
13 <th class="line-num"><%= line_num %></th>
14 <td class="line-code"><%= h(line).gsub(/\s/, '&nbsp;') %></td>
15 </tr>
16 <% line_num += 1 %>
17 <% end %>
18 <tbody>
19 </table>
20
21 <% content_for :header_tags do %>
22 <%= stylesheet_link_tag "scm" %>
23 <% end %>
@@ -0,0 +1,58
1 # redMine - project management software
2 # Copyright (C) 2006-2007 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 module Redmine
19 module MimeType
20
21 MIME_TYPES = {
22 'text/plain' => 'txt',
23 'text/css' => 'css',
24 'text/html' => 'html,htm,xhtml',
25 'text/x-javascript' => 'js',
26 'text/x-html-template' => 'rhtml',
27 'text/x-ruby' => 'rb,ruby',
28 'image/gif' => 'gif',
29 'image/jpeg' => 'jpg,jpeg,jpe',
30 'image/png' => 'png',
31 'image/tiff' => 'tiff,tif'
32 }.freeze
33
34 EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)|
35 exts.split(',').each {|ext| map[ext] = type}
36 map
37 end
38
39 # returns mime type for name or nil if unknown
40 def self.of(name)
41 return nil unless name
42 m = name.to_s.match(/\.([^\.]+)$/)
43 EXTENSIONS[m[1]] if m
44 end
45
46 def self.main_mimetype_of(name)
47 mimetype = of(name)
48 mimetype.split('/').first if mimetype
49 end
50
51 # return true if mime-type for name is type/*
52 # otherwise false
53 def self.is_type?(type, name)
54 main_mimetype = main_mimetype_of(name)
55 type.to_s == main_mimetype
56 end
57 end
58 end
@@ -61,10 +61,10 class RepositoriesController < ApplicationController
61 end
61 end
62
62
63 def entry
63 def entry
64 if 'raw' == params[:format]
64 @content = @repository.scm.cat(@path, @rev)
65 content = @repository.scm.cat(@path, @rev)
65 show_error and return unless @content
66 show_error and return unless content
66 if 'raw' == params[:format]
67 send_data content, :filename => @path.split('/').last
67 send_data @content, :filename => @path.split('/').last
68 end
68 end
69 end
69 end
70
70
@@ -174,6 +174,7 module SvnRepos
174 cmd << " --username #{@login} --password #{@password}" if @login
174 cmd << " --username #{@login} --password #{@password}" if @login
175 cat = nil
175 cat = nil
176 shellout(cmd) do |io|
176 shellout(cmd) do |io|
177 io.binmode
177 cat = io.read
178 cat = io.read
178 end
179 end
179 return nil if $? && $?.exitstatus != 0
180 return nil if $? && $?.exitstatus != 0
@@ -248,6 +249,10 module SvnRepos
248 def is_dir?
249 def is_dir?
249 'dir' == self.kind
250 'dir' == self.kind
250 end
251 end
252
253 def is_text?
254 Redmine::MimeType.is_type?('text', name)
255 end
251 end
256 end
252
257
253 class Revisions < Array
258 class Revisions < Array
@@ -9,7 +9,12
9
9
10 <% if @entry && @entry.is_file? %>
10 <% if @entry && @entry.is_file? %>
11 <h3><%=h @entry.name %></h3>
11 <h3><%=h @entry.name %></h3>
12 <p><%= link_to l(:button_download), {:action => 'entry', :id => @project, :path => @path, :rev => @rev, :format => 'raw' }, :class => "icon file" %> (<%= number_to_human_size @entry.size %>)</p>
12 <p>
13 <% if @entry.is_text? %>
14 <%= link_to l(:button_view), {:action => 'entry', :id => @project, :path => @path, :rev => @rev } %> |
15 <% end %>
16 <%= link_to l(:button_download), {:action => 'entry', :id => @project, :path => @path, :rev => @rev, :format => 'raw' } %>
17 (<%= number_to_human_size @entry.size %>)</p>
13 <% end %>
18 <% end %>
14
19
15 <h3><%= l(:label_revision_plural) %></h3>
20 <h3><%= l(:label_revision_plural) %></h3>
@@ -1,2 +1,3
1 require 'redmine/version'
1 require 'redmine/version'
2 require 'redmine/mime_type'
2 require 'redmine/acts_as_watchable/init'
3 require 'redmine/acts_as_watchable/init'
General Comments 0
You need to be logged in to leave comments. Login now