Commit 2e8b5ebefd2918bde011206f97b68e5ee3d0d05f
Exists in
master
and in
4 other branches
Merge pull request #1386 from tsigo/github_markup
Use GitHub::Markup to parse markup files
Showing
7 changed files
with
34 additions
and
9 deletions
Show diff stats
Gemfile
Gemfile.lock
| ... | ... | @@ -178,6 +178,7 @@ GEM |
| 178 | 178 | gherkin (2.11.0) |
| 179 | 179 | json (>= 1.4.6) |
| 180 | 180 | git (1.2.5) |
| 181 | + github-markup (0.7.4) | |
| 181 | 182 | gitlab_meta (2.9) |
| 182 | 183 | grape (0.2.1) |
| 183 | 184 | hashie (~> 1.2) |
| ... | ... | @@ -396,6 +397,7 @@ DEPENDENCIES |
| 396 | 397 | ffaker |
| 397 | 398 | foreman |
| 398 | 399 | git |
| 400 | + github-markup (~> 0.7.4) | |
| 399 | 401 | gitlab_meta (= 2.9) |
| 400 | 402 | gitolite! |
| 401 | 403 | grack! | ... | ... |
app/controllers/refs_controller.rb
app/helpers/tree_helper.rb
| ... | ... | @@ -24,4 +24,14 @@ module TreeHelper |
| 24 | 24 | content.name |
| 25 | 25 | end |
| 26 | 26 | end |
| 27 | + | |
| 28 | + # Public: Determines if a given filename is compatible with GitHub::Markup. | |
| 29 | + # | |
| 30 | + # filename - Filename string to check | |
| 31 | + # | |
| 32 | + # Returns boolean | |
| 33 | + def markup?(filename) | |
| 34 | + filename.end_with?(*%w(.mdown .md .markdown .textile .rdoc .org .creole | |
| 35 | + .mediawiki .rst .asciidoc .pod)) | |
| 36 | + end | |
| 27 | 37 | end | ... | ... |
app/views/refs/_tree.html.haml
| ... | ... | @@ -43,11 +43,7 @@ |
| 43 | 43 | %i.icon-file |
| 44 | 44 | = content.name |
| 45 | 45 | .file_content.wiki |
| 46 | - - if content.name =~ /\.(md|markdown)$/i | |
| 47 | - = preserve do | |
| 48 | - = markdown(content.data) | |
| 49 | - - else | |
| 50 | - = simple_format(content.data) | |
| 46 | + = raw GitHub::Markup.render(content.name, content.data) | |
| 51 | 47 | |
| 52 | 48 | :javascript |
| 53 | 49 | $(function(){ | ... | ... |
app/views/refs/_tree_file.html.haml
| ... | ... | @@ -9,10 +9,9 @@ |
| 9 | 9 | = link_to "history", project_commits_path(@project, path: params[:path], ref: @ref), class: "btn very_small" |
| 10 | 10 | = link_to "blame", blame_file_project_ref_path(@project, @ref, path: params[:path]), class: "btn very_small" |
| 11 | 11 | - if file.text? |
| 12 | - - if name =~ /\.(md|markdown)$/i | |
| 12 | + - if markup?(name) | |
| 13 | 13 | .file_content.wiki |
| 14 | - = preserve do | |
| 15 | - = markdown(file.data) | |
| 14 | + = raw GitHub::Markup.render(name, file.data) | |
| 16 | 15 | - else |
| 17 | 16 | .file_content.code |
| 18 | 17 | - unless file.empty? | ... | ... |
| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | +require 'spec_helper' | |
| 2 | + | |
| 3 | +describe TreeHelper do | |
| 4 | + describe '#markup?' do | |
| 5 | + %w(mdown md markdown textile rdoc org creole mediawiki rst asciidoc pod).each do |type| | |
| 6 | + it "returns true for #{type} files" do | |
| 7 | + markup?("README.#{type}").should be_true | |
| 8 | + end | |
| 9 | + end | |
| 10 | + | |
| 11 | + it "returns false when given a non-markup filename" do | |
| 12 | + markup?('README.rb').should_not be_true | |
| 13 | + end | |
| 14 | + end | |
| 15 | +end | ... | ... |