Added syntax highlightment for repository files (using CodeRay).
Supported languages: c, ruby, rhtml, yaml, html, xml. git-svn-id: http://redmine.rubyforge.org/svn/trunk@644 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
1 parent
a5849ee044
commit
889d50089d
53 files changed
+5813
-13
No files matched your search
@@ -15,7 +15,15 @@
|
||||
# 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 RepositoriesHelper
|
||||
def syntax_highlight(name, content)
|
||||
type = CodeRay::FileType[name]
|
||||
type ? CodeRay.scan(content, type).html : h(content)
|
||||
end
|
||||
|
||||
def repository_field_tags(form, repository)
|
||||
method = repository.class.name.demodulize.underscore + "_field_tags"
|
||||
send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<% cache(@cache_key) do %>
|
||||
<% @diff.each do |table_file| %>
|
||||
<% if @diff_type == 'sbs' %>
|
||||
<table class="list">
|
||||
<table class="list CodeRay">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="4" class="list-filename">
|
||||
@@ -33,13 +33,13 @@
|
||||
<%= table_file[key].nb_line_left %>
|
||||
</th>
|
||||
<td class="line-code <%= table_file[key].type_diff_left %>">
|
||||
<%= table_file[key].line_left %>
|
||||
<pre><%= table_file[key].line_left %></pre>
|
||||
</td>
|
||||
<th class="line-num">
|
||||
<%= table_file[key].nb_line_right %>
|
||||
</th>
|
||||
<td class="line-code <%= table_file[key].type_diff_right %>">
|
||||
<%= table_file[key].line_right %>
|
||||
<pre><%= table_file[key].line_right %></pre>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
@@ -47,7 +47,7 @@
|
||||
</table>
|
||||
|
||||
<% else %>
|
||||
<table class="list">
|
||||
<table class="list CodeRay">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="3" class="list-filename">
|
||||
@@ -71,11 +71,11 @@
|
||||
</th>
|
||||
<% if table_file[key].line_left.empty? %>
|
||||
<td class="line-code <%= table_file[key].type_diff_right %>">
|
||||
<%= table_file[key].line_right %>
|
||||
<pre><%= table_file[key].line_right %></pre>
|
||||
</td>
|
||||
<% else %>
|
||||
<td class="line-code <%= table_file[key].type_diff_left %>">
|
||||
<%= table_file[key].line_left %>
|
||||
<pre><%= table_file[key].line_left %></pre>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<h2><%= render :partial => 'navigation', :locals => { :path => @path, :kind => 'file', :revision => @rev } %></h2>
|
||||
|
||||
<table class="list">
|
||||
<table class="list CodeRay">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="2" class="list-filename"><%= @path %></th>
|
||||
@@ -8,10 +8,10 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<% line_num = 1 %>
|
||||
<% @content.each_line do |line| %>
|
||||
<% syntax_highlight(@path, @content).each_line do |line| %>
|
||||
<tr>
|
||||
<th class="line-num"><%= line_num %></th>
|
||||
<td class="line-code"><%= h(line).gsub(/\s/, ' ') %></td>
|
||||
<td class="line-code"><pre><%= line %></pre></td>
|
||||
</tr>
|
||||
<% line_num += 1 %>
|
||||
<% end %>
|
||||
|
||||
Reference in new issue
Block a user