Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine active page by considering parent too #19

Merged
merged 1 commit into from
May 1, 2018

Conversation

quis
Copy link
Member

@quis quis commented Apr 25, 2018

Currently the logic that works out which page to highlight as ‘active’ in the top navigation is quite naïve (only compares URLs directly).

This commit makes it a bit smarter so that a page can define its parent, then the navigation will highlight the matching ‘parent’ navigation item.

Adapted from: alphagov/govuk-developer-docs@7e5ac51

Copy link
Contributor

@tijmenb tijmenb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

If you'd want to add a test, the meta tags specs are probably a good example. If that doesn't work give me a shout and I'll add something in.


private

attr_reader :config, :current_page
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these aren't necessary, since you're using @current_page page above.

@@ -70,6 +71,10 @@ def current_page_review
def format_date(date)
date.strftime('%-e %B %Y')
end

def active_page
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered making moving the from_path? logic into in here?

@quis quis force-pushed the work-out-active-page-from-parent branch from 7c82eba to 503ffe4 Compare April 26, 2018 08:41
@quis
Copy link
Member Author

quis commented Apr 26, 2018

OK, I’ve managed to make the code much simpler. Not sure how to test it though – I don’t think I can copy the example you gave now that the implementation isn’t wrapped up in a class.

Copy link
Contributor

@tijmenb tijmenb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@quis cool!

You could for example test this by adding a "step" to the integration spec

  then_there_is_a_heading
  then_there_is_a_source_footer
+ and_the_current_page_is_highlighted

And define the step as something like:

def and_the_current_page_is_highlighted
  expect(page).to have_link 'Documentation', class: 'active'
end

I've added some links to the tests in #21 in CONTRIBUTING.md.

@@ -70,6 +70,10 @@ def current_page_review
def format_date(date)
date.strftime('%-e %B %Y')
end

def active_page(page_path)
("/" + current_page.path) == page_path || current_page.data.parent == page_path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might not work for the homepage, because page_path is / and current_page.path is index.html.

Currently the logic that works out which page to highlight as ‘active’
in the top navigation is quite naïve (only compares URLs directly).

This commit makes it a bit smarter so that a page can define its
`parent`, then the navigation will highlight the matching ‘parent’
navigation item.

Adapted from: alphagov/govuk-developer-docs@7e5ac51
@quis quis force-pushed the work-out-active-page-from-parent branch from 503ffe4 to a2f5a12 Compare April 30, 2018 17:04
@quis
Copy link
Member Author

quis commented Apr 30, 2018

@tijmenb I have added:

  • tests
  • documentation
  • a whole bunch of extra complexity to make it actually work 😞

Copy link
Contributor

@tijmenb tijmenb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 it is beautiful! Now that we have tests we can always try to simplify the conditional, but this will definitely work! Feel free to merge.

@quis quis merged commit 9c19930 into master May 1, 2018
@quis quis deleted the work-out-active-page-from-parent branch May 1, 2018 10:54
This was referenced May 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants