From 72d308702d6b5650408e8d85f5c9663d20f56fcc Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Wed, 16 Nov 2016 23:01:29 +0530 Subject: [PATCH] Feature lead image and first paragraph of text from a wiki page on the corresponding tag index page (resolves #973) (#985) * Add feature #973 * Add links and properly display only first paragraph * Fix off-by-1 bug * Move the wiki content to above the graph * Modify tests for the tag controller to reflect changes * Fix erronous test --- app/controllers/tag_controller.rb | 1 + app/views/tag/show.html.erb | 22 ++++++++++++++++++++++ test/functional/tag_controller_test.rb | 9 +++++++++ 3 files changed, 32 insertions(+) diff --git a/app/controllers/tag_controller.rb b/app/controllers/tag_controller.rb index dad857966d..3086b889ed 100644 --- a/app/controllers/tag_controller.rb +++ b/app/controllers/tag_controller.rb @@ -14,6 +14,7 @@ def index end def show + @wiki = DrupalNode.where(path: "/wiki/#{params[:id]}").first if params[:id].match('question:') default_type = "questions" else diff --git a/app/views/tag/show.html.erb b/app/views/tag/show.html.erb index 8b958ff5d0..d1721dfaa3 100644 --- a/app/views/tag/show.html.erb +++ b/app/views/tag/show.html.erb @@ -1,5 +1,27 @@ <%= render :partial => "sidebar/related" %>
+ + <% if @wiki %> +
+ <% if @wiki.main_image %> +
+
+ <%= image_tag(@wiki.main_image.path, class: "img-responsive") %> +
+
+

<%= link_to @wiki.latest.title, "/wiki/#{params[:id]}" %>

+ <%= (@wiki.latest.render_body.split('

').first + '

').html_safe %> + <%= link_to("Read More", "/wiki/#{params[:id]}") if @wiki.latest.render_body.split('

').length > 2 %> +
+
+ <% else %> +

<%= @wiki.latest.title %>

+ <%= @wiki.latest.render_body.split('\n').first.html_safe %> + <%= link_to("Read More", "/wiki/#{params[:id]}") if @wiki.latest.render_body.split('\n').length > 1 %> + <% end %> +
+ <% end %> + <% if @tags.first %>
diff --git a/test/functional/tag_controller_test.rb b/test/functional/tag_controller_test.rb index 86643d82c3..0ceebc63bc 100644 --- a/test/functional/tag_controller_test.rb +++ b/test/functional/tag_controller_test.rb @@ -97,6 +97,15 @@ def setup end #assert_equal assigns['tags'].length, 1 + assert_select '#wiki-content', 0 + end + + test "should show a featured wiki page at top, if it exists" do + tag = tags(:test) + + get :show, id: node(:organizers).slug + + assert_select '#wiki-content', 1 end test "tag widget" do