Class: GovukNavigationHelpers::StepNavContent
- Inherits:
-
Object
- Object
- GovukNavigationHelpers::StepNavContent
- Defined in:
- lib/govuk_navigation_helpers/step_nav_content.rb
Constant Summary collapse
- STEP_NAV_NAMES =
%w( learn-to-drive-a-car ).freeze
Class Method Summary collapse
Instance Method Summary collapse
- #base_path ⇒ Object
- #current? ⇒ Boolean
-
#initialize(file_name: nil, path: nil) ⇒ StepNavContent
constructor
A new instance of StepNavContent.
- #primary_paths ⇒ Object
- #related_paths ⇒ Object
- #set_current_step ⇒ Object
- #show_step_nav? ⇒ Boolean
- #skip_link ⇒ Object
- #step_nav ⇒ Object
- #steps ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(file_name: nil, path: nil) ⇒ StepNavContent
Returns a new instance of StepNavContent.
15 16 17 18 |
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 15 def initialize(file_name: nil, path: nil) @file_name = file_name @path = path end |
Class Method Details
.current_step_nav(path) ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 7 def self.current_step_nav(path) STEP_NAV_NAMES.each do |step_nav_name| step_nav = new(file_name: step_nav_name, path: path) return step_nav if step_nav.current? end nil end |
Instance Method Details
#base_path ⇒ Object
24 25 26 |
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 24 def base_path parsed_file.dig(:base_path) end |
#current? ⇒ Boolean
59 60 61 62 |
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 59 def current? primary_paths.include?(path) || .include?(path) end |
#primary_paths ⇒ Object
36 37 38 39 40 |
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 36 def primary_paths primary_content.reject { |href| href.start_with?('http') }.select(&:present?) end |
#related_paths ⇒ Object
46 47 48 |
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 46 def parsed_file.dig(:related_paths) end |
#set_current_step ⇒ Object
50 51 52 |
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 50 def set_current_step set_step_as_active_if_current_page end |
#show_step_nav? ⇒ Boolean
54 55 56 57 |
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 54 def show_step_nav? primary_paths.include?(path) || .include?(path) end |
#skip_link ⇒ Object
32 33 34 |
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 32 def skip_link "##{steps.first[:title].downcase.tr(' ', '-')}" end |
#step_nav ⇒ Object
28 29 30 |
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 28 def step_nav parsed_file.dig(:step_by_step_nav) end |
#steps ⇒ Object
42 43 44 |
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 42 def steps step_nav.dig(:steps) end |
#title ⇒ Object
20 21 22 |
# File 'lib/govuk_navigation_helpers/step_nav_content.rb', line 20 def title parsed_file.dig(:title) end |