-
Notifications
You must be signed in to change notification settings - Fork 38
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
Conversation
There was a problem hiding this 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.
lib/govuk_tech_docs/helpers.rb
Outdated
|
||
private | ||
|
||
attr_reader :config, :current_page |
There was a problem hiding this comment.
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.
lib/govuk_tech_docs.rb
Outdated
@@ -70,6 +71,10 @@ def current_page_review | |||
def format_date(date) | |||
date.strftime('%-e %B %Y') | |||
end | |||
|
|||
def active_page |
There was a problem hiding this comment.
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?
7c82eba
to
503ffe4
Compare
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. |
There was a problem hiding this 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.
lib/govuk_tech_docs.rb
Outdated
@@ -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 |
There was a problem hiding this comment.
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
503ffe4
to
a2f5a12
Compare
@tijmenb I have added:
|
There was a problem hiding this 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.
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