Defect #29259 » 0002-Attachment-preview-does-not-support-source-code-in-s.patch
app/models/attachment.rb | ||
---|---|---|
237 | 237 |
end |
238 | 238 | |
239 | 239 |
def is_text? |
240 |
Redmine::MimeType.is_type?('text', filename) |
|
240 |
Redmine::MimeType.is_type?('text', filename) || Redmine::SyntaxHighlighting.filename_supported?(filename)
|
|
241 | 241 |
end |
242 | 242 | |
243 | 243 |
def is_image? |
lib/redmine/syntax_highlighting.rb | ||
---|---|---|
52 | 52 |
rescue |
53 | 53 |
false |
54 | 54 |
end |
55 | ||
56 |
def filename_supported?(filename) |
|
57 |
if highlighter.respond_to? :filename_supported? |
|
58 |
highlighter.filename_supported? filename |
|
59 |
else |
|
60 |
false |
|
61 |
end |
|
62 |
end |
|
55 | 63 |
end |
56 | 64 | |
57 | 65 |
module Rouge |
... | ... | |
101 | 109 |
def language_supported?(language) |
102 | 110 |
find_lexer(language.to_s.downcase) ? true : false |
103 | 111 |
end |
112 | ||
113 |
def filename_supported?(filename) |
|
114 |
!::Rouge::Lexer.guesses(:filename => filename).empty? |
|
115 |
end |
|
104 | 116 |
|
105 | 117 |
private |
106 | 118 |
# Alias names used by CodeRay and not supported by Rouge |
test/fixtures/files/hello.js | ||
---|---|---|
1 |
document.write('Hello, World!'); |
test/unit/attachment_test.rb | ||
---|---|---|
502 | 502 |
puts '(ImageMagick convert not available)' |
503 | 503 |
end |
504 | 504 | |
505 |
def test_is_text |
|
506 |
js_attachment = Attachment.new( |
|
507 |
:container => Issue.find(1), |
|
508 |
:file => uploaded_test_file('hello.js', 'application/javascript'), |
|
509 |
:author => User.find(1)) |
|
510 | ||
511 |
to_test = { |
|
512 |
js_attachment => true, # hello.js (application/javascript) |
|
513 |
attachments(:attachments_003) => false, # logo.gif (image/gif) |
|
514 |
attachments(:attachments_004) => true, # source.rb (application/x-ruby) |
|
515 |
attachments(:attachments_015) => true, # private.diff (text/x-diff) |
|
516 |
attachments(:attachments_016) => false, # testfile.png (image/png) |
|
517 |
} |
|
518 |
to_test.each do |attachment, expected| |
|
519 |
assert_equal expected, attachment.is_text? |
|
520 |
end |
|
521 |
end |
|
505 | 522 |
end |
test/unit/lib/redmine/syntax_highlighting/rouge_test.rb | ||
---|---|---|
20 | 20 |
require File.expand_path('../../../../../test_helper', __FILE__) |
21 | 21 | |
22 | 22 |
class Redmine::SyntaxHighlighting::RougeTest < ActiveSupport::TestCase |
23 |
def test_filename_supported |
|
24 |
to_test = { |
|
25 |
'application.js' => true, |
|
26 |
'Gemfile' => true, |
|
27 |
'AUTOEXEC.BAT' => false, |
|
28 |
'HELLO.C' => true |
|
29 |
} |
|
30 |
to_test.each do |filename, expected| |
|
31 |
assert_equal expected, Redmine::SyntaxHighlighting::Rouge.filename_supported?(filename) |
|
32 |
end |
|
33 |
end |
|
34 | ||
23 | 35 |
def test_highlight_by_filename_should_distinguish_perl_and_prolog |
24 | 36 |
raw_perl = <<'RAW_PERL' |
25 | 37 |
#!/usr/bin/perl |
- « Previous
- 1
- 2
- 3
- Next »