Commit ba02aa5007c20a431511f04d41c9928886e6a166
Factor out nav links generation
Charles Lehner committed on 3/30/2016, 10:17:40 PMParent: 7de0259e18a5afbfea5e9cb0ce2545040440b56e
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -151,8 +151,17 @@ | ||
151 | 151 | ]) |
152 | 152 | } |
153 | 153 | } |
154 | 154 | |
155 | +function nav(links, page, after) { | |
156 | + return ['<nav>'].concat( | |
157 | + links.map(function (link) { | |
158 | + var href = typeof link[0] == 'string' ? link[0] : encodeLink(link[0]) | |
159 | + var props = link[2] == page ? ' class="active"' : '' | |
160 | + return '<a href="' + href + '"' + props + '>' + link[1] + '</a>' | |
161 | + }), after || '', '</nav>').join('') | |
162 | +} | |
163 | + | |
155 | 164 | function renderNameForm(enabled, id, name, action, inputId, title, header) { |
156 | 165 | if (!inputId) inputId = action |
157 | 166 | return '<form class="petname" action="" method="post">' + |
158 | 167 | (enabled ? |
@@ -709,14 +718,12 @@ | ||
709 | 718 | readOnce(function (cb) { |
710 | 719 | about.getName(feedId, function (err, name) { |
711 | 720 | cb(null, '<h2>' + link([feedId], name) + |
712 | 721 | '<code class="user-id">' + feedId + '</code></h2>' + |
713 | - '<nav>' + | |
714 | - link([feedId], 'Activity', true, | |
715 | - page == 'activity' ? ' class="active"' : '') + | |
716 | - link([feedId, 'repos'], 'Repos', true, | |
717 | - page == 'repos' ? ' class="active"' : '') + | |
718 | - '</nav>') | |
722 | + nav([ | |
723 | + [[feedId], 'Activity', 'activity'], | |
724 | + [[feedId, 'repos'], 'Repos', 'repos'] | |
725 | + ], page)) | |
719 | 726 | }) |
720 | 727 | }), |
721 | 728 | body, |
722 | 729 | ])) |
@@ -913,19 +920,15 @@ | ||
913 | 920 | renderNameForm(!isPublic, repo.id, repoName, 'repo-name', null, |
914 | 921 | 'Rename the repo', |
915 | 922 | '<h2>' + link([repo.feed], authorName) + ' / ' + |
916 | 923 | link([repo.id], repoName) + '</h2>') + |
917 | - '</div><nav>' + | |
918 | - link([repo.id], 'Code', true, | |
919 | - page == 'code' ? ' class="active"' : '') + | |
920 | - link([repo.id, 'activity'], 'Activity', true, | |
921 | - page == 'activity' ? ' class="active"' : '') + | |
922 | - link([repo.id, 'commits', branch || ''], 'Commits', true, | |
923 | - page == 'commits' ? ' class="active"' : '') + | |
924 | - link([repo.id, 'issues'], 'Issues', true, | |
925 | - page == 'issues' ? ' class="active"' : '') + | |
926 | - gitLink + | |
927 | - '</nav>'), | |
924 | + '</div>' + | |
925 | + nav([ | |
926 | + [[repo.id], 'Code', 'code'], | |
927 | + [[repo.id, 'activity'], 'Activity', 'activity'], | |
928 | + [[repo.id, 'commits', branch || ''], 'Commits', 'commits'], | |
929 | + [[repo.id, 'issues'], 'Issues', 'issues'] | |
930 | + ], page, gitLink)), | |
928 | 931 | body |
929 | 932 | ]))) |
930 | 933 | }) |
931 | 934 | }) |
@@ -1380,16 +1383,13 @@ | ||
1380 | 1383 | '<div class="right-bar">' + link([repo.id, 'issues', 'new'], |
1381 | 1384 | '<button class="btn">+ New Issue</button>', true) + |
1382 | 1385 | '</div>') + |
1383 | 1386 | '<h3>Issues</h3>' + |
1384 | - '<nav>' + | |
1385 | - '<a href="?state=open"' + | |
1386 | - (state == 'open' ? ' class="active"' : '') + '>Open</a>' + | |
1387 | - '<a href="?state=closed"' + | |
1388 | - (state == 'closed' ? ' class="active"' : '') + '>Closed</a>' + | |
1389 | - '<a href="?state=all"' + | |
1390 | - (state == 'all' ? ' class="active"' : '') + '>All</a>' + | |
1391 | - '</nav>'), | |
1387 | + nav([ | |
1388 | + ['?state=open', 'Open', 'open'], | |
1389 | + ['?state=closed', 'Closed', 'closed'], | |
1390 | + ['?state=all', 'All', 'all'] | |
1391 | + ], state)), | |
1392 | 1392 | pull( |
1393 | 1393 | issues.createFeedStream({ project: repo.id }), |
1394 | 1394 | pull.filter(function (issue) { |
1395 | 1395 | return state == 'all' ? true : (state == 'closed') == !issue.open |
Built with git-ssb-web