Class: GovukTechDocs::SourceUrls

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_tech_docs/contribution_banner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configObject (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_pageObject (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_branchObject



41
42
43
# File 'lib/govuk_tech_docs/contribution_banner.rb', line 41

def repo_branch
  config[:tech_docs][:github_branch] || "master" # TODO: change this to 'main' in a future breaking release
end

#repo_urlObject



37
38
39
# File 'lib/govuk_tech_docs/contribution_banner.rb', line 37

def repo_url
  "https://github.com/#{config[:tech_docs][:github_repo]}"
end

#report_issue_urlObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/govuk_tech_docs/contribution_banner.rb', line 21

def 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_urlObject



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