File tree Expand file tree Collapse file tree 6 files changed +103
-47
lines changed Expand file tree Collapse file tree 6 files changed +103
-47
lines changed Original file line number Diff line number Diff line change 37
37
<%= yield %>
38
38
</ div >
39
39
<% if @page . topics . any? %>
40
- < section class ="section-content container ">
40
+ < section id =" article-topics " class ="section-content container ">
41
41
<%= render Pages ::Topics . new ( topics : @page . topics . pluck ( :slug ) ) %>
42
42
</ section >
43
43
<% end %>
Original file line number Diff line number Diff line change 4
4
5
5
<div class ="column-content container py-gap mb-3xl ">
6
6
< nav class ="sidebar " data-turbo-permanent >
7
- <%= turbo_frame_tag :topics_sidebar do %>
8
- <%= render Topics ::Select . new ( topics , class : "lg:hidden" ) %>
9
- <% topics . each do |topic | %>
10
- <%= tag . div id : dom_id ( topic ) , class : "text-small mb-2 hidden lg:block" do %>
11
- <%= link_to topic . name , topic_path ( topic ) , data : { turbo_frame : :topics_mainbar } %>
12
- < span class ="text-faint "> (<%= topic . pages_count %> )</ span >
13
- <% end %>
14
- <% end %>
7
+ <%= turbo_frame_tag "topics-sidebar" do %>
8
+ <%= render Topics ::Nav . new ( topics , class : "lg:hidden" ) %>
15
9
<% end %>
16
10
</ nav >
17
11
< div class ="mainbar w-full ">
18
- <%= turbo_frame_tag :topics_mainbar , data : { turbo_action : "advance" } do %>
12
+ <%= turbo_frame_tag "topics-mainbar" , data : { turbo_action : "advance" } do %>
19
13
< div >
20
14
< h3 class ="mb-8 lg:hidden "> Howdy!</ h3 >
21
15
< div >
Original file line number Diff line number Diff line change
1
+ module Topics
2
+ class Nav < ApplicationComponent
3
+ include Phlex ::Rails ::Helpers ::CurrentPage
4
+ include Phlex ::Rails ::Helpers ::DOMID
5
+ include PhlexConcerns ::FlexBlock
6
+
7
+ attr_reader :topics , :attributes
8
+
9
+ def initialize ( topics = [ ] , **attributes )
10
+ @topics = topics
11
+ @attributes = attributes
12
+ end
13
+
14
+ def view_template
15
+ topics_select
16
+ topics_list
17
+ end
18
+
19
+ def topics_select
20
+ flex_block ( class : "lg:hidden" ) do
21
+ label ( for : "topic" , class : "block text-sm font-medium text-gray-700" ) do
22
+ "Select a topic"
23
+ end
24
+ select (
25
+ name : "topic" ,
26
+ data : {
27
+ :controller => "select-nav" ,
28
+ :action => "select-nav#visit" ,
29
+ "select-nav-turbo-frame-value" => "topics-mainbar"
30
+ }
31
+ ) do
32
+ option ( value : "" ) { "Start here" }
33
+ topics . each do |topic |
34
+ option (
35
+ value : topic_path ( topic ) ,
36
+ selected : current_page? ( topic_path ( topic ) )
37
+ ) do
38
+ topic . name
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ def topics_list
46
+ topics . each do |topic |
47
+ div id : dom_id ( topic ) , class : "text-small mb-2 hidden lg:block" do
48
+ a (
49
+ href : topic_path ( topic ) ,
50
+ data : {
51
+ turbo_frame : "topics-mainbar"
52
+ }
53
+ ) do
54
+ topic . name
55
+ end
56
+
57
+ whitespace
58
+ span ( class : "text-faint" ) do
59
+ plain "(#{ topic . pages_count } )"
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 5
5
6
6
<div class ="column-content container py-gap mb-3xl ">
7
7
< nav class ="sidebar " data-turbo-permanent >
8
- <%= turbo_frame_tag :topics_sidebar , src : topics_path %>
8
+ <%= turbo_frame_tag "topics-sidebar" , src : topics_path %>
9
9
</ nav >
10
10
< div class ="mainbar w-full ">
11
- <%= turbo_frame_tag :topics_mainbar , data : { turbo_action : "advance" } do %>
11
+ <%= turbo_frame_tag "topics-mainbar" , data : { turbo_action : "advance" } do %>
12
12
<% if topic . pages . blank? %>
13
13
< div >
14
14
< h2 > No articles have been added for this topic yet!</ h2 >
17
17
</ div >
18
18
</ div >
19
19
<% else %>
20
- < h3 class ="mb-8 hidden lg:block "> Topic: <%= topic . name %> </ h3 >
20
+ < h3 class ="mb-8 hidden lg:block "> <%= topic . name %> </ h3 >
21
21
< ul >
22
22
<% topic . pages . as_published_articles . each do |page | %>
23
23
<%= tag . li id : dom_id ( page ) do %>
Original file line number Diff line number Diff line change 6
6
7
7
expect ( page ) . to have_content ( "Articles" )
8
8
end
9
+
10
+ it "displays a single article" do
11
+ Page . upsert_from_sitepress! ( limit : 1 )
12
+
13
+ article = Page . first
14
+ article . topics << FactoryBot . create_list ( :topic , 2 , :approved )
15
+ article . save!
16
+
17
+ visit "/articles"
18
+
19
+ click_on article . title
20
+
21
+ within ( "header.page-header" ) do
22
+ expect ( page ) . to have_content ( article . title )
23
+ end
24
+
25
+ expect ( article . topics . count ) . to eq ( 2 )
26
+
27
+ article . topics . each do |topic |
28
+ expect ( page ) . to have_link ( "##{ topic . slug } " , href : topic_path ( topic ) )
29
+ end
30
+
31
+ first_topic = article . topics . first
32
+ click_link "##{ first_topic . slug } "
33
+
34
+ within ( "header.page-header" ) do
35
+ expect ( page ) . to have_content ( "Topics" )
36
+ end
37
+ expect ( page ) . to have_content ( first_topic . name )
38
+ expect ( page ) . to have_content ( article . title )
39
+ end
9
40
end
You can’t perform that action at this time.
0 commit comments