File tree Expand file tree Collapse file tree
lib/polish_open_source_rank/web/presentation
spec/polish_open_source_rank/web Expand file tree Collapse file tree Original file line number Diff line number Diff line change 355355 color : var (--accent-strong );
356356}
357357
358+ .second_place {
359+ background : linear-gradient (130deg , # bbb 0% , # eee 50% );
360+ }
361+
362+ .first_place {
363+ background : linear-gradient (130deg , # d4af37 0% , # fff3b0 50% );
364+ }
365+
366+ .third_place {
367+ background : linear-gradient (130deg , # b87333 0% , # ffd1a3 50% );
368+ }
369+
358370.metric {
359371 color : var (--accent );
360372 font-weight : 900 ;
Original file line number Diff line number Diff line change 33 <% if rows . any? %>
44 < ol class ="ranking-list " aria-labelledby ="<%= h heading_id %> ">
55 <% rows . each_with_index do |row , index | %>
6- < li class ="ranking-list__item ">
6+ <% place_class = { 1 => "first_place" , 2 => "second_place" , 3 => "third_place" } [ index + 1 ] %>
7+ < li class ="ranking-list__item<% if place_class %> <%= h place_class %> <% end %> ">
78 < span class ="rank-cell rank-mark "> <%= index + 1 %> </ span >
89 < div class ="ranking-list__body ">
910 < div class ="ranking-list__title ">
Original file line number Diff line number Diff line change 33 <% if rows . any? %>
44 < ol class ="ranking-list " aria-labelledby ="<%= h heading_id %> ">
55 <% rows . each_with_index do |row , index | %>
6+ <% place_class = { 1 => "first_place" , 2 => "second_place" , 3 => "third_place" } [ index + 1 ] %>
67 <% repository = { platform : row . fetch ( :platform ) , full_name : row . fetch ( :full_name ) } %>
78 <% path = row . fetch ( :repository_kind ) == "organization" ? organization_repository_profile_path ( repository ) : repository_profile_path ( repository ) %>
89 <% owner = { platform : row . fetch ( :platform ) , login : row . fetch ( :owner_login ) } %>
910 <% owner_path = row . fetch ( :repository_kind ) == "organization" ? organization_profile_path ( owner ) : user_profile_path ( owner ) %>
10- < li class ="ranking-list__item ">
11+ < li class ="ranking-list__item<% if place_class %> <%= h place_class %> <% end %> ">
1112 < span class ="rank-cell rank-mark "> <%= index + 1 %> </ span >
1213 < div class ="ranking-list__body ">
1314 < div class ="ranking-list__title ">
Original file line number Diff line number Diff line change 33 <% if rows . any? %>
44 < ol class ="ranking-list " aria-labelledby ="<%= h heading_id %> ">
55 <% rows . each_with_index do |row , index | %>
6+ <% place_class = { 1 => "first_place" , 2 => "second_place" , 3 => "third_place" } [ index + 1 ] %>
67 <% registry_url = safe_external_url ( row [ :registry_url ] ) %>
78 <% repository_profile_url = package_repository_profile_link ( row ) %>
89 <% repository_source_url = package_repository_link ( row ) %>
910 <% owner_profile_url = package_owner_profile_link ( row ) %>
1011 <% owner_login = package_owner_login ( row ) %>
11- < li class ="ranking-list__item ">
12+ < li class ="ranking-list__item<% if place_class %> <%= h place_class %> <% end %> ">
1213 < span class ="rank-cell rank-mark "> <%= index + 1 %> </ span >
1314 < div class ="ranking-list__body ">
1415 < div class ="ranking-list__title ">
Original file line number Diff line number Diff line change 33 <% if rows . any? %>
44 < ol class ="ranking-list " aria-labelledby ="<%= h heading_id %> ">
55 <% rows . each_with_index do |row , index | %>
6- < li class ="ranking-list__item ">
6+ <% place_class = { 1 => "first_place" , 2 => "second_place" , 3 => "third_place" } [ index + 1 ] %>
7+ < li class ="ranking-list__item<% if place_class %> <%= h place_class %> <% end %> ">
78 < span class ="rank-cell rank-mark "> <%= index + 1 %> </ span >
89 < div class ="ranking-list__body ">
910 < div class ="ranking-list__title ">
Original file line number Diff line number Diff line change @@ -5,15 +5,21 @@ module Web
55 module Presentation
66 module BadgeHelpers
77 def repository_badge_path ( repository )
8- "#{ repository_profile_path ( repository ) . sub ( '/repositories/' , '/badges/repositories/' ) } .svg"
8+ platform = Rack ::Utils . escape_path ( repository . fetch ( :platform , 'github' ) )
9+ owner , name = repository . fetch ( :full_name ) . split ( '/' , 2 )
10+ "/badges/repositories/#{ platform } /#{ Rack ::Utils . escape_path ( owner ) } /#{ Rack ::Utils . escape_path ( name ) } .svg"
911 end
1012
1113 def user_badge_path ( user )
12- "#{ user_profile_path ( user ) . sub ( '/users/' , '/badges/users/' ) } .svg"
14+ platform = Rack ::Utils . escape_path ( user . fetch ( :platform , 'github' ) )
15+ login = Rack ::Utils . escape_path ( user . fetch ( :login ) )
16+ "/badges/users/#{ platform } /#{ login } .svg"
1317 end
1418
1519 def organization_badge_path ( organization )
16- "#{ organization_profile_path ( organization ) . sub ( '/organizations/' , '/badges/organizations/' ) } .svg"
20+ platform = Rack ::Utils . escape_path ( organization . fetch ( :platform , 'github' ) )
21+ login = Rack ::Utils . escape_path ( organization . fetch ( :login ) )
22+ "/badges/organizations/#{ platform } /#{ login } .svg"
1723 end
1824
1925 def linked_badge_markdown ( alt , badge_path )
Original file line number Diff line number Diff line change @@ -653,6 +653,12 @@ def user(_access_token)
653653
654654 github_callback = sign_in_with_github ( request )
655655 profile = request . get ( '/users/github/alice/alice-example' , 'HTTP_COOKIE' => cookie_header ( github_callback ) )
656+ expect ( profile . body ) . to include (
657+ '[]' \
658+ '(https://rank.example/people)'
659+ )
660+ expect ( profile . body ) . not_to include ( '/badges/users/github/alice/alice-example.svg' )
661+
656662 delete = request . post (
657663 '/users/github/alice/alice-example/delete' ,
658664 'HTTP_COOKIE' => cookie_header ( profile ) ,
@@ -1572,7 +1578,9 @@ def expect_latest_user_ranking_page(response)
15721578 podium_classes = html_elements ( response . body , "//ol[@aria-labelledby='ranking-detail-users']/li" )
15731579 . first ( 3 )
15741580 . map { |element | element . attributes [ 'class' ] }
1575- expect ( podium_classes ) . to all ( eq ( 'ranking-list__item' ) )
1581+ expect ( podium_classes ) . to eq (
1582+ [ 'ranking-list__item first_place' , 'ranking-list__item second_place' , 'ranking-list__item third_place' ]
1583+ )
15761584 expect ( response . body ) . not_to include ( '<table>' )
15771585 end
15781586
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ RSpec . describe PolishOpenSourceRank ::Web ::Presentation ::BadgeHelpers do
4+ subject ( :helper_host ) do
5+ Class . new do
6+ include PolishOpenSourceRank ::Web ::Presentation ::BadgeHelpers
7+ end . new
8+ end
9+
10+ it 'builds stable badge paths without profile SEO slugs' , :aggregate_failures do
11+ expect (
12+ helper_host . user_badge_path ( platform : 'github' , login : 'ciembor' , name : 'Maciej Ciemborowicz' )
13+ ) . to eq ( '/badges/users/github/ciembor.svg' )
14+ expect (
15+ helper_host . organization_badge_path ( platform : 'github' , login : 'acme' , name : 'Acme Labs' )
16+ ) . to eq ( '/badges/organizations/github/acme.svg' )
17+ expect (
18+ helper_host . repository_badge_path ( platform : 'github' , full_name : 'ciembor/polish-open-source-rank' )
19+ ) . to eq ( '/badges/repositories/github/ciembor/polish-open-source-rank.svg' )
20+ end
21+ end
You can’t perform that action at this time.
0 commit comments