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
| @@ -44,7 +44,8 @@ gem "ffaker" | @@ -44,7 +44,8 @@ gem "ffaker" | ||
| 44 | gem "seed-fu" | 44 | gem "seed-fu" |
| 45 | 45 | ||
| 46 | # Markdown to HTML | 46 | # Markdown to HTML |
| 47 | -gem "redcarpet", "~> 2.1.1" | 47 | +gem "redcarpet", "~> 2.1.1" |
| 48 | +gem "github-markup", "~> 0.7.4" | ||
| 48 | 49 | ||
| 49 | # Servers | 50 | # Servers |
| 50 | gem "thin" | 51 | gem "thin" |
Gemfile.lock
| @@ -178,6 +178,7 @@ GEM | @@ -178,6 +178,7 @@ GEM | ||
| 178 | gherkin (2.11.0) | 178 | gherkin (2.11.0) |
| 179 | json (>= 1.4.6) | 179 | json (>= 1.4.6) |
| 180 | git (1.2.5) | 180 | git (1.2.5) |
| 181 | + github-markup (0.7.4) | ||
| 181 | gitlab_meta (2.9) | 182 | gitlab_meta (2.9) |
| 182 | grape (0.2.1) | 183 | grape (0.2.1) |
| 183 | hashie (~> 1.2) | 184 | hashie (~> 1.2) |
| @@ -396,6 +397,7 @@ DEPENDENCIES | @@ -396,6 +397,7 @@ DEPENDENCIES | ||
| 396 | ffaker | 397 | ffaker |
| 397 | foreman | 398 | foreman |
| 398 | git | 399 | git |
| 400 | + github-markup (~> 0.7.4) | ||
| 399 | gitlab_meta (= 2.9) | 401 | gitlab_meta (= 2.9) |
| 400 | gitolite! | 402 | gitolite! |
| 401 | grack! | 403 | grack! |
app/controllers/refs_controller.rb
app/helpers/tree_helper.rb
| @@ -24,4 +24,14 @@ module TreeHelper | @@ -24,4 +24,14 @@ module TreeHelper | ||
| 24 | content.name | 24 | content.name |
| 25 | end | 25 | end |
| 26 | end | 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 | end | 37 | end |
app/views/refs/_tree.html.haml
| @@ -43,11 +43,7 @@ | @@ -43,11 +43,7 @@ | ||
| 43 | %i.icon-file | 43 | %i.icon-file |
| 44 | = content.name | 44 | = content.name |
| 45 | .file_content.wiki | 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 | :javascript | 48 | :javascript |
| 53 | $(function(){ | 49 | $(function(){ |
app/views/refs/_tree_file.html.haml
| @@ -9,10 +9,9 @@ | @@ -9,10 +9,9 @@ | ||
| 9 | = link_to "history", project_commits_path(@project, path: params[:path], ref: @ref), class: "btn very_small" | 9 | = link_to "history", project_commits_path(@project, path: params[:path], ref: @ref), class: "btn very_small" |
| 10 | = link_to "blame", blame_file_project_ref_path(@project, @ref, path: params[:path]), class: "btn very_small" | 10 | = link_to "blame", blame_file_project_ref_path(@project, @ref, path: params[:path]), class: "btn very_small" |
| 11 | - if file.text? | 11 | - if file.text? |
| 12 | - - if name =~ /\.(md|markdown)$/i | 12 | + - if markup?(name) |
| 13 | .file_content.wiki | 13 | .file_content.wiki |
| 14 | - = preserve do | ||
| 15 | - = markdown(file.data) | 14 | + = raw GitHub::Markup.render(name, file.data) |
| 16 | - else | 15 | - else |
| 17 | .file_content.code | 16 | .file_content.code |
| 18 | - unless file.empty? | 17 | - unless file.empty? |
| @@ -0,0 +1,15 @@ | @@ -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 |