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

@stylesheet tag breaks menu with 2 or more parents #252

Open
akagomez opened this issue Jul 12, 2016 · 1 comment
Open

@stylesheet tag breaks menu with 2 or more parents #252

akagomez opened this issue Jul 12, 2016 · 1 comment
Assignees

Comments

@akagomez
Copy link

The Problem

When a @stylesheet page has more than one parent, the menu is rendered incorrectly:

What's incorrect is that the parent menu item ("Egowall") is rendering it's children.

What I've learned is that this due to the @stylesheet tag configuring a hideChildrenInMenu property:

this.hideChildrenInMenu = true;

this.hideChildrenInMenu = true;

The hideChildrenInMenu property is designed to hide the children of the active @stylesheet page in the menu, so that they can instead be displayed as sub-headings within the page's content:

{{^if hideChildrenInMenu}}
  <li class="search-container active">
    <a class="sidebar-title" href="{{urlTo name}}" data-search="{{#if title}}{{title}}{{else}}{{{name}}}{{/if}}">
      {{makeTitle}}
    </a>
    {{> active-menu.mustache}}
  </li>
{{/if}}

{{^if hideChildrenInMenu}}
<li class="search-container active">
<a class="sidebar-title" href="{{urlTo name}}" data-search="{{#if title}}{{title}}{{else}}{{{name}}}{{/if}}">
{{makeTitle}}
</a>
{{> active-menu.mustache}}
</li>
{{/if}}

In reality, the property hides the active @stylesheet menu item itself as well as its children:

<a class="sidebar-title" href="{{urlTo name}}" data-search="{{#if title}}{{title}}{{else}}{{{name}}}{{/if}}">
{{makeTitle}}
</a>

In order to add the active @stylesheet page back to the menu, the template renders the children of its parent menu:

{{#if ../active.hideChildrenInMenu}}
  {{> active-menu.mustache}}
{{/if}}

{{#if ../active.hideChildrenInMenu}}
{{> active-menu.mustache}}
{{/if}}

Unfortunately, this renders the children of EVERY parent menu:

{{#each parents}}
  <li class="search-container active parent">
    <a class="sidebar-title" href="{{urlTo name}}" data-search="{{#if title}}{{title}}{{else}}{{{name}}}{{/if}}">
      {{makeTitle}}
    </a>
    {{#if ../active.hideChildrenInMenu}}
      {{> active-menu.mustache}}
    {{/if}}
  </li>
{{/each}}

{{#each parents}}
<li class="search-container active parent">
<a class="sidebar-title" href="{{urlTo name}}" data-search="{{#if title}}{{title}}{{else}}{{{name}}}{{/if}}">
{{makeTitle}}
</a>
{{#if ../active.hideChildrenInMenu}}
{{> active-menu.mustache}}
{{/if}}
</li>
{{/each}}

A Fix

If you only show the LAST parent's child pages, everything works as was intended:

The way to accomplish this is to add a helper to check that a given item is the last in the the given list:

/**
 * @function documentjs.generators.html.defaultHelpers.ifIsLastItem
 *
 * Renders the truthy section if the current context is the last item
 * in the list.
 *
 * @param {Array} list
 * @param {*} item
 */
ifIsLastItem: function(list, item, options){
 return list[list.length - 1] === item ? options.fn(this) : '';
},

And add a condition to the rendering of child items in the parent menu:

{{#if ../active.hideChildrenInMenu}}
  {{#ifIsLastItem ../../parents .}}
    {{> active-menu.mustache}}
  {{/ifIsLastItem}}
{{/if}}

If nobody has a problem with this solution, I'll submit a PR later this week.

@justinbmeyer
Copy link
Member

I think it looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants