mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-19 15:01:14 +00:00
Render Textile and Markdown attachments on the preview page (#29752).
Patch by Takenori TAKAKI. git-svn-id: http://svn.redmine.org/redmine/trunk@18584 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
df1c54146f
commit
3ce678510e
@ -86,4 +86,14 @@ module AttachmentsHelper
|
|||||||
end
|
end
|
||||||
api.created_on attachment.created_on
|
api.created_on attachment.created_on
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render_file_content(attachment, content)
|
||||||
|
if attachment.is_markdown?
|
||||||
|
render :partial => 'common/markup', :locals => {:markup_text_formatting => 'markdown', :markup_text => content}
|
||||||
|
elsif attachment.is_textile?
|
||||||
|
render :partial => 'common/markup', :locals => {:markup_text_formatting => 'textile', :markup_text => content}
|
||||||
|
else
|
||||||
|
render :partial => 'common/file', :locals => {:content => content, :filename => attachment.filename}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -240,6 +240,14 @@ class Attachment < ActiveRecord::Base
|
|||||||
Redmine::MimeType.is_type?('text', filename) || Redmine::SyntaxHighlighting.filename_supported?(filename)
|
Redmine::MimeType.is_type?('text', filename) || Redmine::SyntaxHighlighting.filename_supported?(filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_markdown?
|
||||||
|
Redmine::MimeType.of(filename) == 'text/markdown'
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_textile?
|
||||||
|
self.filename =~ /\.textile$/i
|
||||||
|
end
|
||||||
|
|
||||||
def is_image?
|
def is_image?
|
||||||
Redmine::MimeType.is_type?('image', filename)
|
Redmine::MimeType.is_type?('image', filename)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
<%= render :layout => 'layouts/file' do %>
|
<%= render :layout => 'layouts/file' do %>
|
||||||
|
|
||||||
<%= render :partial => 'common/file', :locals => {:content => @content, :filename => @attachment.filename} %>
|
<%= render_file_content(@attachment, @content) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
3
app/views/common/_markup.html.erb
Normal file
3
app/views/common/_markup.html.erb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<div class="wiki">
|
||||||
|
<%= Redmine::WikiFormatting.to_html(markup_text_formatting, Redmine::CodesetUtil.to_utf8_by_setting(markup_text)).html_safe %>
|
||||||
|
</div>
|
||||||
3
test/fixtures/files/testfile.md
vendored
Normal file
3
test/fixtures/files/testfile.md
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Header 1
|
||||||
|
## Header 2
|
||||||
|
### Header 3
|
||||||
5
test/fixtures/files/testfile.textile
vendored
Normal file
5
test/fixtures/files/testfile.textile
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
h1. Header 1
|
||||||
|
|
||||||
|
h2. Header 2
|
||||||
|
|
||||||
|
h3. Header 3
|
||||||
@ -205,6 +205,38 @@ class AttachmentsControllerTest < Redmine::ControllerTest
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_show_text_file_formated_markdown
|
||||||
|
set_tmp_attachments_directory
|
||||||
|
a = Attachment.new(:container => Issue.find(1),
|
||||||
|
:file => uploaded_test_file('testfile.md', 'text/plain'),
|
||||||
|
:author => User.find(1))
|
||||||
|
assert a.save
|
||||||
|
assert_equal 'testfile.md', a.filename
|
||||||
|
|
||||||
|
get :show, :params => {
|
||||||
|
:id => a.id
|
||||||
|
}
|
||||||
|
assert_response :success
|
||||||
|
assert_equal 'text/html', @response.content_type
|
||||||
|
assert_select 'div.wiki', :html => "<h1>Header 1</h1>\n\n<h2>Header 2</h2>\n\n<h3>Header 3</h3>"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_show_text_file_fromated_textile
|
||||||
|
set_tmp_attachments_directory
|
||||||
|
a = Attachment.new(:container => Issue.find(1),
|
||||||
|
:file => uploaded_test_file('testfile.textile', 'text/plain'),
|
||||||
|
:author => User.find(1))
|
||||||
|
assert a.save
|
||||||
|
assert_equal 'testfile.textile', a.filename
|
||||||
|
|
||||||
|
get :show, :params => {
|
||||||
|
:id => a.id
|
||||||
|
}
|
||||||
|
assert_response :success
|
||||||
|
assert_equal 'text/html', @response.content_type
|
||||||
|
assert_select 'div.wiki', :html => "<h1>Header 1</h1>\n\n\n\t<h2>Header 2</h2>\n\n\n\t<h3>Header 3</h3>"
|
||||||
|
end
|
||||||
|
|
||||||
def test_show_image
|
def test_show_image
|
||||||
@request.session[:user_id] = 2
|
@request.session[:user_id] = 2
|
||||||
get :show, :params => {
|
get :show, :params => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user