Class: GovukTechDocs::SourceUrls
- Inherits:
-
Object
- Object
- GovukTechDocs::SourceUrls
- Defined in:
- lib/govuk_tech_docs/contribution_banner.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
Instance Method Summary collapse
-
#initialize(current_page, config) ⇒ SourceUrls
constructor
A new instance of SourceUrls.
- #repo_branch ⇒ Object
- #repo_url ⇒ Object
- #report_issue_url ⇒ Object
- #view_source_url ⇒ Object
Constructor Details
#initialize(current_page, config) ⇒ SourceUrls
Returns a new instance of SourceUrls.
12 13 14 15 |
# File 'lib/govuk_tech_docs/contribution_banner.rb', line 12 def initialize(current_page, config) @current_page = current_page @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/govuk_tech_docs/contribution_banner.rb', line 10 def config @config end |
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
10 11 12 |
# File 'lib/govuk_tech_docs/contribution_banner.rb', line 10 def current_page @current_page end |
Instance Method Details
#repo_branch ⇒ Object
53 54 55 |
# File 'lib/govuk_tech_docs/contribution_banner.rb', line 53 def repo_branch config[:tech_docs][:github_branch] || "master" end |
#repo_url ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/govuk_tech_docs/contribution_banner.rb', line 38 def repo_url github_repo = config[:tech_docs][:github_repo] if github_repo.nil? || github_repo.empty? raise ArgumentError, "github_repo value not found in config/tech-docs.yml" end repo_url = if github_repo.match?(%r{\Ahttps://github\.com/}i) github_repo else "https://github.com/#{github_repo}" end repo_url.delete_suffix("/") end |
#report_issue_url ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/govuk_tech_docs/contribution_banner.rb', line 21 def report_issue_url url = config[:tech_docs][:source_urls]&.[](:report_issue_url) url ||= config[:source_urls]&.[](:report_issue_url) params = { body: "Problem with '#{current_page.data.title}' (#{config[:tech_docs][:host]}#{current_page.url})", } if url.nil? url = "#{repo_url}/issues/new" params["labels"] = "bug" params["title"] = "Re: '#{current_page.data.title}'" else params["subject"] = "Re: '#{current_page.data.title}'" end "#{url}?#{URI.encode_www_form(params)}" end |
#view_source_url ⇒ Object
17 18 19 |
# File 'lib/govuk_tech_docs/contribution_banner.rb', line 17 def view_source_url override_from_page || source_from_yaml_file || source_from_file end |