Commit 5627542f authored by Robert Speicher's avatar Robert Speicher

Merge branch 'routing' into 'master'

Added & use Gitlab::Routing for URL helpers

Extracted from !3389

See merge request !3486
parents c8038dc2 84b0ab77
...@@ -89,7 +89,7 @@ class Milestone < ActiveRecord::Base ...@@ -89,7 +89,7 @@ class Milestone < ActiveRecord::Base
def to_reference(from_project = nil) def to_reference(from_project = nil)
escaped_title = self.title.gsub("]", "\\]") escaped_title = self.title.gsub("]", "\\]")
h = Gitlab::Application.routes.url_helpers h = Gitlab::Routing.url_helpers
url = h.namespace_project_milestone_url(self.project.namespace, self.project, self) url = h.namespace_project_milestone_url(self.project.namespace, self.project, self)
"[#{escaped_title}](#{url})" "[#{escaped_title}](#{url})"
......
...@@ -471,7 +471,7 @@ class Project < ActiveRecord::Base ...@@ -471,7 +471,7 @@ class Project < ActiveRecord::Base
end end
def web_url def web_url
Gitlab::Application.routes.url_helpers.namespace_project_url(self.namespace, self) Gitlab::Routing.url_helpers.namespace_project_url(self.namespace, self)
end end
def web_url_without_protocol def web_url_without_protocol
...@@ -592,7 +592,7 @@ class Project < ActiveRecord::Base ...@@ -592,7 +592,7 @@ class Project < ActiveRecord::Base
if avatar.present? if avatar.present?
[gitlab_config.url, avatar.url].join [gitlab_config.url, avatar.url].join
elsif avatar_in_git elsif avatar_in_git
Gitlab::Application.routes.url_helpers.namespace_project_avatar_url(namespace, self) Gitlab::Routing.url_helpers.namespace_project_avatar_url(namespace, self)
end end
end end
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
# #
class GitlabIssueTrackerService < IssueTrackerService class GitlabIssueTrackerService < IssueTrackerService
include Gitlab::Application.routes.url_helpers include Gitlab::Routing.url_helpers
prop_accessor :title, :description, :project_url, :issues_url, :new_issue_url prop_accessor :title, :description, :project_url, :issues_url, :new_issue_url
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
class JiraService < IssueTrackerService class JiraService < IssueTrackerService
include HTTParty include HTTParty
include Gitlab::Application.routes.url_helpers include Gitlab::Routing.url_helpers
DEFAULT_API_VERSION = 2 DEFAULT_API_VERSION = 2
......
...@@ -224,7 +224,7 @@ class SystemNoteService ...@@ -224,7 +224,7 @@ class SystemNoteService
# #
# "Started branch `issue-branch-button-201`" # "Started branch `issue-branch-button-201`"
def self.new_issue_branch(issue, project, author, branch) def self.new_issue_branch(issue, project, author, branch)
h = Gitlab::Application.routes.url_helpers h = Gitlab::Routing.url_helpers
link = h.namespace_project_compare_url(project.namespace, project, from: project.default_branch, to: branch) link = h.namespace_project_compare_url(project.namespace, project, from: project.default_branch, to: branch)
body = "Started branch [`#{branch}`](#{link})" body = "Started branch [`#{branch}`](#{link})"
......
...@@ -8,7 +8,7 @@ module API ...@@ -8,7 +8,7 @@ module API
expose :id, :state, :avatar_url expose :id, :state, :avatar_url
expose :web_url do |user, options| expose :web_url do |user, options|
Gitlab::Application.routes.url_helpers.user_url(user) Gitlab::Routing.url_helpers.user_url(user)
end end
end end
...@@ -89,7 +89,7 @@ module API ...@@ -89,7 +89,7 @@ module API
expose :avatar_url expose :avatar_url
expose :web_url do |group, options| expose :web_url do |group, options|
Gitlab::Application.routes.url_helpers.group_url(group) Gitlab::Routing.url_helpers.group_url(group)
end end
end end
......
...@@ -43,7 +43,7 @@ module Banzai ...@@ -43,7 +43,7 @@ module Banzai
end end
def url_for_object(range, project) def url_for_object(range, project)
h = Gitlab::Application.routes.url_helpers h = Gitlab::Routing.url_helpers
h.namespace_project_compare_url(project.namespace, project, h.namespace_project_compare_url(project.namespace, project,
range.to_param.merge(only_path: context[:only_path])) range.to_param.merge(only_path: context[:only_path]))
end end
......
...@@ -37,7 +37,7 @@ module Banzai ...@@ -37,7 +37,7 @@ module Banzai
end end
def url_for_object(commit, project) def url_for_object(commit, project)
h = Gitlab::Application.routes.url_helpers h = Gitlab::Routing.url_helpers
h.namespace_project_commit_url(project.namespace, project, commit, h.namespace_project_commit_url(project.namespace, project, commit,
only_path: context[:only_path]) only_path: context[:only_path])
end end
......
...@@ -31,7 +31,7 @@ module Banzai ...@@ -31,7 +31,7 @@ module Banzai
end end
def url_for_object(label, project) def url_for_object(label, project)
h = Gitlab::Application.routes.url_helpers h = Gitlab::Routing.url_helpers
h.namespace_project_issues_url(project.namespace, project, label_name: label.name, h.namespace_project_issues_url(project.namespace, project, label_name: label.name,
only_path: context[:only_path]) only_path: context[:only_path])
end end
......
...@@ -14,7 +14,7 @@ module Banzai ...@@ -14,7 +14,7 @@ module Banzai
end end
def url_for_object(mr, project) def url_for_object(mr, project)
h = Gitlab::Application.routes.url_helpers h = Gitlab::Routing.url_helpers
h.namespace_project_merge_request_url(project.namespace, project, mr, h.namespace_project_merge_request_url(project.namespace, project, mr,
only_path: context[:only_path]) only_path: context[:only_path])
end end
......
...@@ -11,7 +11,7 @@ module Banzai ...@@ -11,7 +11,7 @@ module Banzai
end end
def url_for_object(issue, project) def url_for_object(issue, project)
h = Gitlab::Application.routes.url_helpers h = Gitlab::Routing.url_helpers
h.namespace_project_milestone_url(project.namespace, project, milestone, h.namespace_project_milestone_url(project.namespace, project, milestone,
only_path: context[:only_path]) only_path: context[:only_path])
end end
......
...@@ -14,7 +14,7 @@ module Banzai ...@@ -14,7 +14,7 @@ module Banzai
end end
def url_for_object(snippet, project) def url_for_object(snippet, project)
h = Gitlab::Application.routes.url_helpers h = Gitlab::Routing.url_helpers
h.namespace_project_snippet_url(project.namespace, project, snippet, h.namespace_project_snippet_url(project.namespace, project, snippet,
only_path: context[:only_path]) only_path: context[:only_path])
end end
......
...@@ -90,7 +90,7 @@ module Banzai ...@@ -90,7 +90,7 @@ module Banzai
private private
def urls def urls
Gitlab::Application.routes.url_helpers Gitlab::Routing.url_helpers
end end
def link_class def link_class
......
...@@ -5,7 +5,7 @@ module Gitlab ...@@ -5,7 +5,7 @@ module Gitlab
attr_accessor :recipient attr_accessor :recipient
attr_reader :author_id, :ref, :action attr_reader :author_id, :ref, :action
include Gitlab::Application.routes.url_helpers include Gitlab::Routing.url_helpers
delegate :namespace, :name_with_namespace, to: :project, prefix: :project delegate :namespace, :name_with_namespace, to: :project, prefix: :project
delegate :name, to: :author, prefix: :author delegate :name, to: :author, prefix: :author
......
module Gitlab
module Routing
# Returns the URL helpers Module.
#
# This method caches the output as Rails' "url_helpers" method creates an
# anonymous module every time it's called.
#
# Returns a Module.
def self.url_helpers
@url_helpers ||= Gitlab::Application.routes.url_helpers
end
end
end
module Gitlab module Gitlab
class UrlBuilder class UrlBuilder
include Gitlab::Application.routes.url_helpers include Gitlab::Routing.url_helpers
include GitlabRoutingHelper include GitlabRoutingHelper
include ActionView::RecordIdentifier include ActionView::RecordIdentifier
......
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe ExtractsPath, lib: true do describe ExtractsPath, lib: true do
include ExtractsPath include ExtractsPath
include RepoHelpers include RepoHelpers
include Gitlab::Application.routes.url_helpers include Gitlab::Routing.url_helpers
let(:project) { double('project') } let(:project) { double('project') }
......
...@@ -236,6 +236,6 @@ describe Gitlab::ClosingIssueExtractor, lib: true do ...@@ -236,6 +236,6 @@ describe Gitlab::ClosingIssueExtractor, lib: true do
end end
def urls def urls
Gitlab::Application.routes.url_helpers Gitlab::Routing.url_helpers
end end
end end
...@@ -78,6 +78,6 @@ module FilterSpecHelper ...@@ -78,6 +78,6 @@ module FilterSpecHelper
# Shortcut to Rails' auto-generated routes helpers, to avoid including the # Shortcut to Rails' auto-generated routes helpers, to avoid including the
# module # module
def urls def urls
Gitlab::Application.routes.url_helpers Gitlab::Routing.url_helpers
end end
end end
...@@ -106,7 +106,7 @@ class MarkdownFeature ...@@ -106,7 +106,7 @@ class MarkdownFeature
end end
def urls def urls
Gitlab::Application.routes.url_helpers Gitlab::Routing.url_helpers
end end
def raw_markdown def raw_markdown
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment