diff options
author | Marin Jankovski <maxlazio@gmail.com> | 2013-10-09 13:28:25 +0200 |
---|---|---|
committer | Marin Jankovski <maxlazio@gmail.com> | 2013-10-09 13:28:25 +0200 |
commit | 70f828cd4b06c0854e71b72cc03cf45c11987d7e (patch) | |
tree | ff52144d1caf86aa6b936936fc7e08b83c370bff | |
parent | 1eabd9dfecad735a4e59884c568b27d27932517f (diff) | |
download | gitlab-ce-70f828cd4b06c0854e71b72cc03cf45c11987d7e.tar.gz |
Split.
-rw-r--r-- | app/helpers/gitlab_markdown_helper.rb | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb index bd0dd22bea8..7039bdc2cd0 100644 --- a/app/helpers/gitlab_markdown_helper.rb +++ b/app/helpers/gitlab_markdown_helper.rb @@ -60,16 +60,39 @@ module GitlabMarkdownHelper end def create_relative_links(text, project_path_with_namespace, ref, wiki = false) - links = text.split("\n").map { |a| a.scan(/\]\(([^(]+)\)/) }.reject{|b| b.empty? }.flatten.reject{|c| c.include?("http" || "www")} + links = extract_paths(text) links.each do |string| - new_link = [ - project_path_with_namespace, - wiki ? "wikis":"blob", - ref, - string - ].compact.join("/") + new_link = new_link(project_path_with_namespace, string, ref) text.gsub!("](#{string})", "](/#{new_link})") end text end + + def extract_paths(text) + text.split("\n").map { |a| a.scan(/\]\(([^(]+)\)/) }.reject{|b| b.empty? }.flatten.reject{|c| c.include?("http" || "www")} + end + + def new_link(path_with_namespace, string, ref) + [ + path_with_namespace, + path(string, ref), + string + ].compact.join("/") + end + + def path(string, ref) + if File.exists?(Rails.root.join(string)) + "#{local_path(string)}/#{correct_ref(ref)}" + else + "wikis" + end + end + + def local_path(string) + File.directory?(Rails.root.join(string)) ? "tree":"blob" + end + + def correct_ref(ref) + ref ? ref:'master' + end end |