Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions templates/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,31 @@ module.exports = function(docMap, options, getCurrent, helpers, OtherHandlebars)
version = version.replace(/-/g, '--');
return 'https://img.shields.io/badge/npm%20package-'+version+'-brightgreen.svg';
},
sourceLink: function(packageObject) {
repoName: function() {
var current = docMapInfo.getCurrent();

if (!current.src) {
return false;
}
var name = packageObject.name,
srcPath = current.src.path.replace('node_modules/' + name + '/', ''),
line = current.src.line ? '#L' + (current.src.line + 1) : '';
return '//github.com/canjs/' + name + '/edit/master/' + srcPath + line;

var nodeModulesFolderNameRegex = /^node_modules\/([\w-]+)\/.*/,
folderNameMatches = current.src.path.match(nodeModulesFolderNameRegex);

// find repoName by picking it out of the node_modules path, or we can assume this page is in the root canjs repo
// this assumes the npm module name matches the github repository name
return folderNameMatches ? folderNameMatches[1] : 'canjs';
},
sourceLink: function(repoName) {
var current = docMapInfo.getCurrent();

if (!current.src) {
return false;
}

var srcPath = current.src.path.replace('node_modules/' + repoName + '/', ''),
line = current.src.line ? '#L' + (current.src.line + 1) : '';

return '//github.com/canjs/' + repoName + '/edit/master/' + srcPath + line;
},
customSort: function(children) {
var ordered = [],
Expand Down
10 changes: 5 additions & 5 deletions templates/title.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
</a>
</li>
<li>
<a class="github-button nav-social" href="https://github.com/canjs/{{name}}"
data-count-href="/canjs/{{name}}/stargazers"
data-count-api="/repos/canjs/{{name}}#stargazers_count">Star</a>
</li>
<a class="github-button nav-social" href="https://github.com/canjs/{{repoName}}"
data-count-href="/canjs/{{repoName}}/stargazers"
data-count-api="/repos/canjs/{{repoName}}#stargazers_count">Star</a>
</li>
</ul>
{{/if}}
{{#with (getClosestWithPackage)}}
<ul class="title-links">
<!-- <li><a href="#">docco</a></li> -->
{{#with (sourceLink .)}}<li><a href="{{.}}">Edit on GitHub</a></li>{{/with}}
<li><a href="{{sourceLink (repoName)}}">Edit on GitHub</a></li>
Copy link
Member

Choose a reason for hiding this comment

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

Would {{#sourceLink(repoName)}} work outside the <li> to prevent the link from being rendered if we can’t get the link?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I don't think it would. However I haven't been able to reproduce a situation where sourceLink fails to get a link.

That would only occur if docMapInfo.getCurrent().src is undefined and I haven't seen that. Do you know if that's a likely situation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did a quick check on if docMapInfo.getCurrent().src === undefined occurs. It does, but apparently only when rendering subsection headers, for example, "behaviors" under the can-connect. That "virtual parent page" doesn't have content so it's just an ordering in the side menu and doesn't render a page where this tag without a link would be visible.

From what I can tell the removal of the {{#with}} shouldn't have any side effects.

Copy link
Member

Choose a reason for hiding this comment

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

FYI, those group pages do exist: https://canjs.com/doc/can-connect.behaviors.html

I’m not sure why the edit button doesn’t render now (I think #with is always supposed to render), but it wouldn’t hurt to check if the changes in this PR affect that.

Copy link
Contributor Author

@nlundquist nlundquist May 25, 2017

Choose a reason for hiding this comment

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

For interests sake, is there any way to navigate to that page without knowing the URL? Should we add some content (an index of it's children?) to that page seeing as it exists?

For now I can change this back as removing the #with now causes the page to have an edit link.

Copy link
Member

Choose a reason for hiding this comment

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

There will be with search: #259

In that issue I debate that we should either not have those pages at all. If we keep them, then yeah, better content would be in order.

<!-- <li><a href="#">download</a></li> -->
<!-- <li><a href="#">tests</a></li> -->
</ul>
Expand Down