dss_tech_docs 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +29 -0
  3. data/.gitignore +37 -0
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +11 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +9 -0
  8. data/CHANGELOG.md +274 -0
  9. data/CONTRIBUTING.md +9 -0
  10. data/Gemfile +4 -0
  11. data/LICENCE +21 -0
  12. data/README.md +89 -0
  13. data/Rakefile +13 -0
  14. data/docs/configuration.md +205 -0
  15. data/docs/core-layout-without-sidebar.png +0 -0
  16. data/docs/core-layout.png +0 -0
  17. data/docs/expired-page.png +0 -0
  18. data/docs/frontmatter.md +145 -0
  19. data/docs/last-reviewed-only.png +0 -0
  20. data/docs/last-reviewed-only.svg +1 -0
  21. data/docs/layout-layout.png +0 -0
  22. data/docs/not-expired-page.png +0 -0
  23. data/docs/page-expiry.md +85 -0
  24. data/dss_tech_docs.gemspec +46 -0
  25. data/example/.ruby-version +1 -0
  26. data/example/Gemfile +3 -0
  27. data/example/config.rb +9 -0
  28. data/example/config/hide-expiry.yml +51 -0
  29. data/example/config/tech-docs.yml +50 -0
  30. data/example/source/api-path.html.md +7 -0
  31. data/example/source/api-reference.html.md +5 -0
  32. data/example/source/child-of-expired-page.html.md +8 -0
  33. data/example/source/core-layout-without-sidebar.html.md.erb +7 -0
  34. data/example/source/core-layout.html.md.erb +12 -0
  35. data/example/source/expired-page-with-owner.html.md +10 -0
  36. data/example/source/expired-page.html.md +9 -0
  37. data/example/source/headings.html.md +11 -0
  38. data/example/source/index.html.md.erb +19 -0
  39. data/example/source/javascripts/application.js +1 -0
  40. data/example/source/not-expired-page.html.md +9 -0
  41. data/example/source/pets.yml +109 -0
  42. data/example/source/stylesheets/print.css.scss +3 -0
  43. data/example/source/stylesheets/screen-old-ie.css.scss +4 -0
  44. data/example/source/stylesheets/screen.css.scss +1 -0
  45. data/example/source/templates/proxy_template.html.md +8 -0
  46. data/lib/assets/javascripts/_analytics.js +58 -0
  47. data/lib/assets/javascripts/_govuk/modules.js +57 -0
  48. data/lib/assets/javascripts/_modules/anchored-headings.js +18 -0
  49. data/lib/assets/javascripts/_modules/collapsible-navigation.js +95 -0
  50. data/lib/assets/javascripts/_modules/in-page-navigation.js +132 -0
  51. data/lib/assets/javascripts/_modules/navigation.js +34 -0
  52. data/lib/assets/javascripts/_modules/page-expiry.js +15 -0
  53. data/lib/assets/javascripts/_modules/search.js +367 -0
  54. data/lib/assets/javascripts/_modules/table-of-contents.js +111 -0
  55. data/lib/assets/javascripts/_start-modules.js +13 -0
  56. data/lib/assets/javascripts/_vendor/fixedsticky.js +194 -0
  57. data/lib/assets/javascripts/_vendor/jquery.js +5 -0
  58. data/lib/assets/javascripts/_vendor/jquery.mark.js +1081 -0
  59. data/lib/assets/javascripts/_vendor/lodash.js +613 -0
  60. data/lib/assets/javascripts/_vendor/modernizr.js +3 -0
  61. data/lib/assets/javascripts/govuk_tech_docs.js +10 -0
  62. data/lib/assets/stylesheets/_accessibility.scss +9 -0
  63. data/lib/assets/stylesheets/_core.scss +71 -0
  64. data/lib/assets/stylesheets/_fonts.scss +29 -0
  65. data/lib/assets/stylesheets/_govuk_tech_docs.scss +2 -0
  66. data/lib/assets/stylesheets/_syntax-highlighting.scss +196 -0
  67. data/lib/assets/stylesheets/_variables.scss +12 -0
  68. data/lib/assets/stylesheets/govuk_frontend_toolkit/_colours.scss +2 -0
  69. data/lib/assets/stylesheets/govuk_frontend_toolkit/_conditionals.scss +81 -0
  70. data/lib/assets/stylesheets/govuk_frontend_toolkit/_css3.scss +90 -0
  71. data/lib/assets/stylesheets/govuk_frontend_toolkit/_device-pixels.scss +10 -0
  72. data/lib/assets/stylesheets/govuk_frontend_toolkit/_font_stack.scss +19 -0
  73. data/lib/assets/stylesheets/govuk_frontend_toolkit/_grid_layout.scss +136 -0
  74. data/lib/assets/stylesheets/govuk_frontend_toolkit/_helpers.scss +16 -0
  75. data/lib/assets/stylesheets/govuk_frontend_toolkit/_measurements.scss +14 -0
  76. data/lib/assets/stylesheets/govuk_frontend_toolkit/_shims.scss +55 -0
  77. data/lib/assets/stylesheets/govuk_frontend_toolkit/_typography.scss +249 -0
  78. data/lib/assets/stylesheets/govuk_frontend_toolkit/_url-helpers.scss +16 -0
  79. data/lib/assets/stylesheets/govuk_frontend_toolkit/colours/_organisation.scss +103 -0
  80. data/lib/assets/stylesheets/govuk_frontend_toolkit/colours/_palette.scss +77 -0
  81. data/lib/assets/stylesheets/govuk_frontend_toolkit/design-patterns/_alpha-beta.scss +66 -0
  82. data/lib/assets/stylesheets/govuk_frontend_toolkit/design-patterns/_breadcrumbs.scss +53 -0
  83. data/lib/assets/stylesheets/govuk_frontend_toolkit/design-patterns/_buttons.scss +141 -0
  84. data/lib/assets/stylesheets/govuk_frontend_toolkit/design-patterns/_media-player.scss +242 -0
  85. data/lib/assets/stylesheets/modules/_anchored-heading.scss +54 -0
  86. data/lib/assets/stylesheets/modules/_app-pane.scss +64 -0
  87. data/lib/assets/stylesheets/modules/_collapsible.scss +52 -0
  88. data/lib/assets/stylesheets/modules/_contribution-banner.scss +22 -0
  89. data/lib/assets/stylesheets/modules/_footer.scss +130 -0
  90. data/lib/assets/stylesheets/modules/_govuk-logo.scss +47 -0
  91. data/lib/assets/stylesheets/modules/_header.scss +290 -0
  92. data/lib/assets/stylesheets/modules/_page-review.scss +35 -0
  93. data/lib/assets/stylesheets/modules/_phase-banner.scss +22 -0
  94. data/lib/assets/stylesheets/modules/_search.scss +137 -0
  95. data/lib/assets/stylesheets/modules/_skip-link.scss +31 -0
  96. data/lib/assets/stylesheets/modules/_technical-documentation.scss +241 -0
  97. data/lib/assets/stylesheets/modules/_toc.scss +216 -0
  98. data/lib/assets/stylesheets/modules/_warning-text.scss +73 -0
  99. data/lib/assets/stylesheets/palette/_syntax-highlighting.scss +23 -0
  100. data/lib/assets/stylesheets/utilities/_fonts.scss +29 -0
  101. data/lib/assets/stylesheets/utilities/_printable.scss +13 -0
  102. data/lib/assets/stylesheets/vendor/_fixedsticky.scss +22 -0
  103. data/lib/dss_tech_docs.rb +121 -0
  104. data/lib/govuk_tech_docs/api_reference/api_reference_extension.rb +101 -0
  105. data/lib/govuk_tech_docs/api_reference/api_reference_renderer.rb +279 -0
  106. data/lib/govuk_tech_docs/api_reference/templates/api_reference_full.html.erb +19 -0
  107. data/lib/govuk_tech_docs/api_reference/templates/operation.html.erb +11 -0
  108. data/lib/govuk_tech_docs/api_reference/templates/parameters.html.erb +28 -0
  109. data/lib/govuk_tech_docs/api_reference/templates/path.html.erb +4 -0
  110. data/lib/govuk_tech_docs/api_reference/templates/responses.html.erb +33 -0
  111. data/lib/govuk_tech_docs/api_reference/templates/schema.html.erb +29 -0
  112. data/lib/govuk_tech_docs/contribution_banner.rb +62 -0
  113. data/lib/govuk_tech_docs/meta_tags.rb +67 -0
  114. data/lib/govuk_tech_docs/page_review.rb +52 -0
  115. data/lib/govuk_tech_docs/pages.rb +32 -0
  116. data/lib/govuk_tech_docs/redirects.rb +39 -0
  117. data/lib/govuk_tech_docs/table_of_contents/heading.rb +30 -0
  118. data/lib/govuk_tech_docs/table_of_contents/heading_tree.rb +27 -0
  119. data/lib/govuk_tech_docs/table_of_contents/heading_tree_builder.rb +41 -0
  120. data/lib/govuk_tech_docs/table_of_contents/heading_tree_renderer.rb +46 -0
  121. data/lib/govuk_tech_docs/table_of_contents/headings_builder.rb +39 -0
  122. data/lib/govuk_tech_docs/table_of_contents/helpers.rb +79 -0
  123. data/lib/govuk_tech_docs/tech_docs_html_renderer.rb +34 -0
  124. data/lib/govuk_tech_docs/unique_identifier_extension.rb +13 -0
  125. data/lib/govuk_tech_docs/unique_identifier_generator.rb +72 -0
  126. data/lib/govuk_tech_docs/version.rb +3 -0
  127. data/lib/govuk_tech_docs/warning_text_extension.rb +23 -0
  128. data/lib/source/api/pages.json.erb +1 -0
  129. data/lib/source/favicon.ico +0 -0
  130. data/lib/source/images/anchored-heading-icon-2x.png +0 -0
  131. data/lib/source/images/anchored-heading-icon.png +0 -0
  132. data/lib/source/images/gov.uk_logotype_crown-2x.png +0 -0
  133. data/lib/source/images/gov.uk_logotype_crown.png +0 -0
  134. data/lib/source/images/gov.uk_logotype_crown_invert_trans.png +0 -0
  135. data/lib/source/images/govuk-crest-2x.png +0 -0
  136. data/lib/source/images/govuk-crest.png +0 -0
  137. data/lib/source/images/govuk-icn-close.png +0 -0
  138. data/lib/source/images/govuk-icn-close@2x.png +0 -0
  139. data/lib/source/images/govuk-icn-numbered-list.png +0 -0
  140. data/lib/source/images/govuk-icn-numbered-list@2x.png +0 -0
  141. data/lib/source/images/open-government-licence.png +0 -0
  142. data/lib/source/images/open-government-licence_2x.png +0 -0
  143. data/lib/source/images/search-result-caret.svg +13 -0
  144. data/lib/source/layouts/_analytics.erb +15 -0
  145. data/lib/source/layouts/_footer.erb +10 -0
  146. data/lib/source/layouts/_header.erb +44 -0
  147. data/lib/source/layouts/_page_review.erb +22 -0
  148. data/lib/source/layouts/_search.erb +16 -0
  149. data/lib/source/layouts/core.erb +82 -0
  150. data/lib/source/layouts/layout.erb +18 -0
  151. metadata +474 -0
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "govuk_tech_docs/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dss_tech_docs"
8
+ spec.version = GovukTechDocs::VERSION
9
+ spec.authors = ["Digital Shared Services"]
10
+ spec.email = ["stephen.patterson@finance-ni.gov.uk"]
11
+
12
+ spec.summary = %q{Gem to distribute the DSS Tech Docs Template}
13
+ spec.description = %q{Gem to distribute the DSS Tech Docs Template. See https://github.com/dof-dss/tech-docs-gem for the project.}
14
+ spec.homepage = "https://github.com/dof-dss/tech-docs-gem"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "activesupport"
25
+ spec.add_dependency "chronic", "~> 0.10.2"
26
+ spec.add_dependency "middleman", "~> 4.0"
27
+ spec.add_dependency "middleman-autoprefixer", "~> 2.7.0"
28
+ spec.add_dependency "middleman-compass", ">= 4.0.0"
29
+ spec.add_dependency "middleman-livereload"
30
+ spec.add_dependency "middleman-sprockets", "~> 4.0.0"
31
+ spec.add_dependency "middleman-syntax", "~> 3.0.0"
32
+ spec.add_dependency 'middleman-search-gds', '~> 0.11.0a'
33
+ spec.add_dependency "nokogiri"
34
+ spec.add_dependency "redcarpet", "~> 3.3.2"
35
+ spec.add_dependency "openapi3_parser"
36
+ spec.add_dependency "pry"
37
+
38
+
39
+ spec.add_development_dependency "bundler", "~> 2.0.1"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "capybara", "~> 2.18.0"
42
+ spec.add_development_dependency "govuk-lint", "~> 3.7.0"
43
+ spec.add_development_dependency "jasmine", "~> 3.1.0"
44
+ spec.add_development_dependency "rspec", "~> 3.7.0"
45
+ spec.add_development_dependency "byebug"
46
+ end
@@ -0,0 +1 @@
1
+ 2.4.2
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'govuk_tech_docs', path: '..'
@@ -0,0 +1,9 @@
1
+ require 'govuk_tech_docs'
2
+
3
+ GovukTechDocs.configure(self)
4
+
5
+ ignore 'templates/*'
6
+
7
+ proxy '/a-proxied-page.html', 'templates/proxy_template.html', locals: {
8
+ title: 'I am a title'
9
+ }
@@ -0,0 +1,51 @@
1
+ # Host to use for canonical URL generation (without trailing slash)
2
+ host: https://docs.example.com
3
+
4
+ # Header-related options
5
+ show_govuk_logo: true
6
+ service_name: My First Service
7
+ service_link: /
8
+ phase: Beta
9
+
10
+ # Links to show on right-hand-side of header
11
+ header_links:
12
+ Documentation: /
13
+ Expired page: /expired-page.html
14
+ Expired with owner: /expired-page-with-owner.html
15
+ Not expired page: /not-expired-page.html
16
+
17
+ # Tracking ID from Google Analytics (e.g. UA-XXXX-Y)
18
+ ga_tracking_id:
19
+
20
+ # Enable multipage navigation in the sidebar
21
+ multipage_nav: true
22
+
23
+ # Enable collapsible navigation in the sidebar
24
+ collapsible_nav: true
25
+
26
+ # Table of contents depth – how many levels to include in the table of contents.
27
+ # If your ToC is too long, reduce this number and we'll only show higher-level
28
+ # headings.
29
+ max_toc_heading_level: 6
30
+
31
+ # Prevent robots from indexing (e.g. whilst in development)
32
+ prevent_indexing: false
33
+
34
+ google_site_verification: dstbao8TVS^DRVDS&rv76
35
+
36
+ enable_search: true
37
+
38
+ show_contribution_banner: true
39
+
40
+ github_repo: alphagov/example-repo
41
+ github_branch: source
42
+
43
+ redirects:
44
+ /something/old.html: /index.html
45
+
46
+ api_path: source/pets.yml
47
+
48
+ # Optional global settings for the page review process
49
+ owner_slack_workspace: gds
50
+ default_owner_slack: '#2nd-line'
51
+ show_expiry: false
@@ -0,0 +1,50 @@
1
+ # Host to use for canonical URL generation (without trailing slash)
2
+ host: https://docs.example.com
3
+
4
+ # Header-related options
5
+ show_govuk_logo: false
6
+ service_name: DSS Tech Docs Example
7
+ service_link: /
8
+ phase: Beta
9
+
10
+ # Links to show on right-hand-side of header
11
+ header_links:
12
+ Documentation: /
13
+ Expired page: /expired-page.html
14
+ Expired with owner: /expired-page-with-owner.html
15
+ Not expired page: /not-expired-page.html
16
+
17
+ # Tracking ID from Google Analytics (e.g. UA-XXXX-Y)
18
+ ga_tracking_id:
19
+
20
+ # Enable multipage navigation in the sidebar
21
+ multipage_nav: true
22
+
23
+ # Enable collapsible navigation in the sidebar
24
+ collapsible_nav: true
25
+
26
+ # Table of contents depth – how many levels to include in the table of contents.
27
+ # If your ToC is too long, reduce this number and we'll only show higher-level
28
+ # headings.
29
+ max_toc_heading_level: 6
30
+
31
+ # Prevent robots from indexing (e.g. whilst in development)
32
+ prevent_indexing: false
33
+
34
+ google_site_verification: dstbao8TVS^DRVDS&rv76
35
+
36
+ enable_search: true
37
+
38
+ show_contribution_banner: true
39
+
40
+ github_repo: dof-dss/example-repo
41
+ github_branch: source
42
+
43
+ redirects:
44
+ /something/old.html: /index.html
45
+
46
+ api_path: source/pets.yml
47
+
48
+ # Optional global settings for the page review process
49
+ owner_slack_workspace: gds
50
+ default_owner_slack: '#2nd-line'
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: API /Pets
3
+ ---
4
+
5
+ # API /Pets
6
+
7
+ api> /pets
@@ -0,0 +1,5 @@
1
+ ---
2
+ title: Example API Petstore
3
+ ---
4
+
5
+ api>
@@ -0,0 +1,8 @@
1
+ ---
2
+ title: This is a child of expired page
3
+ parent: /expired-page.html
4
+ ---
5
+
6
+ # This is a child of expired page
7
+
8
+ Expired page should highlight in the navigation.
@@ -0,0 +1,7 @@
1
+ ---
2
+ layout: core
3
+ ---
4
+
5
+ # Core layout, no sidebar
6
+
7
+ This page does not have a sidebar.
@@ -0,0 +1,12 @@
1
+ ---
2
+ layout: core
3
+ ---
4
+
5
+ <% content_for :sidebar do %>
6
+ You can put anything in the sidebar.
7
+ <% end %>
8
+
9
+
10
+ # Core layout, alternative sidebar
11
+
12
+ This page has a configurable sidebar that is independent of the content.
@@ -0,0 +1,10 @@
1
+ ---
2
+ title: This is an expired page
3
+ last_reviewed_on: 1983-01-18
4
+ review_in: 18 years
5
+ owner_slack: '@foo'
6
+ ---
7
+
8
+ # This is an expired page with owner
9
+
10
+ See the banner on this page.
@@ -0,0 +1,9 @@
1
+ ---
2
+ title: This is an expired page
3
+ last_reviewed_on: 1983-01-18
4
+ review_in: 18 years
5
+ ---
6
+
7
+ # This is an expired page
8
+
9
+ See the banner on this page.
@@ -0,0 +1,11 @@
1
+ ---
2
+ layout: layout
3
+ ---
4
+
5
+ # The title
6
+
7
+ ## A subheader
8
+
9
+ ### A h3 subheader
10
+
11
+ ## Another subheader
@@ -0,0 +1,19 @@
1
+ ---
2
+ title: DSS Tech Docs Example
3
+ old_paths:
4
+ - /something/old-as-well.html
5
+ ---
6
+
7
+ # Hello, World!
8
+
9
+ ## Edit Me!
10
+
11
+ Open `source/documentation/index.md` in your favourite text editor and start editing!
12
+
13
+ You can write content in [Markdown](https://daringfireball.net/projects/markdown/) using **all** of the _usual_ syntax that you're used to!
14
+
15
+ To change the title of the page or include additional files you'll need to edit `source/index.html.md.erb`.
16
+
17
+ If you want slightly more control, you can always use <strong>HTML</strong>.
18
+
19
+ For more detail and troubleshooting, take a look at the `README.md` file in the root of this project.
@@ -0,0 +1 @@
1
+ //= require govuk_tech_docs
@@ -0,0 +1,9 @@
1
+ ---
2
+ title: This is an expired page
3
+ last_reviewed_on: 2050-01-18
4
+ review_in: 1 month
5
+ ---
6
+
7
+ # This is not an expired page
8
+
9
+ See the banner on this page.
@@ -0,0 +1,109 @@
1
+ openapi: "3.0.0"
2
+ info:
3
+ version: 1.0.0
4
+ title: Swagger Petstore
5
+ description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification
6
+ license:
7
+ name: MIT
8
+ servers:
9
+ - description: Production
10
+ url: http://petstore.swagger.io/v1
11
+ - description: Development
12
+ url: http://dev.petstore.swagger.io
13
+ paths:
14
+ /pets:
15
+ get:
16
+ summary: List all pets
17
+ operationId: listPets
18
+ tags:
19
+ - pets
20
+ parameters:
21
+ - name: limit
22
+ in: query
23
+ description: How many items to return at one time (max 100)
24
+ required: false
25
+ schema:
26
+ type: integer
27
+ format: int32
28
+ responses:
29
+ '200':
30
+ description: A paged array of pets
31
+ headers:
32
+ content:
33
+ application/json:
34
+ schema:
35
+ $ref: "#/components/schemas/Pets"
36
+ default:
37
+ description: unexpected error
38
+ content:
39
+ application/json:
40
+ schema:
41
+ $ref: "#/components/schemas/Error"
42
+ post:
43
+ summary: Create a pet
44
+ operationId: createPets
45
+ tags:
46
+ - pets
47
+ responses:
48
+ '201':
49
+ description: Null response
50
+ default:
51
+ description: unexpected error
52
+ content:
53
+ application/json:
54
+ schema:
55
+ $ref: "#/components/schemas/Error"
56
+ /pets/{petId}:
57
+ get:
58
+ summary: Info for a specific pet
59
+ operationId: showPetById
60
+ tags:
61
+ - pets
62
+ parameters:
63
+ - name: petId
64
+ in: path
65
+ required: true
66
+ description: The id of the pet to retrieve
67
+ schema:
68
+ type: string
69
+ responses:
70
+ '200':
71
+ description: Expected response to a valid request
72
+ content:
73
+ application/json:
74
+ schema:
75
+ $ref: "#/components/schemas/Pets"
76
+ default:
77
+ description: unexpected error
78
+ content:
79
+ application/json:
80
+ schema:
81
+ $ref: "#/components/schemas/Error"
82
+ components:
83
+ schemas:
84
+ Pet:
85
+ required:
86
+ - id
87
+ - name
88
+ properties:
89
+ id:
90
+ type: integer
91
+ format: int64
92
+ name:
93
+ type: string
94
+ tag:
95
+ type: string
96
+ Pets:
97
+ type: array
98
+ items:
99
+ $ref: "#/components/schemas/Pet"
100
+ Error:
101
+ required:
102
+ - code
103
+ - message
104
+ properties:
105
+ code:
106
+ type: integer
107
+ format: int32
108
+ message:
109
+ type: string
@@ -0,0 +1,3 @@
1
+ $is-print: true;
2
+
3
+ @import "govuk_tech_docs";
@@ -0,0 +1,4 @@
1
+ $is-ie: true;
2
+ $ie-version: 8;
3
+
4
+ @import "govuk_tech_docs";
@@ -0,0 +1 @@
1
+ @import "govuk_tech_docs";
@@ -0,0 +1,8 @@
1
+ ---
2
+ title: Proxied page
3
+ source_url: http://example.org/source.md
4
+ ---
5
+
6
+ # Proxied page
7
+
8
+ This is a proxied page.
@@ -0,0 +1,58 @@
1
+ (function($) {
2
+ function trackLinkClick(action, $element) {
3
+ var linkText = $.trim($element.text());
4
+ var linkURL = $element.attr('href');
5
+ var label = linkText + '|' + linkURL;
6
+
7
+ ga(
8
+ 'send',
9
+ 'event',
10
+ 'SM Technical Documentation', // Event Category
11
+ action, // Event Action
12
+ label // Event Label
13
+ );
14
+ }
15
+
16
+ function linkTrackingEventHandler(action) {
17
+ return function() {
18
+ trackLinkClick(action, $(this));
19
+ };
20
+ };
21
+
22
+ function catchBrokenFragmentLinks() {
23
+ var fragment = window.location.hash;
24
+ var $target = $(fragment);
25
+ if(!$target.get(0)) {
26
+ ga(
27
+ 'send',
28
+ 'event',
29
+ 'Broken fragment ID', // Event Category
30
+ 'pageview', // Event Action
31
+ window.location.pathname + fragment // Event Label
32
+ );
33
+ }
34
+ }
35
+
36
+ $(document).on('ready', function() {
37
+ if (typeof ga === 'undefined') {
38
+ return;
39
+ }
40
+
41
+ $('.technical-documentation a').on('click', linkTrackingEventHandler('inTextClick'));
42
+ $('.header a').on('click', linkTrackingEventHandler('topNavigationClick'));
43
+ $('.toc a').on('click', linkTrackingEventHandler('tableOfContentsNavigationClick'));
44
+ catchBrokenFragmentLinks();
45
+
46
+ // Borrowed from:
47
+ // https://github.com/alphagov/govuk_frontend_toolkit/blob/master/javascripts/govuk/analytics/analytics.js
48
+ window.stripPIIFromString = function (string) {
49
+ var EMAIL_PATTERN = /[^\s=/?&]+(?:@|%40)[^\s=/?&]+/g
50
+ var POSTCODE_PATTERN = /[A-PR-UWYZ][A-HJ-Z]?[0-9][0-9A-HJKMNPR-Y]?(?:[\s+]|%20)*[0-9][ABD-HJLNPQ-Z]{2}/gi
51
+ var DATE_PATTERN = /\d{4}(-?)\d{2}(-?)\d{2}/g
52
+ var stripped = string.replace(EMAIL_PATTERN, '[email]')
53
+ .replace(DATE_PATTERN, '[date]')
54
+ .replace(POSTCODE_PATTERN, '[postcode]');
55
+ return stripped
56
+ }
57
+ });
58
+ })(jQuery);